Compare commits

...

11 Commits

  1. 1
      spec/factories/lettings_log.rb
  2. 12
      spec/features/lettings_log_spec.rb
  3. 59
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb
  4. 25
      spec/models/form/lettings/questions/previous_let_type_spec.rb
  5. 5
      spec/requests/form_controller_spec.rb
  6. 46
      spec/requests/lettings_logs_controller_spec.rb
  7. 28
      spec/requests/organisations_controller_spec.rb
  8. 42
      spec/services/csv/sales_log_csv_service_spec.rb
  9. 59
      spec/services/merge/merge_organisations_service_spec.rb
  10. 7
      spec/views/logs/edit.html.erb_spec.rb

1
spec/factories/lettings_log.rb

@ -178,6 +178,7 @@ FactoryBot.define do
town_or_city { Faker::Address.city } town_or_city { Faker::Address.city }
ppcodenk { 1 } ppcodenk { 1 }
tshortfall_known { 1 } tshortfall_known { 1 }
nationality_all_group { 826 }
after(:build) do |log, evaluator| after(:build) do |log, evaluator|
if log.startdate >= Time.zone.local(2024, 4, 1) if log.startdate >= Time.zone.local(2024, 4, 1)
log.nationality_all_group = 826 log.nationality_all_group = 826

12
spec/features/lettings_log_spec.rb

@ -242,16 +242,6 @@ RSpec.describe "Lettings Log Features" do
end end
context "when completing the setup lettings log section", :aggregate_failure do context "when completing the setup lettings log section", :aggregate_failure do
before do
Timecop.freeze(Time.zone.local(2023, 4, 3))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "includes the owning organisation and assigned to questions" do it "includes the owning organisation and assigned to questions" do
visit("/lettings-logs") visit("/lettings-logs")
click_button("Create a new lettings log") click_button("Create a new lettings log")
@ -263,7 +253,7 @@ RSpec.describe "Lettings Log Features" do
log_id = page.current_path.scan(/\d/).join log_id = page.current_path.scan(/\d/).join
visit("lettings-logs/#{log_id}/setup/check-answers") visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Stock owner User org", normalize_ws: true) expect(page).to have_content("Stock owner User org", normalize_ws: true)
expect(page).to have_content("You have answered 2 of 8 questions") expect(page).to have_content("You have answered 2 of 9 questions")
end end
end end

59
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -581,6 +581,12 @@ RSpec.describe "bulk_update" do
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("updated_locations.csv") .with("updated_locations.csv")
.and_return(StringIO.new(replace_entity_ids_for_locations(locations[0], locations[1], locations[2], scheme, scheme, { id: "non existent scheme id" }, File.open("./spec/fixtures/files/updated_locations.csv").read))) .and_return(StringIO.new(replace_entity_ids_for_locations(locations[0], locations[1], locations[2], scheme, scheme, { id: "non existent scheme id" }, File.open("./spec/fixtures/files/updated_locations.csv").read)))
lettings_log.address_line1 = "1 Test Street"
lettings_log.address_line2 = "Testville"
lettings_log.county = "Testshire"
lettings_log.town_or_city = "Testford"
lettings_log.postcode_full = "SW1 1AA"
lettings_log.save!(validate: false)
end end
it "does not clear the charges values and marks the log in progress" do it "does not clear the charges values and marks the log in progress" do
@ -595,59 +601,6 @@ RSpec.describe "bulk_update" do
expect(lettings_log.supcharg).to eq(50) expect(lettings_log.supcharg).to eq(50)
end end
end end
context "when new LA triggers soft rent ranges validations for closed collection period" do
let!(:lettings_log) do
FactoryBot.create(:lettings_log,
:completed,
:sh,
location: locations[0],
scheme:,
values_updated_at: nil,
owning_organisation: scheme.owning_organisation,
brent: 100,
scharge: 50,
pscharge: 50,
supcharg: 50,
beds: 4,
lettype: 1,
period: 1)
end
before do
LaRentRange.create!(
ranges_rent_id: "1",
la: "E09000033",
beds: 0,
lettype: 8,
soft_min: 12.41,
soft_max: 89.54,
hard_min: 9.87,
hard_max: 100.99,
start_year: 2022,
)
allow(storage_service).to receive(:get_file_io)
.with("updated_locations.csv")
.and_return(StringIO.new(replace_entity_ids_for_locations(locations[0], locations[1], locations[2], scheme, scheme, { id: "non existent scheme id" }, File.open("./spec/fixtures/files/updated_locations.csv").read)))
lettings_log.startdate = Time.zone.local(2022, 4, 1)
lettings_log.owning_organisation = scheme.owning_organisation
lettings_log.save!(validate: false)
end
it "does not clear the charges values and confirms the rent value check" do
expect(lettings_log.status).to eq("completed")
task.invoke(original_locations_csv_path, updated_locations_csv_path)
lettings_log.reload
expect(lettings_log.status).to eq("completed")
expect(lettings_log.rent_value_check).to eq(0)
expect(lettings_log.brent).to eq(100)
expect(lettings_log.scharge).to eq(50)
expect(lettings_log.pscharge).to eq(50)
expect(lettings_log.supcharg).to eq(50)
end
end
end end
end end
end end

