Simplify stubbing age responses in residence tests

This commit is contained in:
Javi Martín
2023-07-19 01:57:56 +02:00
parent 332e3a296a
commit 018ef2e483

View File

@@ -130,13 +130,15 @@ describe Officing::Residence do
describe "allowed age" do
it "is not valid if user is under allowed age" do
allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(15.years.ago)
allow(residence).to receive(:response_date_of_birth).and_return(15.years.ago)
expect(residence).not_to be_valid
expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate")
end
it "is valid if user is above allowed age" do
allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(16.years.ago)
allow(residence).to receive(:response_date_of_birth).and_return(16.years.ago)
expect(residence).to be_valid
expect(residence.errors[:year_of_birth]).to be_empty
end