Browse Source

CLDC-3343 Check relat fields for people we collect data for (#2335)

* Check relat fields for people we collect data for

* rename
pull/2308/head
kosiakkatrina 9 months ago committed by GitHub
parent
commit
e52a8238cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/models/validations/soft_validations.rb
  2. 38
      spec/models/validations/sales/soft_validations_spec.rb

3
app/models/validations/soft_validations.rb

@ -194,7 +194,8 @@ module Validations::SoftValidations
def multiple_partners? def multiple_partners?
return unless hhmemb return unless hhmemb
(2..hhmemb).many? { |n| public_send("relat#{n}") == "P" } max_person_with_details = sales? ? [hhmemb, 6].min : [hhmemb, 8].min
(2..max_person_with_details).many? { |n| public_send("relat#{n}") == "P" }
end end
private private

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

@ -1324,4 +1324,42 @@ RSpec.describe Validations::Sales::SoftValidations do
end end
end end
end end
describe "#multiple_partners?" do
let(:record) { FactoryBot.create(:sales_log, :completed, ownershipsch: 1, jointpur: 1) }
context "when there are multiple partners" do
before do
record.hhmemb = 3
record.relat2 = "P"
record.relat3 = "P"
end
it "returns true" do
expect(record).to be_multiple_partners
end
end
context "when there are not multiple partners" do
before do
record.hhmemb = 2
record.relat2 = "P"
end
it "returns false" do
expect(record).not_to be_multiple_partners
end
end
context "when hhmemb is more than the number of person details we require for joint purchase" do
before do
record.hhmemb = 14
record.relat2 = "P"
end
it "correctly runs the method" do
expect(record).not_to be_multiple_partners
end
end
end
end end

Loading…
Cancel
Save