Skip to content

Commit

Permalink
Merge pull request #456 from leandroalemao/add_debate_date_to_awaitin…
Browse files Browse the repository at this point in the history
…g_debate_petitions_view

Add scheduled debate date to awaiting debate petitions view
  • Loading branch information
pixeltrix committed Apr 22, 2016
2 parents dd800e2 + 4700c6f commit 077ced0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/helpers/date_time_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module DateTimeHelper
WAITING_FOR_KEYS = Hash.new(:other).merge(0 => :zero, 1 => :one)
TO_BE_DEBATED_KEYS = Hash.new(:other).merge(0 => :today, 1 => :tomorrow)

def short_date_format(date_time)
date_time && date_time.strftime("%-d %B %Y")
Expand Down Expand Up @@ -44,4 +45,12 @@ def api_date_format(date_time)
end
end
end

def to_be_debated_on_in_words(date, today = Date.current)
scope = :"petitions.to_be_debated_on_in_words"
days = (date - today).to_i
key = TO_BE_DEBATED_KEYS[days]

t(key, scope: scope, formatted_date: short_date_format(date))
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
<p><%= waiting_for_in_words(petition.debate_threshold_reached_at) %></p>
<% if petition.scheduled_debate_date? %>
<p><%= to_be_debated_on_in_words(petition.scheduled_debate_date) %></p>
<% end %>
5 changes: 5 additions & 0 deletions config/locales/petitions.en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ en-GB:
one: "Waiting for 1 day"
other: "Waiting for %{formatted_count} days"

to_be_debated_on_in_words:
today: "To be debated today"
tomorrow: "To be debated tomorrow"
other: "To be debated on %{formatted_date}"

signature_counts:
default:
html:
Expand Down
26 changes: 26 additions & 0 deletions spec/helpers/date_time_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,30 @@
end
end
end

describe "#to_be_debated_on_in_words" do
context "when the date is today" do
let(:date) { Date.parse("11/11/2016") }

it "returns 'To be debated on 11 November 2016'" do
expect(helper.to_be_debated_on_in_words(date)).to eq("To be debated on 11 November 2016")
end
end

context "when the date is today" do
let(:date) { Date.current }

it "returns 'To be debated today'" do
expect(helper.to_be_debated_on_in_words(date)).to eq("To be debated today")
end
end

context "when the date is tomorrow" do
let(:date) { Date.tomorrow }

it "returns 'To be debated tomorrow'" do
expect(helper.to_be_debated_on_in_words(date)).to eq("To be debated tomorrow")
end
end
end
end

0 comments on commit 077ced0

Please sign in to comment.