Browse Source

Add soft validation method

pull/1516/head
Kat 3 years ago
parent
commit
cfc6c953dd
  1. 11
      app/models/validations/sales/soft_validations.rb
  2. 138
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -136,6 +136,17 @@ module Validations::Sales::SoftValidations
(discounted_ownership_sale? || shared_ownership_scheme?) && buy2livein == 2
end
def percentage_discount_invalid?
return unless discount && proptype
case proptype
when 1, 2
discount > 50
when 3, 4, 9
discount > 35
end
end
private
def sale_range

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

@ -938,6 +938,32 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
end
end
describe "#percentage_discount_invalid?" do
context "when property type is Flat (1)" do
let(:record) { FactoryBot.build(:sales_log, proptype: 1) }
context "and discount is under 50%" do
before do
record.discount = 49
end
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "and discount is over 50%" do
before do
record.discount = 51
end
it "returns true" do
expect(record).to be_percentage_discount_invalid
end
end
end
context "when it's a discounted ownership" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 2) }
@ -963,6 +989,30 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
context "when property type is masionette or bedsit (2)" do
let(:record) { FactoryBot.build(:sales_log, proptype: 2) }
context "and discount is under 50%" do
before do
record.discount = 49
end
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "and discount is over 50%" do
before do
record.discount = 51
end
it "returns true" do
expect(record).to be_percentage_discount_invalid
end
end
end
context "when it's a outright sale" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3) }
@ -987,6 +1037,30 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
context "when property type is House (3)" do
let(:record) { FactoryBot.build(:sales_log, proptype: 3) }
context "and discount is under 35%" do
before do
record.discount = 34
end
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "and discount is over 35%" do
before do
record.discount = 36
end
it "returns true" do
expect(record).to be_percentage_discount_invalid
end
end
end
context "when ownership is not given" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 3) }
@ -1095,5 +1169,69 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).not_to be_buyer2_livein_wrong_for_ownership_type
end
end
context "when property type is Bungalow (4)" do
let(:record) { FactoryBot.build(:sales_log, proptype: 4) }
context "and discount is under 35%" do
before do
record.discount = 34
end
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "and discount is over 35%" do
before do
record.discount = 36
end
it "returns true" do
expect(record).to be_percentage_discount_invalid
end
end
end
context "when property type is Other (9)" do
let(:record) { FactoryBot.build(:sales_log, proptype: 9) }
context "and discount is under 35%" do
before do
record.discount = 34
end
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "and discount is over 35%" do
before do
record.discount = 36
end
it "returns true" do
expect(record).to be_percentage_discount_invalid
end
end
end
context "when discount is not given" do
let(:record) { FactoryBot.build(:sales_log, proptype: 1, discount: nil) }
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
context "when property type is not given" do
let(:record) { FactoryBot.build(:sales_log, proptype: nil, discount: 51) }
it "returns false" do
expect(record).not_to be_percentage_discount_invalid
end
end
end
end

Loading…
Cancel
Save