25
spec/models/form/lettings/questions/previous_let_type_spec.rb

@ -1,11 +1,13 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Lettings::Questions::PreviousLetType, type: :model do RSpec.describe Form::Lettings::Questions::PreviousLetType, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(nil, nil, page) } subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_year) }
before do before do
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
@ -29,27 +31,8 @@ RSpec.describe Form::Lettings::Questions::PreviousLetType, type: :model do
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "with collection year on or after 2024" do
it "has the correct answer options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Social rent basis" },
"2" => { "value" => "Affordable rent basis" },
"5" => { "value" => "A London Affordable Rent basis" },
"6" => { "value" => "A Rent to Buy basis" },
"7" => { "value" => "A London Living Rent basis" },
"8" => { "value" => "Another Intermediate Rent basis" },
"divider" => { "value" => true },
"3" => { "value" => "Don’t know" },
})
end
it "has the correct question number" do
expect(question.question_number).to eq(17)
end
end
context "with collection year on or after 2025" do context "with collection year on or after 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1)) } let(:form) { instance_double(Form, start_date: collection_start_date_for_year(2025)) }
before do before do
allow(form).to receive(:start_year_2025_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(true)

5
spec/requests/form_controller_spec.rb

@ -31,6 +31,7 @@ RSpec.describe FormController, type: :request do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do before do
skip "Temporarily disabled, the old 2021_2022 form logic this is based on will be removed in CLDC-4403"
allow(fake_2021_2022_form).to receive_messages(new_logs_end_date: Time.zone.today + 1.day, edit_end_date: Time.zone.today + 2.months) allow(fake_2021_2022_form).to receive_messages(new_logs_end_date: Time.zone.today + 1.day, edit_end_date: Time.zone.today + 2.months)
allow(FormHandler.instance).to receive_messages(current_lettings_form: fake_2021_2022_form, lettings_in_crossover_period?: true) allow(FormHandler.instance).to receive_messages(current_lettings_form: fake_2021_2022_form, lettings_in_crossover_period?: true)
end end
@ -476,14 +477,14 @@ RSpec.describe FormController, type: :request do
context "with a question in a section that isn't enabled yet" do context "with a question in a section that isn't enabled yet" do
it "routes back to the tasklist page" do it "routes back to the tasklist page" do
get "/lettings-logs/#{lettings_log.id}/declaration", headers: headers, params: {} get "/lettings-logs/#{lettings_log.id}/address-search", headers: headers, params: {}
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}") expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}")
end end
end end
context "with a question that isn't enabled yet" do context "with a question that isn't enabled yet" do
it "routes back to the tasklist page" do it "routes back to the tasklist page" do
get "/lettings-logs/#{lettings_log.id}/conditional-question-no-second-page", headers: headers, params: {} get "/lettings-logs/#{lettings_log.id}/scheme", headers: headers, params: {}
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}") expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}")
end end
end end

