diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 9b1d32113..b67701176 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -142,9 +142,7 @@ class LocationsController < ApplicationController end def confirm_location - if [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?) - @location.update!(confirmed: true) - end + @location.update!(confirmed: [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?)) end def show; end diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 15d23fe32..57ef87d64 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -87,7 +87,7 @@ RSpec.describe "Accessible Autocomplete" do it "displays appended text next to the options", js: true do find("#lettings-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter) expect(find(".autocomplete__option", visible: :hidden, text: scheme.service_name)).to be_present - expect(find("span", visible: :hidden, text: "2 locations")).to be_present + expect(find("span", visible: :hidden, text: "2 completed locations, 0 incomplete locations")).to be_present end it "displays hint text under the options", js: true do diff --git a/spec/models/form/lettings/questions/scheme_id_spec.rb b/spec/models/form/lettings/questions/scheme_id_spec.rb index 7e88e3139..a1337f408 100644 --- a/spec/models/form/lettings/questions/scheme_id_spec.rb +++ b/spec/models/form/lettings/questions/scheme_id_spec.rb @@ -44,6 +44,7 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do let(:organisation_2) { FactoryBot.create(:organisation) } let(:user) { FactoryBot.create(:user, organisation:) } let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) } + let!(:location) { FactoryBot.create(:location, scheme:) } let(:lettings_log) { FactoryBot.create(:lettings_log, created_by: user, needstype: 2) } before do @@ -84,13 +85,13 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do end context "when the question is answered" do - it "returns 'select an option' as selected answer" do + it "returns scheme as selected answer" do lettings_log.update!(scheme:) answers = question.displayed_answer_options(lettings_log).map do |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) end answers.each do |answer| - if answer.id == scheme.id + if answer.id.to_i == scheme.id expect(question.answer_selected?(lettings_log, answer)).to eq(true) else expect(question.answer_selected?(lettings_log, answer)).to eq(false) diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 57b5de21a..4e249f901 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2259,7 +2259,7 @@ RSpec.describe LettingsLog do describe "resetting invalidated fields" do let(:scheme) { create(:scheme, owning_organisation: created_by_user.organisation) } - let(:location) { create(:location, location_code: "E07000223", scheme:) } + let!(:location) { create(:location, location_code: "E07000223", scheme:) } let(:lettings_log) do create( :lettings_log, diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index eded7d1ee..cb28e093e 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -798,7 +798,7 @@ RSpec.describe Location, type: :model do before do FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today) FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day) - FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil) + FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil, confirmed: false) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil) end