Allow customizing the text to display poll dates

Since we were using `I18n.t`, our monkey-patch of the `t` helper wasn't
being applied.
This commit is contained in:
Javi Martín
2024-04-22 19:19:47 +02:00
parent d9662164b8
commit bb574db1ea
2 changed files with 18 additions and 5 deletions

View File

@@ -9,6 +9,6 @@ class Polls::PollComponent < ApplicationComponent
private private
def dates def dates
I18n.t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date)) t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
end end
end end

View File

@@ -42,6 +42,7 @@ describe Polls::PollComponent do
end end
end end
describe "dates" do
it "renders the dates inside an HTML tag" do it "renders the dates inside an HTML tag" do
poll = create(:poll, starts_at: "2015-07-15", ends_at: "2015-07-22") poll = create(:poll, starts_at: "2015-07-15", ends_at: "2015-07-22")
@@ -50,6 +51,18 @@ describe Polls::PollComponent do
expect(page).to have_css ".dates", exact_text: "From 2015-07-15 to 2015-07-22" expect(page).to have_css ".dates", exact_text: "From 2015-07-15 to 2015-07-22"
end end
it "allows customizing the text to display dates" do
poll = create(:poll, starts_at: "2015-07-15", ends_at: "2015-07-22")
create(:i18n_content, key: "polls.dates", value: "Starts someday and finishes who-knows-when")
render_inline Polls::PollComponent.new(poll)
expect(page).to have_css ".dates", exact_text: "Starts someday and finishes who-knows-when"
expect(page).not_to have_content "2015-07-15"
expect(page).not_to have_content "2015-07-22"
end
end
it "shows a link to poll stats if enabled" do it "shows a link to poll stats if enabled" do
poll = create(:poll, :expired, name: "Poll with stats", stats_enabled: true) poll = create(:poll, :expired, name: "Poll with stats", stats_enabled: true)