Skip to content

Commit

Permalink
Backport 'Fix error message mismatch in election' to v0.27 (#11033)
Browse files Browse the repository at this point in the history
* Fix error message mismatch in election

* Fix error message mismatch in election

* Fixing hour pluralization after #10900

* Apply review recommendations

* Fix the failing spec
  • Loading branch information
alecslupu committed Jun 15, 2023
1 parent 2d35213 commit 7cadfc7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 41,8 @@ def validations
[:max_selections, {}, election.valid_questions?],
[:published, {}, election.published_at.present?],
[:component_published, {}, election.component.published?],
[:time_before, { hours: Decidim::Elections.setup_minimum_hours_before_start }, election.minimum_hours_before_start?],
[:time_before, { hours: I18n.t("datetime.distance_in_words.x_hours", count: Decidim::Elections.setup_minimum_hours_before_start) },
election.minimum_hours_before_start?],
[:trustees_number, { number: bulletin_board.number_of_trustees }, participatory_space_trustees_with_public_key.size >= bulletin_board.number_of_trustees]
].freeze
end
Expand Down
4 changes: 2 additions & 2 deletions decidim-elections/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 271,7 @@ en:
minimum_answers: Questions must have <strong>at least two answers</strong>.
minimum_questions: The election <strong>must have at least one question</strong>.
published: The election is <strong>not published</strong>.
time_before: The start time is in <strong>less than %{hours} hours</strong> before the election starts.
time_before: The start time is in <strong>less than %{hours}</strong> before the election starts.
trustees_number: The participatory space <strong>must have at least %{number} trustees with public key</strong>.
invalid: There was a problem setting up this election
no_trustees: There are no Trustees configured for this participatory space
Expand All @@ -288,7 288,7 @@ en:
minimum_answers: Each question has <strong>at least 2 answers</strong>.
minimum_questions: The election has <strong>at least 1 question</strong>.
published: The election is <strong>published</strong>.
time_before: The setup is being done <strong>at least %{hours} hours</strong> before the election starts.
time_before: The setup is being done <strong>at least %{hours}</strong> before the election starts.
trustees_number: The participatory space has <strong>at least %{number} trustees with public key</strong>.
submit: Setup election
success: Election successfully sent to the Bulletin Board
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 76,28 @@
end
end

context "when the hours before the start do not comply" do
before do
allow(Decidim::Elections).to receive(:setup_minimum_hours_before_start).and_return(hours_before)
end

context "and there is one hour" do
let(:hours_before) { 1 }

it "shows the message" do
expect(subject.messages).to match(hash_including({ time_before: "The setup is being done <strong>at least 1 hour</strong> before the election starts." }))
end
end

context "and there are three hours" do
let(:hours_before) { 3 }

it "shows the message" do
expect(subject.messages).to match(hash_including({ time_before: "The setup is being done <strong>at least 3 hours</strong> before the election starts." }))
end
end
end

context "when there are no trustees for the election" do
let(:trustees) { [] }

Expand Down

0 comments on commit 7cadfc7

Please sign in to comment.