know if a zone exist at a specific date

This commit is contained in:
Christophe Robillard 2022-08-12 17:37:30 +02:00
parent bc5ea8e906
commit 9773977496
2 changed files with 35 additions and 0 deletions

View file

@ -23,4 +23,8 @@ class Zone < ApplicationRecord
date >= designated_on
end.at(1)
end
def available_at?(date)
label_at(date) != 'NA'
end
end

View file

@ -34,5 +34,36 @@ describe Zone do
expect(zone.label_at(start_previous_government - 1.week)).to eq "Ministère de l'Économie, des Finances et de la Relance"
end
end
describe "#available_at?" do
let(:start_previous_government) { Date.parse('2020-07-06') }
let(:start_last_government) { Date.parse('2022-05-20') }
let(:start_futur_government) { Date.parse('2027-05-20') }
let(:zone) do
create(:zone, labels: [
{
designated_on: start_previous_government,
name: "Ministère des Outre-mer"
},
{
designated_on: start_last_government,
name: "NA"
},
{
designated_on: start_futur_government,
name: "Ministère des Territoires d'Outre-mer"
}
])
end
it "returns false if the zone does'nt exist at a specific date" do
expect(zone.available_at?(start_last_government + 1.week)).to be_falsy
end
it "returns true if the zone exist at a specific date" do
expect(zone.available_at?(start_futur_government + 1.week)).to be_truthy
expect(zone.available_at?(start_previous_government + 1.week)).to be_truthy
end
end
end