46
spec/requests/lettings_logs_controller_spec.rb

@ -408,16 +408,6 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "when filtering" do context "when filtering" do
before do
Timecop.freeze(Time.utc(2024, 3, 3))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with status filter" do context "with status filter" do
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }
let(:user_2) { FactoryBot.create(:user, organisation: organisation_2) } let(:user_2) { FactoryBot.create(:user, organisation: organisation_2) }
@ -563,16 +553,6 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "with bulk_upload_id filter" do context "with bulk_upload_id filter" do
before do
Timecop.freeze(2023, 4, 1)
Singleton.__init__(FormHandler)
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
context "with bulk upload that belongs to current user" do context "with bulk upload that belongs to current user" do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation) }
@ -737,16 +717,6 @@ RSpec.describe LettingsLogsController, type: :request do
let(:log_to_search) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, assigned_to: user) } let(:log_to_search) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, assigned_to: user) }
let(:log_total_count) { LettingsLog.where(owning_organisation: user.organisation).count } let(:log_total_count) { LettingsLog.where(owning_organisation: user.organisation).count }
before do
Timecop.freeze(Time.utc(2024, 3, 3))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "has search results in the title" do it "has search results in the title" do
get "/lettings-logs?search=#{log_to_search.id}", headers:, params: {} get "/lettings-logs?search=#{log_to_search.id}", headers:, params: {}
expect(page).to have_title("Lettings logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Lettings logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
@ -1031,14 +1001,7 @@ RSpec.describe LettingsLogsController, type: :request do
context "when there are multiple sets of duplicates" do context "when there are multiple sets of duplicates" do
before do before do
Timecop.freeze(Time.zone.local(2024, 3, 1)) FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, assigned_to: user, tenancycode: "different tenancy code", propcode: "different property code")
Singleton.__init__(FormHandler)
FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, assigned_to: user)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end end
it "displays the correct copy in the banner" do it "displays the correct copy in the banner" do
@ -1688,17 +1651,10 @@ RSpec.describe LettingsLogsController, type: :request do
let(:delete_request) { delete "/lettings-logs/#{id}", headers: } let(:delete_request) { delete "/lettings-logs/#{id}", headers: }
before do before do
Timecop.freeze(2024, 3, 1)
Singleton.__init__(FormHandler)
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
end end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when delete permitted" do context "when delete permitted" do
let!(:lettings_log) { create(:lettings_log, :completed) } let!(:lettings_log) { create(:lettings_log, :completed) }

28
spec/requests/organisations_controller_spec.rb

