get all available zones at specific date
This commit is contained in:
parent
9773977496
commit
62f19aba8a
2 changed files with 57 additions and 1 deletions
|
@ -27,4 +27,8 @@ class Zone < ApplicationRecord
|
|||
def available_at?(date)
|
||||
label_at(date) != 'NA'
|
||||
end
|
||||
|
||||
def self.available_at(date)
|
||||
Zone.all.filter { |zone| zone.available_at?(date) }.sort_by { |zone| zone.label_at(date) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,5 +65,57 @@ describe Zone do
|
|||
expect(zone.available_at?(start_previous_government + 1.week)).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#self.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(:om) 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
|
||||
|
||||
let!(:culture) do
|
||||
create(:zone, labels: [
|
||||
{
|
||||
designated_on: start_previous_government,
|
||||
name: "Ministère de la Culture"
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
let!(:om) 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 only available zones at specific date' do
|
||||
expect(Zone.available_at(start_last_government + 1.day)).to eq [culture]
|
||||
expect(Zone.available_at(start_previous_government + 1.day)).to eq [culture, om]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue