Browse Source

feat: fix lettings_log_spec.rb

pull/1378/head
natdeanlewissoftwire 3 years ago
parent
commit
b13f8afae3
  1. 2
      db/schema.rb
  2. 47
      spec/models/lettings_log_spec.rb

2
db/schema.rb

@ -541,9 +541,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.integer "ethnicbuy2" t.integer "ethnicbuy2"
t.integer "proplen_asked" t.integer "proplen_asked"
t.string "old_id" t.string "old_id"
t.integer "pregblank"
t.integer "buy2living" t.integer "buy2living"
t.integer "prevtenbuy2" t.integer "prevtenbuy2"
t.integer "pregblank"
t.integer "nationalbuy2" t.integer "nationalbuy2"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"

47
spec/models/lettings_log_spec.rb

@ -1982,26 +1982,18 @@ RSpec.describe LettingsLog do
before do before do
lettings_log.needstype = 2 lettings_log.needstype = 2
allow(FormHandler.instance).to receive(:get_form).and_return(real_2021_2022_form) allow(FormHandler.instance).to receive(:get_form).and_return(real_2021_2022_form)
Timecop.freeze(2022, 4, 2)
end
after do
Timecop.unfreeze
end end
context "and a scheme with a single log is selected" do context "and a scheme with a single log is selected" do
let(:scheme) { FactoryBot.create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
Timecop.freeze(2022, 4, 2) Timecop.freeze(Time.zone.local(2022, 4, 2))
lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:) lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:)
end
after do
Timecop.unfreeze Timecop.unfreeze
end end
let(:scheme) { FactoryBot.create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
it "derives the scheme location" do it "derives the scheme location" do
record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(record_from_db["location_id"]).to eq(location.id) expect(record_from_db["location_id"]).to eq(location.id)
@ -2053,6 +2045,12 @@ RSpec.describe LettingsLog do
end end
context "and renewal" do context "and renewal" do
before do
Timecop.freeze(Time.zone.local(2022, 4, 2))
end
after do
Timecop.unfreeze
end
let(:scheme) { FactoryBot.create(:scheme) } let(:scheme) { FactoryBot.create(:scheme) }
let!(:supported_housing_lettings_log) do let!(:supported_housing_lettings_log) do
described_class.create!({ described_class.create!({
@ -2063,11 +2061,13 @@ RSpec.describe LettingsLog do
scheme_id: scheme.id, scheme_id: scheme.id,
location_id: location.id, location_id: location.id,
renewal: 1, renewal: 1,
startdate: Time.zone.now, startdate: Time.zone.local(2022, 4, 2),
created_at: Time.utc(2022, 2, 8, 16, 52, 15), created_at: Time.utc(2022, 2, 8, 16, 52, 15),
}) })
end end
let(:location) { FactoryBot.create(:location, scheme:) } let(:location) { FactoryBot.create(:location, scheme:) }
it "correctly infers and saves the renewal date" do it "correctly infers and saves the renewal date" do
@ -2835,6 +2835,7 @@ RSpec.describe LettingsLog do
Timecop.unfreeze Timecop.unfreeze
end end
context "with values represented as human readable labels" do context "with values represented as human readable labels" do
before do before do
Timecop.freeze(Time.utc(2022, 6, 5)) Timecop.freeze(Time.utc(2022, 6, 5))
@ -2853,6 +2854,15 @@ RSpec.describe LettingsLog do
expected_content.sub!(/\{location_id\}/, location["id"].to_s) expected_content.sub!(/\{location_id\}/, location["id"].to_s)
end end
around do |example|
Timecop.freeze(Time.zone.local(2022, 6, 5)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with a support user" do context "with a support user" do
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") }
@ -2873,7 +2883,7 @@ RSpec.describe LettingsLog do
context "with values represented as codes" do context "with values represented as codes" do
before do before do
Timecop.freeze(Time.utc(2022, 6, 5)) Timecop.freeze(Time.utc(2022, 6, 5))
lettings_log = FactoryBot.create(:lettings_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user, rent_type: 2, startdate: Time.zone.local(2021, 10, 2)) lettings_log = FactoryBot.create(:lettings_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user, rent_type: 2, startdate: Time.zone.local(2021, 10, 2), created_at: Time.zone.local(2022, 2, 8, 16, 52, 15), updated_at: Time.zone.local(2022, 2, 8, 16, 52, 15))
expected_content.sub!(/\{id\}/, lettings_log["id"].to_s) expected_content.sub!(/\{id\}/, lettings_log["id"].to_s)
expected_content.sub!(/\{scheme_code\}/, "S#{scheme.id}") expected_content.sub!(/\{scheme_code\}/, "S#{scheme.id}")
expected_content.sub!(/\{scheme_service_name\}/, scheme.service_name.to_s) expected_content.sub!(/\{scheme_service_name\}/, scheme.service_name.to_s)
@ -2890,6 +2900,15 @@ RSpec.describe LettingsLog do
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_codes_only.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_codes_only.csv", "r:UTF-8") }
around do |example|
Timecop.freeze(Time.zone.local(2022, 6, 5)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
it "generates a correct csv from a lettings log" do it "generates a correct csv from a lettings log" do
expect(described_class.to_csv(codes_only_export: true)).to eq(expected_content) expect(described_class.to_csv(codes_only_export: true)).to eq(expected_content)
end end

Loading…
Cancel
Save