|
|
|
|
@ -584,13 +584,6 @@ RSpec.describe SalesLog, type: :model do
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not clear deposit when setting mortgage used to yes from no for outright sales with new deposit value" do |
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
sales_log.update!(mortgageused: 1, deposit: 1000) |
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "clears deposit when changing from outright sale with no mortgage to shared ownership" do |
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
sales_log.update!(ownershipsch: 1) |
|
|
|
|
@ -606,21 +599,6 @@ RSpec.describe SalesLog, type: :model do
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not clear deposit when changing from outright sale with no mortgage to shared ownership with new deposit value" do |
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
sales_log.update!(ownershipsch: 1, deposit: 1000) |
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not clear when changing from outright sale with no mortgage to discounted ownership with new deposit value" do |
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
sales_log.update!(ownershipsch: 2, deposit: 1000) |
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "correctly derives and saves pcode1 and pcode1 and pcode2" do |
|
|
|
|
sales_log.update!(postcode_full: "W6 0SP") |
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
@ -636,13 +614,6 @@ RSpec.describe SalesLog, type: :model do
|
|
|
|
|
expect(record_from_db["mortgage"]).to eq(0.0) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "derives a mortgage value of 0 when mortgage is unknown" do |
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
sales_log.update!(value: 123_400, saledate: Time.zone.local(2024, 5, 2), mortgageused: 3, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
expect(record_from_db["mortgage"]).to eq(0.0) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "clears mortgage value if mortgage used is changed from no to yes" do |
|
|
|
|
# to avoid log failing validations when mortgage value is removed: |
|
|
|
|
new_grant_value = sales_log.grant + sales_log.mortgage |
|
|
|
|
|