115 changed files with 2624 additions and 946 deletions
@ -0,0 +1,25 @@
|
||||
class Form::Sales::Pages::NotRetiredValueCheck < Form::Sales::Pages::Person |
||||
def initialize(id, hsh, subsection, person_index:) |
||||
super |
||||
@depends_on = [ |
||||
{ |
||||
"person_#{person_index}_not_retired_over_soft_max_age?" => true, |
||||
}, |
||||
] |
||||
@person_index = person_index |
||||
@title_text = { |
||||
"translation" => "soft_validations.retirement.max.title", |
||||
} |
||||
@informative_text = { |
||||
"translation" => "soft_validations.retirement.max.hint_text", |
||||
} |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [Form::Sales::Questions::NotRetiredValueCheck.new(nil, nil, self, person_index: @person_index)] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%W[age#{@person_index} ecstat#{@person_index}] |
||||
end |
||||
end |
||||
@ -0,0 +1,24 @@
|
||||
class Form::Sales::Questions::NotRetiredValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page, person_index:) |
||||
super(id, hsh, page) |
||||
@id = "retirement_value_check" |
||||
@check_answer_label = "Retirement confirmation" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"retirement_value_check" => 0, |
||||
}, |
||||
{ |
||||
"retirement_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
@check_answers_card_number = person_index |
||||
@header = "Are you sure this person isn't retired?" |
||||
end |
||||
end |
||||
@ -1,2 +0,0 @@
|
||||
class LogsExport < ApplicationRecord |
||||
end |
||||
@ -0,0 +1,78 @@
|
||||
module Exports |
||||
class ExportService |
||||
include CollectionTimeHelper |
||||
|
||||
def initialize(storage_service, logger = Rails.logger) |
||||
@storage_service = storage_service |
||||
@logger = logger |
||||
end |
||||
|
||||
def export_xml(full_update: false, collection: nil) |
||||
start_time = Time.zone.now |
||||
daily_run_number = get_daily_run_number |
||||
lettings_archives_for_manifest = {} |
||||
users_archives_for_manifest = {} |
||||
organisations_archives_for_manifest = {} |
||||
|
||||
if collection.present? |
||||
case collection |
||||
when "users" |
||||
users_archives_for_manifest = get_user_archives(start_time, full_update) |
||||
when "organisations" |
||||
organisations_archives_for_manifest = get_organisation_archives(start_time, full_update) |
||||
else |
||||
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection) |
||||
end |
||||
else |
||||
users_archives_for_manifest = get_user_archives(start_time, full_update) |
||||
organisations_archives_for_manifest = get_organisation_archives(start_time, full_update) |
||||
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection) |
||||
end |
||||
|
||||
write_master_manifest(daily_run_number, lettings_archives_for_manifest.merge(users_archives_for_manifest).merge(organisations_archives_for_manifest)) |
||||
end |
||||
|
||||
private |
||||
|
||||
def get_daily_run_number |
||||
today = Time.zone.today |
||||
Export.where(created_at: today.beginning_of_day..today.end_of_day).select(:started_at).distinct.count + 1 |
||||
end |
||||
|
||||
def write_master_manifest(daily_run, archive_datetimes) |
||||
today = Time.zone.today |
||||
increment_number = daily_run.to_s.rjust(4, "0") |
||||
month = today.month.to_s.rjust(2, "0") |
||||
day = today.day.to_s.rjust(2, "0") |
||||
file_path = "Manifest_#{today.year}_#{month}_#{day}_#{increment_number}.csv" |
||||
string_io = build_manifest_csv_io(archive_datetimes) |
||||
@storage_service.write_file(file_path, string_io) |
||||
end |
||||
|
||||
def build_manifest_csv_io(archive_datetimes) |
||||
headers = ["zip-name", "date-time zipped folder generated", "zip-file-uri"] |
||||
csv_string = CSV.generate do |csv| |
||||
csv << headers |
||||
archive_datetimes.each do |(archive, datetime)| |
||||
csv << [archive, datetime, "#{archive}.zip"] |
||||
end |
||||
end |
||||
StringIO.new(csv_string) |
||||
end |
||||
|
||||
def get_user_archives(start_time, full_update) |
||||
users_export_service = Exports::UserExportService.new(@storage_service, start_time) |
||||
users_export_service.export_xml_users(full_update:) |
||||
end |
||||
|
||||
def get_organisation_archives(start_time, full_update) |
||||
organisations_export_service = Exports::OrganisationExportService.new(@storage_service, start_time) |
||||
organisations_export_service.export_xml_organisations(full_update:) |
||||
end |
||||
|
||||
def get_lettings_archives(start_time, full_update, collection) |
||||
lettings_export_service = Exports::LettingsLogExportService.new(@storage_service, start_time) |
||||
lettings_export_service.export_xml_lettings_logs(full_update:, collection_year: collection) |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,27 @@
|
||||
module Exports::OrganisationExportConstants |
||||
MAX_XML_RECORDS = 10_000 |
||||
|
||||
EXPORT_FIELDS = Set[ |
||||
"id", |
||||
"name", |
||||
"phone", |
||||
"provider_type", |
||||
"address_line1", |
||||
"address_line2", |
||||
"postcode", |
||||
"holds_own_stock", |
||||
"housing_registration_no", |
||||
"active", |
||||
"old_org_id", |
||||
"old_visible_id", |
||||
"merge_date", |
||||
"absorbing_organisation_id", |
||||
"available_from", |
||||
"deleted_at", |
||||
"dsa_signed", |
||||
"dsa_signed_at", |
||||
"dpo_email", |
||||
"profit_status", |
||||
"group" |
||||
] |
||||
end |
||||
@ -0,0 +1,72 @@
|
||||
module Exports |
||||
class OrganisationExportService < Exports::XmlExportService |
||||
include Exports::OrganisationExportConstants |
||||
include CollectionTimeHelper |
||||
|
||||
def export_xml_organisations(full_update: false) |
||||
collection = "organisations" |
||||
recent_export = Export.where(collection:).order("started_at").last |
||||
|
||||
base_number = Export.where(empty_export: false, collection:).maximum(:base_number) || 1 |
||||
export = build_export_run(collection, base_number, full_update) |
||||
archives_for_manifest = write_export_archive(export, collection, recent_export, full_update) |
||||
|
||||
export.empty_export = archives_for_manifest.empty? |
||||
export.save! |
||||
|
||||
archives_for_manifest |
||||
end |
||||
|
||||
private |
||||
|
||||
def get_archive_name(collection, base_number, increment) |
||||
return unless collection |
||||
|
||||
base_number_str = "f#{base_number.to_s.rjust(4, '0')}" |
||||
increment_str = "inc#{increment.to_s.rjust(4, '0')}" |
||||
"#{collection}_2024_2025_apr_mar_#{base_number_str}_#{increment_str}".downcase |
||||
end |
||||
|
||||
def retrieve_resources(recent_export, full_update, _collection) |
||||
if !full_update && recent_export |
||||
params = { from: recent_export.started_at, to: @start_time } |
||||
Organisation.where("(updated_at >= :from AND updated_at <= :to)", params) |
||||
else |
||||
params = { to: @start_time } |
||||
Organisation.where("updated_at <= :to", params) |
||||
end |
||||
end |
||||
|
||||
def build_export_xml(organisations) |
||||
doc = Nokogiri::XML("<forms/>") |
||||
|
||||
organisations.each do |organisation| |
||||
attribute_hash = apply_cds_transformation(organisation) |
||||
form = doc.create_element("form") |
||||
doc.at("forms") << form |
||||
attribute_hash.each do |key, value| |
||||
if !EXPORT_FIELDS.include?(key) |
||||
next |
||||
else |
||||
form << doc.create_element(key, value) |
||||
end |
||||
end |
||||
end |
||||
|
||||
xml_doc_to_temp_file(doc) |
||||
end |
||||
|
||||
def apply_cds_transformation(organisation) |
||||
attribute_hash = organisation.attributes |
||||
attribute_hash["deleted_at"] = organisation.discarded_at |
||||
attribute_hash["dsa_signed"] = organisation.data_protection_confirmed? |
||||
attribute_hash["dsa_signed_at"] = organisation.data_protection_confirmation&.signed_at |
||||
attribute_hash["dpo_email"] = organisation.data_protection_confirmation&.data_protection_officer_email |
||||
attribute_hash["provider_type"] = organisation.provider_type_before_type_cast |
||||
attribute_hash["profit_status"] = nil # will need update when we add the field to the org |
||||
attribute_hash["group"] = nil # will need update when we add the field to the org |
||||
|
||||
attribute_hash |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,18 @@
|
||||
module Exports::UserExportConstants |
||||
MAX_XML_RECORDS = 10_000 |
||||
|
||||
EXPORT_FIELDS = Set[ |
||||
"id", |
||||
"email", |
||||
"name", |
||||
"phone", |
||||
"organisation_id", |
||||
"organisation_name", |
||||
"role", |
||||
"is_dpo", |
||||
"is_key_contact", |
||||
"active", |
||||
"sign_in_count", |
||||
"last_sign_in_at", |
||||
] |
||||
end |
||||
@ -0,0 +1,68 @@
|
||||
module Exports |
||||
class UserExportService < Exports::XmlExportService |
||||
include Exports::UserExportConstants |
||||
include CollectionTimeHelper |
||||
|
||||
def export_xml_users(full_update: false) |
||||
collection = "users" |
||||
recent_export = Export.where(collection:).order("started_at").last |
||||
|
||||
base_number = Export.where(empty_export: false, collection:).maximum(:base_number) || 1 |
||||
export = build_export_run(collection, base_number, full_update) |
||||
archives_for_manifest = write_export_archive(export, collection, recent_export, full_update) |
||||
|
||||
export.empty_export = archives_for_manifest.empty? |
||||
export.save! |
||||
|
||||
archives_for_manifest |
||||
end |
||||
|
||||
private |
||||
|
||||
def get_archive_name(collection, base_number, increment) |
||||
return unless collection |
||||
|
||||
base_number_str = "f#{base_number.to_s.rjust(4, '0')}" |
||||
increment_str = "inc#{increment.to_s.rjust(4, '0')}" |
||||
"#{collection}_2024_2025_apr_mar_#{base_number_str}_#{increment_str}".downcase |
||||
end |
||||
|
||||
def retrieve_resources(recent_export, full_update, _collection) |
||||
if !full_update && recent_export |
||||
params = { from: recent_export.started_at, to: @start_time } |
||||
User.where("(updated_at >= :from AND updated_at <= :to)", params) |
||||
else |
||||
params = { to: @start_time } |
||||
User.where("updated_at <= :to", params) |
||||
end |
||||
end |
||||
|
||||
def build_export_xml(users) |
||||
doc = Nokogiri::XML("<forms/>") |
||||
|
||||
users.each do |user| |
||||
attribute_hash = apply_cds_transformation(user) |
||||
form = doc.create_element("form") |
||||
doc.at("forms") << form |
||||
attribute_hash.each do |key, value| |
||||
if !EXPORT_FIELDS.include?(key) |
||||
next |
||||
else |
||||
form << doc.create_element(key, value) |
||||
end |
||||
end |
||||
end |
||||
|
||||
xml_doc_to_temp_file(doc) |
||||
end |
||||
|
||||
def apply_cds_transformation(user) |
||||
attribute_hash = user.attributes_before_type_cast |
||||
attribute_hash["role"] = user.role |
||||
attribute_hash["organisation_name"] = user.organisation.name |
||||
attribute_hash["active"] = user.active? |
||||
attribute_hash["phone"] = [user.phone, user.phone_extension].compact.join(" ") |
||||
attribute_hash |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,97 @@
|
||||
module Exports |
||||
class XmlExportService |
||||
include Exports::LettingsLogExportConstants |
||||
include CollectionTimeHelper |
||||
|
||||
def initialize(storage_service, start_time, logger = Rails.logger) |
||||
@storage_service = storage_service |
||||
@logger = logger |
||||
@start_time = start_time |
||||
end |
||||
|
||||
private |
||||
|
||||
def build_export_run(collection, base_number, full_update) |
||||
@logger.info("Building export run for #{collection}") |
||||
previous_exports_with_data = Export.where(collection:, empty_export: false) |
||||
|
||||
increment_number = previous_exports_with_data.where(base_number:).maximum(:increment_number) || 1 |
||||
|
||||
if full_update |
||||
base_number += 1 if Export.any? # Only increment when it's not the first run |
||||
increment_number = 1 |
||||
else |
||||
increment_number += 1 |
||||
end |
||||
|
||||
if previous_exports_with_data.empty? |
||||
return Export.new(collection:, base_number:, started_at: @start_time) |
||||
end |
||||
|
||||
Export.new(collection:, started_at: @start_time, base_number:, increment_number:) |
||||
end |
||||
|
||||
def write_export_archive(export, collection, recent_export, full_update) |
||||
archive = get_archive_name(collection, export.base_number, export.increment_number) # archive name would be the same for all logs because they're already filtered by year (?) |
||||
|
||||
initial_count = retrieve_resources(recent_export, full_update, collection).count |
||||
@logger.info("Creating #{archive} - #{initial_count} resources") |
||||
return {} if initial_count.zero? |
||||
|
||||
zip_file = Zip::File.open_buffer(StringIO.new) |
||||
|
||||
part_number = 1 |
||||
last_processed_marker = nil |
||||
count_after_export = 0 |
||||
|
||||
loop do |
||||
slice = if last_processed_marker.present? |
||||
retrieve_resources(recent_export, full_update, collection) |
||||
.where("created_at > ?", last_processed_marker) |
||||
.order(:created_at) |
||||
.limit(MAX_XML_RECORDS).to_a |
||||
else |
||||
retrieve_resources(recent_export, full_update, collection) |
||||
.order(:created_at) |
||||
.limit(MAX_XML_RECORDS).to_a |
||||
end |
||||
|
||||
break if slice.empty? |
||||
|
||||
data_xml = build_export_xml(slice) |
||||
part_number_str = "pt#{part_number.to_s.rjust(3, '0')}" |
||||
zip_file.add("#{archive}_#{part_number_str}.xml", data_xml) |
||||
part_number += 1 |
||||
last_processed_marker = slice.last.created_at |
||||
count_after_export += slice.count |
||||
@logger.info("Added #{archive}_#{part_number_str}.xml") |
||||
end |
||||
|
||||
manifest_xml = build_manifest_xml(count_after_export) |
||||
zip_file.add("manifest.xml", manifest_xml) |
||||
|
||||
# Required by S3 to avoid Aws::S3::Errors::BadDigest |
||||
zip_io = zip_file.write_buffer |
||||
zip_io.rewind |
||||
@logger.info("Writing #{archive}.zip") |
||||
@storage_service.write_file("#{archive}.zip", zip_io) |
||||
{ archive => Time.zone.now } |
||||
end |
||||
|
||||
def xml_doc_to_temp_file(xml_doc) |
||||
file = Tempfile.new |
||||
xml_doc.write_xml_to(file, encoding: "UTF-8") |
||||
file.rewind |
||||
file |
||||
end |
||||
|
||||
def build_manifest_xml(record_number) |
||||
doc = Nokogiri::XML("<report/>") |
||||
doc.at("report") << doc.create_element("form-data-summary") |
||||
doc.at("form-data-summary") << doc.create_element("records") |
||||
doc.at("records") << doc.create_element("count-of-records", record_number) |
||||
|
||||
xml_doc_to_temp_file(doc) |
||||
end |
||||
end |
||||
end |
||||
@ -1,10 +1,12 @@
|
||||
<div class="govuk-button-group app-filter-toggle"> |
||||
<% if @organisation.data_protection_confirmed? %> |
||||
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %> |
||||
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> |
||||
<% end %> |
||||
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %> |
||||
<%= govuk_button_link_to "Upload lettings logs in bulk", bulk_upload_lettings_log_path(id: "start", organisation_id: @organisation.id), secondary: true %> |
||||
<% end %> |
||||
<% if current_page?(controller: 'organisations', action: 'sales_logs') %> |
||||
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %> |
||||
<% end %> |
||||
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %> |
||||
<%= govuk_button_link_to "Upload sales logs in bulk", bulk_upload_sales_log_path(id: "start", organisation_id: @organisation.id), secondary: true %> |
||||
<% end %> |
||||
<% end %> |
||||
</div> |
||||
|
||||
@ -1 +1 @@
|
||||
EZNV2LiNWzf52erbQ41Dz3Bh+2f3Uih8liEyhXp5XzHCLzAbmN6/IJqr7b9cTZiCiroFo4n/dFoG3yYrospp3frKsDXxF1K2/MTCJWjpgnn7wc+HiPQWG0W3HRtQCNkyyrHes0YKcYyDWIP6kztYv1I/Me3p0pGEx6t3CpSTg1v46eRnOlDWiUz3rVxPauwq9IYZ75gmnThqvg/Z8wcYsWLx0arago0SXtRPASCNj4uO/lbqTcAfyIXOTSiOlcAIjoPFRSQY7UqY0o2p8jRR/1L16SmGDsk8ijm+UygNmMexa3Khy5WcKctpQICakHs4NRjHNflqgXpXKL9dVBmNc9d7h+gbhbGJQ53Y0d+a35UbhPRMiv4SRH98FwB+WEsLCDdGSHvdmM6ArfOLljTrqrsmSRf0JfUrvzyVYmMCxjv4xgJwUS/TD5lQD1yPwkp2ss00kQJqzNmB7qwFhA8a3e2iNzV8qtAV/Nj+tMlr99Hb7vZZs98/38G2p5RAsE/5Xl9taKhc/ACnVc/bwJND4JWaBB7duCa08xVB8nkjlt5cCwMurzAcy1ZT+e8JepR+g6s8fpScMEWVJXE0hd8=--rZ41rY9TMXmiBUJw--QiLRVNVXZzTW446s7cec1g== |
||||
QGn9IiI91BaO4IGAtfy92FrNP46X9T2jJErRv+o/PRG9LrimEGeuOE+FwhArKZQ5cTipaDqo8u9Ajv45Kitv3c0GynOOvz0r3OjPRHO/p4hW8BFWQDv581cWWPsyZT2JO51zZ5LnwNFvWrjEB2q49YESgtfADPkJWmtx/By5Cg2/PVIRxvhGKOnheme5cih050wqg/43BdiF0PD9FDTZXJDLJg/QQ8nQYkvQe2jN4nM4mTVpkQkmzDKgGknmUWFfW3qWFzlsdMkdkPdeP9wLnJVbFTeyaaJT3wv6l19d2rKqo8iVvacdaQjRev+LVXqOsNAjVHwcPNQVq9s8pxG24HLk3aQ14Eyjf6tHAuZAV4jLnNqQtBQ0AIldWeOl6SKmlTom1P1tcLp9KpajEADplmWSwUktIGmaakFjk/ApYaUBiYTku2iLHMrT/xSc3jPj5W/ZggeJ0Ij6nuGYE1cmBxWGxda9PzOrDP8coEK9vPHiNeDDM1RoukVmf8gwDmshILi5EwIAsO2gJXM1wtPYMu41+H4/y3c0GIwgfv9QP11q+nqhG1MMcOrAUKGhypAS+M+uLwfGQudfQDKP9Zv3VCnOk3mkKlpIzMMD4UdJxQeE/8sfwIsEhWggEo3oa93ptbRdvJ7YYcVvmMmkVBxk0KWFprl4i/BkFHLWrKNl5LBOGA==--ziMOTnYBB5TDyXYU--3FJMs8e6R8lheqcqB8p8uQ== |
||||
@ -0,0 +1,5 @@
|
||||
class RenameExportTable < ActiveRecord::Migration[7.0] |
||||
def change |
||||
rename_table :logs_exports, :exports |
||||
end |
||||
end |
||||
@ -0,0 +1,5 @@
|
||||
class AddOrganisationIdToBulkUploads < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :bulk_uploads, :organisation_id, :integer |
||||
end |
||||
end |
||||
@ -0,0 +1,5 @@
|
||||
class AddValidationCheckedField < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :log_validations, :checked, :boolean |
||||
end |
||||
end |
||||
@ -0,0 +1,20 @@
|
||||
desc "Recalculates status for 2024 logs that will trigger new sales over retirement age soft validation" |
||||
task recalculate_status_over_retirement: :environment do |
||||
validation_trigger_condition = "(ecstat1 != 5 AND age1 > 66) OR (ecstat2 != 5 AND age2 > 66) OR (ecstat3 != 5 AND age3 > 66) OR (ecstat4 != 5 AND age4 > 66) OR (ecstat5 != 5 AND age5 > 66) OR (ecstat6 != 5 AND age6 > 66)" |
||||
SalesLog.filter_by_year(2024).where(status: "pending", status_cache: "completed").where(validation_trigger_condition).find_each do |log| |
||||
log.status_cache = log.calculate_status |
||||
log.skip_update_status = true |
||||
|
||||
unless log.save |
||||
Rails.logger.info "Could not save changes to pending sales log #{log.id}" |
||||
end |
||||
end |
||||
|
||||
SalesLog.filter_by_year(2024).where(status: "completed").where(validation_trigger_condition).find_each do |log| |
||||
log.status = log.calculate_status |
||||
|
||||
unless log.save |
||||
Rails.logger.info "Could not save changes to sales log #{log.id}" |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<forms> |
||||
<form> |
||||
<id>{id}</id> |
||||
<name>MHCLG</name> |
||||
<phone/> |
||||
<provider_type>1</provider_type> |
||||
<address_line1>2 Marsham Street</address_line1> |
||||
<address_line2>London</address_line2> |
||||
<postcode>SW1P 4DF</postcode> |
||||
<holds_own_stock>true</holds_own_stock> |
||||
<active>true</active> |
||||
<housing_registration_no>1234</housing_registration_no> |
||||
<old_org_id/> |
||||
<old_visible_id/> |
||||
<merge_date/> |
||||
<absorbing_organisation_id/> |
||||
<available_from/> |
||||
<deleted_at/> |
||||
<dsa_signed>true</dsa_signed> |
||||
<dsa_signed_at>{dsa_signed_at}</dsa_signed_at> |
||||
<dpo_email>{dpo_email}</dpo_email> |
||||
<profit_status/> |
||||
<group/> |
||||
</form> |
||||
</forms> |
||||
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<forms> |
||||
<form> |
||||
<id>{id}</id> |
||||
<email>{email}</email> |
||||
<name>Danny Rojas</name> |
||||
<organisation_id>{organisation_id}</organisation_id> |
||||
<sign_in_count>5</sign_in_count> |
||||
<last_sign_in_at/> |
||||
<role>data_provider</role> |
||||
<phone>1234512345123 123</phone> |
||||
<is_dpo>false</is_dpo> |
||||
<is_key_contact>false</is_key_contact> |
||||
<active>true</active> |
||||
<organisation_name>MHCLG</organisation_name> |
||||
</form> |
||||
</forms> |
||||
@ -0,0 +1,55 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "recalculate_status_after_sales_over_retirement_age_validation" do |
||||
describe ":recalculate_status_over_retirement", type: :task do |
||||
subject(:task) { Rake::Task["recalculate_status_over_retirement"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/recalculate_status_after_sales_over_retirement_age_validation") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
context "and there is a completed sales log that trips the validation" do |
||||
let(:log) { create(:sales_log, :completed, ecstat1: 1, age1: 67) } |
||||
|
||||
before do |
||||
log.status = "completed" |
||||
log.skip_update_status = true |
||||
log.save! |
||||
end |
||||
|
||||
it "sets the log to in progress" do |
||||
task.invoke |
||||
log.reload |
||||
expect(log.status).to eq("in_progress") |
||||
end |
||||
end |
||||
|
||||
context "and there is a pending sales log that trips the validation" do |
||||
let(:log) { create(:sales_log, :completed, ecstat2: 1, age2: 70) } |
||||
|
||||
before do |
||||
log.status = "pending" |
||||
log.status_cache = "completed" |
||||
log.skip_update_status = true |
||||
log.save! |
||||
end |
||||
|
||||
it "updates the status cache" do |
||||
task.invoke |
||||
log.reload |
||||
expect(log.status_cache).to eq("in_progress") |
||||
end |
||||
|
||||
it "does not change the log status" do |
||||
task.invoke |
||||
log.reload |
||||
expect(log.status).to eq("pending") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue