Browse Source

Add validations

pull/1521/head
Kat 3 years ago
parent
commit
574fe5a49c
  1. 9
      app/models/validations/sales/soft_validations.rb
  2. 183
      spec/models/validations/sales/soft_validations_spec.rb

9
app/models/validations/sales/soft_validations.rb

@ -124,11 +124,16 @@ module Validations::Sales::SoftValidations
end
def buyer1_not_livein?
false
return unless ownershipsch && buy1livein
(discounted_ownership_sale? || shared_ownership_scheme?) && buy1livein == 2
end
def buyer2_not_livein?
false
return unless ownershipsch && buy2livein
return unless joint_purchase?
(discounted_ownership_sale? || shared_ownership_scheme?) && buy2livein == 2
end
private

183
spec/models/validations/sales/soft_validations_spec.rb

@ -913,4 +913,187 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
end
describe "#buyer1_not_livein?" do
context "when it's a shared ownership" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 1) }
context "and buy1livein is no" do
before do
record.buy1livein = 2
end
it "returns true" do
expect(record).to be_buyer1_not_livein
end
end
context "and buy1livein is yes" do
before do
record.buy1livein = 1
end
it "returns false" do
expect(record).not_to be_buyer1_not_livein
end
end
end
context "when it's a discounted ownership" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 2) }
context "and buy1livein is no" do
before do
record.buy1livein = 2
end
it "returns true" do
expect(record).to be_buyer1_not_livein
end
end
context "and buy1livein is yes" do
before do
record.buy1livein = 1
end
it "returns false" do
expect(record).not_to be_buyer1_not_livein
end
end
end
context "when it's a outright sale" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3) }
context "and buy1livein is no" do
before do
record.buy1livein = 2
end
it "returns false" do
expect(record).not_to be_buyer1_not_livein
end
end
context "and buy1livein is yes" do
before do
record.buy1livein = 1
end
it "returns false" do
expect(record).not_to be_buyer1_not_livein
end
end
end
context "when ownership is not given" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3) }
before do
record.ownershipsch = nil
end
it "returns false" do
expect(record).not_to be_buyer1_not_livein
end
end
end
describe "#buyer2_not_livein?" do
context "when it's a shared ownership" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 1, jointpur: 1) }
context "and buy2livein is no" do
before do
record.buy2livein = 2
end
it "returns true" do
expect(record).to be_buyer2_not_livein
end
end
context "and buy2livein is yes" do
before do
record.buy2livein = 1
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
context "and not a joint purchase" do
before do
record.buy2livein = 2
record.jointpur = 2
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
end
context "when it's a discounted ownership" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 2, jointpur: 1) }
context "and buy2livein is no" do
before do
record.buy2livein = 2
end
it "returns true" do
expect(record).to be_buyer2_not_livein
end
end
context "and buy2livein is yes" do
before do
record.buy2livein = 1
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
end
context "when it's a outright sale" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3, jointpur: 1) }
context "and buy2livein is no" do
before do
record.buy2livein = 2
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
context "and buy2livein is yes" do
before do
record.buy2livein = 1
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
end
context "when ownership is not given" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3, jointpur: 1) }
before do
record.ownershipsch = nil
end
it "returns false" do
expect(record).not_to be_buyer2_not_livein
end
end
end
end

Loading…
Cancel
Save