diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index d8ebf9db3..368af3bab 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -92,7 +92,6 @@ private Date.new(0, 1, 1) end end - next unless question_params if %w[checkbox validation_override].include?(question.type) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 35843cccd..3bea2013a 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -1,10 +1,12 @@ class Form::Question attr_accessor :id, :header, :hint_text, :description, :questions, :disable_clearing_if_not_routed_or_dynamic_answer_options, - :type, :min, :max, :step, :width, :fields_to_add, :result_field, :default_answer, + :type, :min, :max, :step, :width, :fields_to_add, :result_field, :conditional_for, :readonly, :answer_options, :page, :check_answer_label, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, - :top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, - :check_answers_card_number, :unresolved_hint_text, :question_number, :hide_question_number_on_page, :plain_label, :error_label + :top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix, + :requires_js, :fields_added, :derived, :check_answers_card_number, + :unresolved_hint_text, :question_number, :hide_question_number_on_page, + :plain_label, :error_label, :default_answer def initialize(id, hsh, page) @id = id diff --git a/app/models/form/sales/questions/buyers_organisations.rb b/app/models/form/sales/questions/buyers_organisations.rb index bb17c3d4d..3faa33f67 100644 --- a/app/models/form/sales/questions/buyers_organisations.rb +++ b/app/models/form/sales/questions/buyers_organisations.rb @@ -16,7 +16,7 @@ class Form::Sales::Questions::BuyersOrganisations < ::Form::Question "pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregla" => { "value" => "Local Authority" }, "pregghb" => { "value" => "Help to Buy Agent" }, - "pregblank" => { "value" => "None selected" }, + "pregblank" => { "value" => "None of the above" }, }.freeze def displayed_answer_options(_log, _user = nil) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 4566ee852..506bc7456 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -854,8 +854,7 @@ private attributes["pregla"] = field_69 attributes["pregghb"] = field_70 attributes["pregother"] = field_68 - organisations_fields = %i[field_67 field_68 field_69 field_70] - attributes["pregblank"] = organisations_fields.all? { |field| attributes[field.to_s].blank? } + attributes["pregblank"] = no_buyer_organisation attributes["disabled"] = field_76 attributes["wheel"] = field_77 @@ -1122,6 +1121,10 @@ private 0 if field_63 == 1 end + def no_buyer_organisation + [field_67, field_68, field_69, field_70].all?(&:blank?) ? 1 : nil? + end + def block_log_creation! self.block_log_creation = true end diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index e01841f92..e864445f6 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -849,8 +849,7 @@ private attributes["pregla"] = field_68 attributes["pregghb"] = field_69 attributes["pregother"] = field_67 - organisations_fields = %i[field_67 field_68 field_69 field_70] - attributes["pregblank"] = organisations_fields.all? { |field| attributes[field.to_s].blank? } + attributes["pregblank"] = no_buyer_organisation attributes["disabled"] = field_75 attributes["wheel"] = field_76 @@ -1125,6 +1124,10 @@ private end end + def no_buyer_organisation + [field_66, field_67, field_68, field_69].all?(&:blank?) ? 1 : nil? + end + def block_log_creation! self.block_log_creation = true end diff --git a/spec/models/form/sales/questions/buyers_organisations_spec.rb b/spec/models/form/sales/questions/buyers_organisations_spec.rb index 9e772a24d..0f6f9196d 100644 --- a/spec/models/form/sales/questions/buyers_organisations_spec.rb +++ b/spec/models/form/sales/questions/buyers_organisations_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do expect(question.hint_text).to eq("Select all that apply. This question is optional. If no options are applicable, leave the options blank, and select save and continue.") end - it "has the correct default answer" do + it "has the correct default" do expect(question.default_answer).to eq("pregblank") end @@ -46,18 +46,18 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do "pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregla" => { "value" => "Local Authority" }, "pregghb" => { "value" => "Help to Buy Agent" }, - "pregblank" => { "value" => "None selected" }, + "pregblank" => { "value" => "None of the above" }, }, ) end - it "has the correct displayed_answer_options" do - expect(question.displayed_answer_options(FactoryBot.create(:sales_log))).to eq( + it "has the correct displayed answer_options" do + expect(question.answer_options).to eq( { "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" }, "pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregla" => { "value" => "Local Authority" }, - "pregghb" => { "value" => "Help to Buy Agent" }, + "pregghb" => { "value" => "Help to Buy Agent" } }, ) end diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 8913a49d9..7fde3c99e 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -959,13 +959,26 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end describe "#field_67 - 70" do # buyers organisations - context "when all nil" do - let(:attributes) { setup_section_params.merge(field_67: nil, field_68: nil, field_69: nil, field_70: nil) } + let(:empty_organisation_params) { setup_section_params.merge(field_67: nil, field_68: nil, field_69: nil, field_70: nil) } + + context "when all empty" do + let(:attributes) { empty_organisation_params } it "sets pregblank field" do expect(parser.log.pregblank).to be(1) end end + + %i[field_67 field_68 field_69 field_70].each do |field_number| + context "when #{field_number} present" do + let(:attributes) { empty_organisation_params.merge({ field_number => 1 }) } + + it "does not set pregblank field" do + attributes[:field_number] = 1 + expect(parser.log.pregblank).to be(0) + end + end + end end describe "soft validations" do diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index 68a420d44..6890a7936 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -965,14 +965,27 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end - describe "#field_66 - 70" do # buyers organisations - context "when all nil" do - let(:attributes) { setup_section_params.merge(field_66: nil, field_67: nil, field_68: nil, field_69: nil) } + describe "#field_66 - 69" do # buyers organisations + let(:empty_organisation_params) { setup_section_params.merge(field_66: nil, field_67: nil, field_68: nil, field_69: nil) } + + context "when all empty" do + let(:attributes) { empty_organisation_params } it "sets pregblank field" do expect(parser.log.pregblank).to be(1) end end + + %i[field_66 field_67 field_68 field_69].each do |field_number| + context "when #{field_number} present" do + let(:attributes) { empty_organisation_params.merge({ field_number => 1 }) } + + it "does not set pregblank field" do + attributes[:field_number] = 1 + expect(parser.log.pregblank).to be(0) + end + end + end end describe "#field_103" do # shared ownership mortgageused