@ -10,16 +10,6 @@ RSpec.describe OrganisationsController, type: :request do
let(:active) { nil } let(:active) { nil }
let(:params) { { id: organisation.id, organisation: { name: new_value, active:, rent_periods: [], all_rent_periods: [] } } } let(:params) { { id: organisation.id, organisation: { name: new_value, active:, rent_periods: [], all_rent_periods: [] } } }
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when user is not signed in" do context "when user is not signed in" do
describe "#show" do describe "#show" do
it "does not let you see organisation details from org route" do it "does not let you see organisation details from org route" do
@ -210,7 +200,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when organisation has absorbed other organisations" do context "when organisation has absorbed other organisations" do
before do before do
create(:organisation, merge_date: Time.zone.today, absorbing_organisation: organisation) create(:organisation, :without_dpc, merge_date: Time.zone.today, absorbing_organisation: organisation)
end end
context "and it has duplicate schemes or locations" do context "and it has duplicate schemes or locations" do
@ -505,9 +495,9 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when the organisation has absorbed other organisations" do context "when the organisation has absorbed other organisations" do
let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 1.month, absorbing_organisation: organisation) }
let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 1.month, absorbing_organisation: organisation) }
let!(:previously_absorbed_organisation) { create(:organisation, name: "Previously Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation) } let!(:previously_absorbed_organisation) { create(:organisation, name: "Previously Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 2.months, absorbing_organisation: organisation) }
before do before do
get "/organisations/#{organisation.id}/details", headers:, params: {} get "/organisations/#{organisation.id}/details", headers:, params: {}
@ -2376,14 +2366,6 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when the organisation does not have a confirmation" do context "when the organisation does not have a confirmation" do
before do
Timecop.freeze(Time.zone.local(2022, 2, 1))
end
after do
Timecop.unfreeze
end
let(:user) { create(:user, is_dpo: true, organisation:, with_dsa: false) } let(:user) { create(:user, is_dpo: true, organisation:, with_dsa: false) }
it "returns redirects to details page" do it "returns redirects to details page" do
@ -2403,7 +2385,7 @@ RSpec.describe OrganisationsController, type: :request do
expect(data_protection_confirmation.organisation).to eq(organisation) expect(data_protection_confirmation.organisation).to eq(organisation)
expect(data_protection_confirmation.data_protection_officer).to eq(user) expect(data_protection_confirmation.data_protection_officer).to eq(user)
expect(data_protection_confirmation.signed_at).to eq(Time.zone.local(2022, 2, 1)) expect(data_protection_confirmation.signed_at).to be_within(1.minute).of(Time.zone.now)
expect(data_protection_confirmation.organisation_name).to eq(organisation.name) expect(data_protection_confirmation.organisation_name).to eq(organisation.name)
expect(data_protection_confirmation.organisation_address).to eq(organisation.address_row) expect(data_protection_confirmation.organisation_address).to eq(organisation.address_row)
expect(data_protection_confirmation.organisation_phone_number).to eq(organisation.phone) expect(data_protection_confirmation.organisation_phone_number).to eq(organisation.phone)

42
spec/services/csv/sales_log_csv_service_spec.rb

@ -169,30 +169,26 @@ RSpec.describe Csv::SalesLogCsvService do
end end
context "when exporting with human readable labels" do context "when exporting with human readable labels" do
let(:year) { 2023 } let(:year) { current_collection_start_year }
let(:fixed_time) { Time.zone.local(2023, 12, 8) } let(:fixed_time) { Time.zone.local(current_collection_start_year, 12, 8) }
let(:now) { fixed_time } let(:now) { fixed_time }
it "gives answers to radio questions as their labels" do it "gives answers to radio questions as their labels" do
national_column_index = attribute_line.index("NATIONAL") nationality_all_column_index = attribute_line.index("NATIONALITYALL1")
national_value = content_line[national_column_index] nationality_all_value = content_line[nationality_all_column_index]
expect(national_value).to eq "United Kingdom" expect(nationality_all_value).to eq "United Kingdom"
relat2_column_index = attribute_line.index("RELAT2") relat2_column_index = attribute_line.index("RELAT2")
relat2_value = content_line[relat2_column_index] relat2_value = content_line[relat2_column_index]
expect(relat2_value).to eq "Partner" expect(relat2_value).to eq "Yes"
end end
it "gives answers to free input questions as the user input" do it "gives answers to free input questions as the user input" do
age1_column_index = attribute_line.index("AGE1") age1_column_index = attribute_line.index("AGE1")
age1_value = content_line[age1_column_index] age1_value = content_line[age1_column_index]
expect(age1_value).to eq 30.to_s expect(age1_value).to eq 30.to_s
postcode_part1, postcode_part2 = log.postcode_full.split town_or_city_column_index = attribute_line.index("TOWNCITY")
postcode_part1_column_index = attribute_line.index("PCODE1") town_or_city_value = content_line[town_or_city_column_index]
postcode_part1_value = content_line[postcode_part1_column_index] expect(town_or_city_value).to eq "Town or city"
expect(postcode_part1_value).to eq postcode_part1
postcode_part2_column_index = attribute_line.index("PCODE2")
postcode_part2_value = content_line[postcode_part2_column_index]
expect(postcode_part2_value).to eq postcode_part2
end end
it "exports the code for the local authority under the heading 'la'" do it "exports the code for the local authority under the heading 'la'" do
@ -296,14 +292,14 @@ RSpec.describe Csv::SalesLogCsvService do
context "when exporting values as codes" do context "when exporting values as codes" do
let(:service) { described_class.new(user:, export_type: "codes", year:) } let(:service) { described_class.new(user:, export_type: "codes", year:) }
let(:year) { 2023 } let(:year) { current_collection_start_year }
let(:fixed_time) { Time.zone.local(2023, 12, 8) } let(:fixed_time) { Time.zone.local(current_collection_start_year, 12, 8) }
let(:now) { fixed_time } let(:now) { fixed_time }
it "gives answers to radio questions as their codes" do it "gives answers to radio questions as their codes" do
national_column_index = attribute_line.index("NATIONAL") nationality_all_column_index = attribute_line.index("NATIONALITYALL1")
national_value = content_line[national_column_index] national_all_value = content_line[nationality_all_column_index]
expect(national_value).to eq 18.to_s expect(national_all_value).to eq 826.to_s
relat2_column_index = attribute_line.index("RELAT2") relat2_column_index = attribute_line.index("RELAT2")
relat2_value = content_line[relat2_column_index] relat2_value = content_line[relat2_column_index]
expect(relat2_value).to eq "P" expect(relat2_value).to eq "P"
@ -313,13 +309,9 @@ RSpec.describe Csv::SalesLogCsvService do
age1_column_index = attribute_line.index("AGE1") age1_column_index = attribute_line.index("AGE1")
age1_value = content_line[age1_column_index] age1_value = content_line[age1_column_index]
expect(age1_value).to eq 30.to_s expect(age1_value).to eq 30.to_s
postcode_part1, postcode_part2 = log.postcode_full.split town_or_city_column_index = attribute_line.index("TOWNCITY")
postcode_part1_column_index = attribute_line.index("PCODE1") town_or_city_value = content_line[town_or_city_column_index]
postcode_part1_value = content_line[postcode_part1_column_index] expect(town_or_city_value).to eq "Town or city"
expect(postcode_part1_value).to eq postcode_part1
postcode_part2_column_index = attribute_line.index("PCODE2")
postcode_part2_value = content_line[postcode_part2_column_index]
expect(postcode_part2_value).to eq postcode_part2
end end
it "exports the code for the local authority under the heading 'la'" do it "exports the code for the local authority under the heading 'la'" do

