From 07a22dd8b1843fbae1ea78c6e1a20c5a0286e9c5 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 14 Aug 2023 12:58:24 +0100 Subject: [PATCH] tests --- spec/models/lettings_log_spec.rb | 22 +++++++++---------- spec/models/sales_log_spec.rb | 11 +++++----- .../duplicate_logs_controller_spec.rb | 6 ++--- spec/requests/form_controller_spec.rb | 8 +++---- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 40f2ff355..1bf526ab3 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -3090,7 +3090,7 @@ RSpec.describe LettingsLog do end context "when there is a log with nil values for tenancycode" do - let!(:tenancycode_not_given) { create(:lettings_log, :duplicate, tenancycode: nil) } + let!(:tenancycode_not_given) { create(:lettings_log, :duplicate, tenancycode: nil, owning_organisation: organisation) } it "returns the log as a duplicate if tenancy code is nil" do log.update!(tenancycode: nil) @@ -3100,7 +3100,7 @@ RSpec.describe LettingsLog do end context "when there is a log with age1 not known" do - let!(:age1_not_known) { create(:lettings_log, :duplicate, age1_known: 1, age1: nil) } + let!(:age1_not_known) { create(:lettings_log, :duplicate, age1_known: 1, age1: nil, owning_organisation: organisation) } it "returns the log as a duplicate if age1 is not known" do log.update!(age1_known: 1, age1: nil) @@ -3113,8 +3113,8 @@ RSpec.describe LettingsLog do let(:scheme) { create(:scheme) } let(:location) { create(:location, scheme:) } let(:location_2) { create(:location, scheme:) } - let!(:supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:) } - let!(:duplicate_supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:) } + let!(:supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation) } + let!(:duplicate_supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation) } it "returns the log as a duplicate" do expect(duplicate_sets.count).to eq(2) @@ -3129,8 +3129,8 @@ RSpec.describe LettingsLog do end it "does not compare tcharge if there are no household charges" do - supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) - duplicate_supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) + duplicate_supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) expect(duplicate_sets.count).to eq(2) expect(duplicate_sets.first).to contain_exactly(log.id, duplicate_log.id) expect(duplicate_sets.second).to contain_exactly(supported_housing_log.id, duplicate_supported_housing_log.id) @@ -3138,7 +3138,7 @@ RSpec.describe LettingsLog do it "does not return logs not associated with the user if user is given" do user = create(:user) - supported_housing_log.update!(created_by: user, managing_organisation: user.organisation) + supported_housing_log.update!(created_by: user, owning_organisation: user.organisation) duplicate_supported_housing_log.update!(owning_organisation: user.organisation) duplicate_sets = described_class.duplicate_sets(user.id) expect(duplicate_sets.count).to eq(1) @@ -3146,16 +3146,16 @@ RSpec.describe LettingsLog do end it "compares chcharge if it's a carehome" do - supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) - duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) + duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) expect(duplicate_sets.count).to eq(2) expect(duplicate_sets.first).to contain_exactly(log.id, duplicate_log.id) expect(duplicate_sets.second).to contain_exactly(supported_housing_log.id, duplicate_supported_housing_log.id) end it "does not return a duplicate if carehome charge is not given" do - supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) - duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) + duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil, owning_organisation: organisation) expect(duplicate_sets.count).to eq(1) expect(duplicate_sets.first).to contain_exactly(log.id, duplicate_log.id) end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 8e1b73b3b..15f4e6518 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -281,8 +281,8 @@ RSpec.describe SalesLog, type: :model do context "when getting list of duplicate logs" do let(:organisation) { create(:organisation) } - let!(:log) { create(:sales_log, :duplicate) } - let!(:duplicate_log) { create(:sales_log, :duplicate) } + let!(:log) { create(:sales_log, :duplicate, owning_organisation: organisation) } + let!(:duplicate_log) { create(:sales_log, :duplicate, owning_organisation: organisation) } let(:duplicate_sets) { described_class.duplicate_sets } it "returns a list of duplicates in the same organisation" do @@ -379,7 +379,7 @@ RSpec.describe SalesLog, type: :model do end context "when there is a log with nil values for purchid" do - let!(:purchid_not_given) { create(:sales_log, :duplicate, purchid: nil) } + let!(:purchid_not_given) { create(:sales_log, :duplicate, purchid: nil, owning_organisation: organisation) } it "returns the log as a duplicate if tenancy code is nil" do log.update!(purchid: nil) @@ -389,7 +389,7 @@ RSpec.describe SalesLog, type: :model do end context "when there is a log with age1 not known" do - let!(:age1_not_known) { create(:sales_log, :duplicate, age1_known: 1, age1: nil) } + let!(:age1_not_known) { create(:sales_log, :duplicate, age1_known: 1, age1: nil, owning_organisation: organisation) } it "returns the log as a duplicate if age1 is not known" do log.update!(age1_known: 1, age1: nil) @@ -399,7 +399,7 @@ RSpec.describe SalesLog, type: :model do end context "when there is a log with age1 prefers not to say" do - let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil) } + let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil, owning_organisation: organisation) } it "returns the log as a duplicate if age1 is prefers not to say" do log.update!(age1_known: 2, age1: nil) @@ -428,6 +428,7 @@ RSpec.describe SalesLog, type: :model do end it "does not return logs not associated with the given user" do + duplicate_log.update!(owning_organisation: user.organisation) duplicate_sets = described_class.duplicate_sets(user.id) expect(duplicate_sets.count).to eq(1) expect(duplicate_sets.first).to contain_exactly(log.id, duplicate_log.id) diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb index 52dfe0ae7..fa989e836 100644 --- a/spec/requests/duplicate_logs_controller_spec.rb +++ b/spec/requests/duplicate_logs_controller_spec.rb @@ -380,9 +380,9 @@ RSpec.describe DuplicateLogsController, type: :request do end it "shows links for each set of duplciates" do - expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1)) - expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3)) - expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11)) + expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1)) + expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3)) + expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11)) end end end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 8e8a965cb..5f0e7b273 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -797,7 +797,7 @@ RSpec.describe FormController, type: :request do end it "redirects back to the duplicates page for remaining duplicates" do - expect(response).to have_http_status(:ok) + expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}") end end end @@ -805,13 +805,13 @@ RSpec.describe FormController, type: :request do context "when the sales question was accessed from a duplicate logs screen" do let(:sales_log) { create(:sales_log, :duplicate, created_by: user) } let(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) } - let(:referrer) { "/sales-logs/#{sales_log.id}/buyer-1-age?referrer=duplicate_logs&first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{sales_log.id}" } + let(:referrer) { "/sales-logs/#{sales_log.id}/buyer-1-age?referrer=duplicate_logs&first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs" } let(:params) do { id: sales_log.id, sales_log: { page: "buyer_1_age", - age1: 20, + age1: 29, age1_known: 1, }, } @@ -838,7 +838,7 @@ RSpec.describe FormController, type: :request do end it "redirects back to the duplicates page for remaining duplicates" do - expect(response).to have_http_status(:ok) + expect(response).to redirect_to("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}") end end end