Browse Source
* Update feature tests * Remove old rake tasks * Update some unit tests * Update more tests * More tests * Fix failing sales household validation test --------- Co-authored-by: Robert Sullivan <robert.sullivan@softwire.com>pull/2364/head v0.4.29
kosiakkatrina
9 months ago
committed by
GitHub
28 changed files with 333 additions and 701 deletions
@ -1,26 +0,0 @@ |
|||||||
desc "Update lettings logs renewal previous postcode and la data to be the same as current postcode/la" |
|
||||||
task correct_renewal_postcodes: :environment do |
|
||||||
LettingsLog.filter_by_year(2023).where(renewal: 1).where(" |
|
||||||
((ppostcode_full != postcode_full) |
|
||||||
OR (ppostcode_full IS NULL AND postcode_full IS NOT NULL) |
|
||||||
OR (postcode_full IS NULL AND ppostcode_full IS NOT NULL)) |
|
||||||
OR ((prevloc != la) |
|
||||||
OR (la IS NULL AND prevloc IS NOT NULL) |
|
||||||
OR (prevloc IS NULL AND la IS NOT NULL)) |
|
||||||
").each do |log| |
|
||||||
log.ppostcode_full = log.postcode_full |
|
||||||
log.ppcodenk = case log.postcode_known |
|
||||||
when 0 |
|
||||||
1 |
|
||||||
when 1 |
|
||||||
0 |
|
||||||
end |
|
||||||
log.is_previous_la_inferred = log.is_la_inferred |
|
||||||
log.previous_la_known = log.la.present? ? 1 : 0 |
|
||||||
log.prevloc = log.la |
|
||||||
log.values_updated_at = Time.zone.now |
|
||||||
unless log.save |
|
||||||
Rails.logger.info("Failed to save log #{log.id}: #{log.errors.full_messages}") |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,24 +0,0 @@ |
|||||||
desc "Set duplicate references for sales and lettings logs" |
|
||||||
task set_duplicate_references: :environment do |
|
||||||
SalesLog.filter_by_year(2023).duplicate_sets.each do |duplicate_set| |
|
||||||
duplicate_set_id = SalesLog.maximum(:duplicate_set_id).to_i + 1 |
|
||||||
next if duplicate_set.any? { |_log_id| SalesLog.exists?(duplicate_set_id:) } |
|
||||||
|
|
||||||
duplicate_set.each do |log_id| |
|
||||||
log = SalesLog.find(log_id) |
|
||||||
log.duplicate_set_id = duplicate_set_id |
|
||||||
log.save!(touch: false, validate: false) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
LettingsLog.filter_by_year(2023).duplicate_sets.each do |duplicate_set| |
|
||||||
duplicate_set_id = LettingsLog.maximum(:duplicate_set_id).to_i + 1 |
|
||||||
next if duplicate_set.any? { |_log_id| LettingsLog.exists?(duplicate_set_id:) } |
|
||||||
|
|
||||||
duplicate_set.each do |log_id| |
|
||||||
log = LettingsLog.find(log_id) |
|
||||||
log.duplicate_set_id = duplicate_set_id |
|
||||||
log.save!(touch: false, validate: false) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,241 +0,0 @@ |
|||||||
require "rails_helper" |
|
||||||
require "rake" |
|
||||||
|
|
||||||
RSpec.describe "correct_renewal_postcodes" do |
|
||||||
describe ":correct_renewal_postcodes", type: :task do |
|
||||||
subject(:task) { Rake::Task["correct_renewal_postcodes"] } |
|
||||||
|
|
||||||
before do |
|
||||||
Rake.application.rake_require("tasks/correct_renewal_postcodes") |
|
||||||
Rake::Task.define_task(:environment) |
|
||||||
task.reenable |
|
||||||
end |
|
||||||
|
|
||||||
context "when the rake task is run" do |
|
||||||
context "and there there is a renewal lettings log with different previous postcode" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: "AA1 1AA") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "updates the previous postcode and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq("SW1A 1AA") |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there there is a non renewal lettings log with different previous postcode" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: "AA1 1AA") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 0 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not update and reexport the previous postcode" do |
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
expect(log.values_updated_at).to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there there is a renewal lettings log with missing previous postcode" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: nil) } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "updates the previous postcode and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq("SW1A 1AA") |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there there is a renewal lettings log without postcode" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, ppostcode_full: "AA1 1AA") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "clears the previous postcode and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log with same postcodes" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "AA1 1AA", ppostcode_full: "AA1 1AA") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not update the previous postcode and does not re-export" do |
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
expect(log.values_updated_at).to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log with same nil postcodes" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_known: 0, la: "E07000223", prevloc: "E07000223", postcode_full: nil, ppostcode_full: nil) } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not update the previous postcode and does not re-export" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
expect(log.values_updated_at).to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log with same nil postcodes and different la" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: "E07000223", ppostcode_full: nil, prevloc: "E07000026") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "updates the previous la and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.prevloc).to eq("E07000223") |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log with same nil postcodes, la not nil and prevloc nil" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: "E07000223", ppostcode_full: nil, previous_la_known: 0, prevloc: nil) } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "updates the previous la and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.prevloc).to eq("E07000223") |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log with same nil postcodes, la nil and prevloc not nil" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: nil, ppostcode_full: nil, prevloc: "E07000223") } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "updates the previous la and reexports the log" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
expect(log.prevloc).to eq("E07000223") |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.prevloc).to eq(nil) |
|
||||||
expect(log.values_updated_at).not_to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there is a renewal lettings log from closed collection year" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "AA1 1AA", ppostcode_full: nil) } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.startdate = Time.zone.local(2022, 4, 4) |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not update the previous postcode and does not re-export" do |
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq(nil) |
|
||||||
expect(log.values_updated_at).to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there there is a different validation error" do |
|
||||||
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: "AA1 1AA") } |
|
||||||
let(:not_related_user) { create(:user) } |
|
||||||
|
|
||||||
before do |
|
||||||
log.renewal = 1 |
|
||||||
log.values_updated_at = nil |
|
||||||
log.created_by = not_related_user |
|
||||||
log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not updaate the log and logs the errors" do |
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
expect(Rails.logger).to receive(:info).with(/Failed to save log #{log.id}:/) |
|
||||||
|
|
||||||
task.invoke |
|
||||||
log.reload |
|
||||||
|
|
||||||
expect(log.ppostcode_full).to eq("AA1 1AA") |
|
||||||
expect(log.values_updated_at).to eq(nil) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,235 +0,0 @@ |
|||||||
require "rails_helper" |
|
||||||
require "rake" |
|
||||||
|
|
||||||
RSpec.describe "set_duplicate_references" do |
|
||||||
describe ":set_duplicate_references", type: :task do |
|
||||||
subject(:task) { Rake::Task["set_duplicate_references"] } |
|
||||||
|
|
||||||
before do |
|
||||||
Rake.application.rake_require("tasks/set_duplicate_references") |
|
||||||
Rake::Task.define_task(:environment) |
|
||||||
task.reenable |
|
||||||
end |
|
||||||
|
|
||||||
context "when the rake task is run" do |
|
||||||
context "and there are sales duplicates in 1 organisation" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:second_duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:sales_log_without_duplicates) { create(:sales_log, created_by: user) } |
|
||||||
|
|
||||||
it "creates duplicate references for sales logs" do |
|
||||||
initial_sales_log_updated_at = sales_log.updated_at |
|
||||||
expect(sales_log.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(second_duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(second_duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(sales_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
sales_log.reload |
|
||||||
duplicate_sales_log.reload |
|
||||||
second_duplicate_sales_log.reload |
|
||||||
sales_log_without_duplicates.reload |
|
||||||
|
|
||||||
expect(sales_log.duplicates.count).to eq(2) |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(2) |
|
||||||
expect(second_duplicate_sales_log.duplicates.count).to eq(2) |
|
||||||
expect(sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to eq(duplicate_sales_log.duplicate_set_id) |
|
||||||
expect(sales_log.duplicate_set_id).to eq(second_duplicate_sales_log.duplicate_set_id) |
|
||||||
expect(sales_log.updated_at).to eq(initial_sales_log_updated_at) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there are sales duplicates in multiple organisations" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:sales_log_without_duplicates) { create(:sales_log, created_by: user) } |
|
||||||
let(:other_user) { create(:user) } |
|
||||||
let!(:other_sales_log) { create(:sales_log, :duplicate, created_by: other_user) } |
|
||||||
let!(:other_duplicate_sales_log) { create(:sales_log, :duplicate, created_by: other_user) } |
|
||||||
let!(:other_sales_log_without_duplicates) { create(:sales_log, created_by: other_user) } |
|
||||||
|
|
||||||
it "creates separate duplicate references for sales logs" do |
|
||||||
expect(sales_log.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(sales_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
expect(other_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(other_sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(other_duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(other_duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(other_sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(other_sales_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
sales_log.reload |
|
||||||
duplicate_sales_log.reload |
|
||||||
sales_log_without_duplicates.reload |
|
||||||
other_sales_log.reload |
|
||||||
other_duplicate_sales_log.reload |
|
||||||
|
|
||||||
expect(sales_log.duplicates.count).to eq(1) |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(1) |
|
||||||
expect(sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to eq(duplicate_sales_log.duplicate_set_id) |
|
||||||
|
|
||||||
expect(other_sales_log.duplicates.count).to eq(1) |
|
||||||
expect(other_duplicate_sales_log.duplicates.count).to eq(1) |
|
||||||
expect(other_sales_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(other_sales_log.duplicate_set_id).to eq(other_duplicate_sales_log.duplicate_set_id) |
|
||||||
expect(other_sales_log.duplicate_set_id).not_to eq(sales_log.duplicate_set_id) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there are sales duplicates for non 2023/24 collection period" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user) } |
|
||||||
|
|
||||||
before do |
|
||||||
sales_log.saledate = Time.zone.local(2022, 4, 4) |
|
||||||
sales_log.save!(validate: false) |
|
||||||
duplicate_sales_log.saledate = Time.zone.local(2022, 4, 4) |
|
||||||
duplicate_sales_log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not create duplicate references for sales logs" do |
|
||||||
expect(sales_log.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
sales_log.reload |
|
||||||
duplicate_sales_log.reload |
|
||||||
|
|
||||||
expect(sales_log.duplicates.count).to eq(0) |
|
||||||
expect(sales_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_sales_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_sales_log.duplicate_set_id).to be_nil |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there are lettings duplicates in 1 organisation" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:second_duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:lettings_log_without_duplicates) { create(:lettings_log, created_by: user) } |
|
||||||
|
|
||||||
it "creates duplicate references for lettings logs" do |
|
||||||
initial_lettings_log_updated_at = lettings_log.updated_at |
|
||||||
expect(lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(second_duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(second_duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
lettings_log.reload |
|
||||||
duplicate_lettings_log.reload |
|
||||||
second_duplicate_lettings_log.reload |
|
||||||
lettings_log_without_duplicates.reload |
|
||||||
|
|
||||||
expect(lettings_log.duplicates.count).to eq(2) |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(2) |
|
||||||
expect(second_duplicate_lettings_log.duplicates.count).to eq(2) |
|
||||||
expect(lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
expect(lettings_log.duplicate_set_id).to eq(duplicate_lettings_log.duplicate_set_id) |
|
||||||
expect(lettings_log.duplicate_set_id).to eq(second_duplicate_lettings_log.duplicate_set_id) |
|
||||||
expect(lettings_log.updated_at).to eq(initial_lettings_log_updated_at) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there are lettings duplicates in multiple organisations" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:lettings_log_without_duplicates) { create(:lettings_log, created_by: user) } |
|
||||||
let(:other_user) { create(:user) } |
|
||||||
let!(:other_lettings_log) { create(:lettings_log, :duplicate, created_by: other_user) } |
|
||||||
let!(:other_duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: other_user) } |
|
||||||
let!(:other_lettings_log_without_duplicates) { create(:lettings_log, created_by: other_user) } |
|
||||||
|
|
||||||
it "creates separate duplicate references for lettings logs" do |
|
||||||
expect(lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
expect(other_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(other_lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(other_duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(other_duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(other_lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(other_lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
lettings_log.reload |
|
||||||
duplicate_lettings_log.reload |
|
||||||
lettings_log_without_duplicates.reload |
|
||||||
other_lettings_log.reload |
|
||||||
other_duplicate_lettings_log.reload |
|
||||||
|
|
||||||
expect(lettings_log.duplicates.count).to eq(1) |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(1) |
|
||||||
expect(lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
expect(lettings_log.duplicate_set_id).to eq(duplicate_lettings_log.duplicate_set_id) |
|
||||||
|
|
||||||
expect(other_lettings_log.duplicates.count).to eq(1) |
|
||||||
expect(other_duplicate_lettings_log.duplicates.count).to eq(1) |
|
||||||
expect(other_lettings_log_without_duplicates.duplicates.count).to eq(0) |
|
||||||
expect(other_lettings_log_without_duplicates.duplicate_set_id).to be_nil |
|
||||||
expect(other_lettings_log.duplicate_set_id).to eq(other_duplicate_lettings_log.duplicate_set_id) |
|
||||||
expect(other_lettings_log.duplicate_set_id).not_to eq(lettings_log.duplicate_set_id) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "and there are lettings duplicates for non 2023/24 collection period" do |
|
||||||
let(:user) { create(:user) } |
|
||||||
let!(:lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
let!(:duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user) } |
|
||||||
|
|
||||||
before do |
|
||||||
lettings_log.startdate = Time.zone.local(2022, 4, 4) |
|
||||||
lettings_log.save!(validate: false) |
|
||||||
duplicate_lettings_log.startdate = Time.zone.local(2022, 4, 4) |
|
||||||
duplicate_lettings_log.save!(validate: false) |
|
||||||
end |
|
||||||
|
|
||||||
it "does not create duplicate references for lettings logs" do |
|
||||||
expect(lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
|
|
||||||
task.invoke |
|
||||||
lettings_log.reload |
|
||||||
duplicate_lettings_log.reload |
|
||||||
|
|
||||||
expect(lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(lettings_log.duplicate_set_id).to be_nil |
|
||||||
expect(duplicate_lettings_log.duplicates.count).to eq(0) |
|
||||||
expect(duplicate_lettings_log.duplicate_set_id).to be_nil |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
Loading…
Reference in new issue