59
spec/services/merge/merge_organisations_service_spec.rb

@ -3,17 +3,10 @@ require "rails_helper"
RSpec.describe Merge::MergeOrganisationsService do RSpec.describe Merge::MergeOrganisationsService do
describe "#call" do describe "#call" do
before do before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
mail_double = instance_double(ActionMailer::MessageDelivery, deliver_later: nil) mail_double = instance_double(ActionMailer::MessageDelivery, deliver_later: nil)
allow(MergeCompletionMailer).to receive_messages(send_merged_organisation_success_mail: mail_double, send_absorbing_organisation_success_mail: mail_double) allow(MergeCompletionMailer).to receive_messages(send_merged_organisation_success_mail: mail_double, send_absorbing_organisation_success_mail: mail_double)
end end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when merging a single organisation into an existing organisation" do context "when merging a single organisation into an existing organisation" do
subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) } subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) }
@ -170,12 +163,12 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.service_name).to eq(scheme.service_name) expect(absorbed_scheme.service_name).to eq(scheme.service_name)
expect(absorbed_scheme.old_id).to be_nil expect(absorbed_scheme.old_id).to be_nil
expect(absorbed_scheme.old_visible_id).to be_nil expect(absorbed_scheme.old_visible_id).to be_nil
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.postcode).to eq(location.postcode) expect(absorbed_location.postcode).to eq(location.postcode)
expect(absorbed_location.old_id).to be_nil expect(absorbed_location.old_id).to be_nil
expect(absorbed_location.old_visible_id).to be_nil expect(absorbed_location.old_visible_id).to be_nil
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
end end
it "deactivates schemes and locations on the merged organisation" do it "deactivates schemes and locations on the merged organisation" do
@ -183,9 +176,9 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
expect(location.scheme).to eq(scheme) expect(location.scheme).to eq(scheme)
expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(location.location_deactivation_periods.count).to eq(1) expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(location.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
end end
end end
@ -204,8 +197,8 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
end end
it "deactivates schemes and locations on the merged organisation" do it "deactivates schemes and locations on the merged organisation" do
@ -215,9 +208,9 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
expect(location.scheme).to eq(scheme) expect(location.scheme).to eq(scheme)
expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(location.location_deactivation_periods.count).to eq(1) expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(location.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
end end
end end
@ -276,10 +269,10 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(0) expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(0)
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.count).to eq(0) expect(absorbed_location.location_deactivation_periods.count).to eq(0)
end end
@ -287,9 +280,9 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
expect(location.scheme).to eq(scheme) expect(location.scheme).to eq(scheme)
expect(scheme.scheme_deactivation_periods.count).to eq(2) expect(scheme.scheme_deactivation_periods.count).to eq(2)
expect(scheme.scheme_deactivation_periods.last.deactivation_date).to eq(Time.zone.today) expect(scheme.scheme_deactivation_periods.last.deactivation_date.to_date).to eq(Time.zone.today)
expect(location.location_deactivation_periods.count).to eq(2) expect(location.location_deactivation_periods.count).to eq(2)
expect(location.location_deactivation_periods.last.deactivation_date).to eq(Time.zone.today) expect(location.location_deactivation_periods.last.deactivation_date.to_date).to eq(Time.zone.today)
end end
end end
@ -313,10 +306,10 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1) expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1)
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.count).to eq(1) expect(absorbed_location.location_deactivation_periods.count).to eq(1)
end end
@ -324,9 +317,9 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
expect(location.scheme).to eq(scheme) expect(location.scheme).to eq(scheme)
expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.last.deactivation_date).to eq(Time.zone.today) expect(scheme.scheme_deactivation_periods.last.deactivation_date.to_date).to eq(Time.zone.today)
expect(location.location_deactivation_periods.count).to eq(1) expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.last.deactivation_date).to eq(Time.zone.today) expect(location.location_deactivation_periods.last.deactivation_date.to_date).to eq(Time.zone.today)
end end
end end
@ -397,14 +390,14 @@ RSpec.describe Merge::MergeOrganisationsService do
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expected_reactivation_date = Time.zone.today + 1.month expected_reactivation_date = Time.zone.today + 1.month
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1) expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1)
expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone) expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone)
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.count).to eq(1) expect(absorbed_location.location_deactivation_periods.count).to eq(1)
expect(absorbed_location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_location.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone) expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone)
end end
@ -441,14 +434,14 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1) expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1)
expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to be_nil expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to be_nil
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.count).to eq(1) expect(absorbed_location.location_deactivation_periods.count).to eq(1)
expect(absorbed_location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_location.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to be_nil expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to be_nil
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
@ -826,8 +819,8 @@ RSpec.describe Merge::MergeOrganisationsService do
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbed_active_scheme.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) expect(absorbed_active_scheme.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbed_active_scheme.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) expect(absorbed_active_scheme.locations.find_by(postcode: location_without_startdate.postcode).startdate.to_date).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) expect(absorbed_active_scheme.locations.find_by(postcode: location_with_past_startdate.postcode).startdate.to_date).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months) expect(absorbed_active_scheme.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months)
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) expect(absorbed_active_scheme.service_name).to eq(scheme.service_name)
expect(absorbed_active_scheme.old_id).to be_nil expect(absorbed_active_scheme.old_id).to be_nil

7
spec/views/logs/edit.html.erb_spec.rb

@ -4,17 +4,10 @@ RSpec.describe "logs/edit.html.erb" do
let(:current_user) { create(:user, :support) } let(:current_user) { create(:user, :support) }
before do before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
assign(:log, log) assign(:log, log)
sign_in current_user sign_in current_user
end end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when log is in progress" do context "when log is in progress" do
let(:log) { create(:lettings_log, :in_progress) } let(:log) { create(:lettings_log, :in_progress) }

Loading…
Cancel
Save