get zone label at specific date
This commit is contained in:
parent
a504e82021
commit
59cce4203a
2 changed files with 13 additions and 0 deletions
|
@ -16,4 +16,11 @@ class Zone < ApplicationRecord
|
|||
def label
|
||||
labels.first.name
|
||||
end
|
||||
|
||||
def label_at(date)
|
||||
labels_a = labels.pluck(:designated_on, :name)
|
||||
labels_a.find(-> { labels_a[-1] }) do |designated_on, _|
|
||||
date >= designated_on
|
||||
end.at(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,12 @@ describe Zone do
|
|||
it 'returns label for the current millesime' do
|
||||
expect(zone.label).to eq "Ministère de l'Économie, des Finances et de la Souveraineté industrielle et numérique"
|
||||
end
|
||||
|
||||
it 'returns label at specific date' do
|
||||
expect(zone.label_at(start_previous_government + 1.week)).to eq "Ministère de l'Économie, des Finances et de la Relance"
|
||||
expect(zone.label_at(start_last_government + 1.week)).to eq "Ministère de l'Économie, des Finances et de la Souveraineté industrielle et numérique"
|
||||
expect(zone.label_at(start_previous_government - 1.week)).to eq "Ministère de l'Économie, des Finances et de la Relance"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue