Skip to content

Commit e3d971a

Browse files
authored
Merge pull request #641 from alphagov/add-christmas-delay-message
Add message about moderation delayed over Christmas
2 parents 6c9100d + 33e915a commit e3d971a

6 files changed

Lines changed: 164 additions & 3 deletions

File tree

app/helpers/date_time_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ def scheduled_for_debate_in_words(date, today = Date.current)
5757

5858
t(key, scope: scope, formatted_date: short_date_format(date))
5959
end
60+
61+
def christmas_period?(today = Date.current)
62+
if today.mon == 12
63+
today.day > 21 ? true : false
64+
elsif today.mon == 1
65+
today.day < 5 ? true : false
66+
else
67+
false
68+
end
69+
end
6070
end

app/views/sponsor_mailer/sponsor_signed_email_on_threshold.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
<p><%= @sponsor.name %> supported your petition – “<%= @petition.action %>”.</p>
66

7+
<% if christmas_period? %>
8+
<p><%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Christmas period it may take us a little longer than usual. We’ll check your petition as quickly as we can.</p>
9+
<% else %>
710
<p><%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less.</p>
11+
<% end %>
812

913
<p>Find out how we check petitions before we publish them:<br />
1014
<%= link_to nil, help_url(anchor: 'standards') %></p>

app/views/sponsor_mailer/sponsor_signed_email_on_threshold.text.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Your petition is nearly ready to go.
44

55
<%= @sponsor.name %> supported your petition – "<%= @petition.action %>".
66

7+
<% if christmas_period? %>
8+
<%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Christmas period it may take us a little longer than usual. We’ll check your petition as quickly as we can.
9+
<% else %>
710
<%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less.
11+
<% end %>
812

913
Find out how we check petitions before we publish them:
1014
<%= help_url(anchor: 'standards') %>

spec/helpers/date_time_helper_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,56 @@
134134
end
135135
end
136136
end
137+
138+
describe "#christmas_period?" do
139+
context "when the date is before the 22nd Dec" do
140+
around do |example|
141+
travel_to("2017-12-21") { example.run }
142+
end
143+
144+
it "returns false" do
145+
expect(helper.christmas_period?).to eq(false)
146+
end
147+
end
148+
149+
context "when the date is the 22nd Dec" do
150+
around do |example|
151+
travel_to("2017-12-22") { example.run }
152+
end
153+
154+
it "returns true" do
155+
expect(helper.christmas_period?).to eq(true)
156+
end
157+
end
158+
159+
context "when the date is between 22nd Dec and 4th Jan" do
160+
around do |example|
161+
travel_to("2017-12-26") { example.run }
162+
end
163+
164+
it "returns true" do
165+
expect(helper.christmas_period?).to eq(true)
166+
end
167+
end
168+
169+
context "when the date is the 4th Jan" do
170+
around do |example|
171+
travel_to("2018-01-04") { example.run }
172+
end
173+
174+
it "returns true" do
175+
expect(helper.christmas_period?).to eq(true)
176+
end
177+
end
178+
179+
context "when the date is after the 4th Jan" do
180+
around do |example|
181+
travel_to("2018-01-05") { example.run }
182+
end
183+
184+
it "returns false" do
185+
expect(helper.christmas_period?).to eq(false)
186+
end
187+
end
188+
end
137189
end
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Preview all emails at http://localhost:3000/rails/mailers/sponsor_mailer
22
class SponsorMailerPreview < ActionMailer::Preview
3-
def new_sponsor_email
4-
SponsorMailer.new_sponsor_email(Sponsor.first)
3+
def petition_and_email_confirmation_for_sponsor
4+
SponsorMailer.petition_and_email_confirmation_for_sponsor(Signature.sponsors.last)
5+
end
6+
7+
def sponsor_signed_email_on_threshold
8+
sponsor = Signature.sponsors.last
9+
petition = sponsor.petition
10+
11+
SponsorMailer.sponsor_signed_email_on_threshold(petition, sponsor)
512
end
613
end

spec/mailers/sponsor_mailer_spec.rb

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
end
1616

1717
let :sponsor do
18-
FactoryBot.create(:sponsor, :pending, email: 'allyadams@outlook.com', petition: petition)
18+
FactoryBot.create(:sponsor, :pending, name: "Ally Adams", email: 'allyadams@outlook.com', petition: petition)
1919
end
2020

2121
describe "#petition_and_email_confirmation_for_sponsor" do
@@ -75,4 +75,88 @@
7575
end
7676
end
7777
end
78+
79+
describe "#sponsor_signed_email_on_threshold" do
80+
subject(:mail) { described_class.sponsor_signed_email_on_threshold(petition, sponsor) }
81+
82+
before do
83+
allow(petition).to receive_message_chain(:sponsors, :validated, :count).and_return(5)
84+
end
85+
86+
shared_examples_for "a sponsor signed on threshold email" do
87+
it "has the correct subject" do
88+
expect(mail.subject).to eq("We’re checking your petition")
89+
end
90+
91+
it "sends it only to the creator" do
92+
expect(mail.to).to eq(%w[bazbutler@gmail.com])
93+
expect(mail.cc).to be_blank
94+
expect(mail.bcc).to be_blank
95+
end
96+
97+
it "includes the creator's name in the body" do
98+
expect(mail).to have_body_text(%r[Barry Butler])
99+
end
100+
101+
it "includes the sponsor's name in the body" do
102+
expect(mail).to have_body_text(%r[Ally Adams])
103+
end
104+
105+
it "includes the petition action" do
106+
expect(mail).to have_body_text(%r[Allow organic vegetable vans to use red diesel])
107+
end
108+
109+
it "doesn't include the petition background" do
110+
expect(mail).not_to have_body_text(%r[Add vans to permitted users of red diesel])
111+
end
112+
113+
it "doesn't include the petition additional details" do
114+
expect(mail).not_to have_body_text(%r[To promote organic vegetables])
115+
end
116+
117+
it "includes the sponsor count" do
118+
expect(mail).to have_body_text(%r[5 people have supported your petition so far])
119+
end
120+
121+
it "tells the creator that the petition is being checked" do
122+
expect(mail).to have_body_text(%r[We’re checking your petition to make sure it meets the petition standards])
123+
end
124+
end
125+
126+
context "before the Christmas period" do
127+
around do |example|
128+
travel_to("2017-12-21") { example.run }
129+
end
130+
131+
it_behaves_like "a sponsor signed on threshold email"
132+
133+
it "doesn't include the moderation delay message" do
134+
expect(mail).not_to have_body_text(%r[over the Christmas period it may take us a little longer than usual])
135+
end
136+
end
137+
138+
context "during the Christmas period" do
139+
around do |example|
140+
travel_to("2017-12-26") { example.run }
141+
end
142+
143+
it_behaves_like "a sponsor signed on threshold email"
144+
145+
it "includes the moderation delay message" do
146+
expect(mail).to have_body_text(%r[over the Christmas period it may take us a little longer than usual])
147+
end
148+
end
149+
150+
context "after the Christmas period" do
151+
around do |example|
152+
travel_to("2018-01-05") { example.run }
153+
end
154+
155+
it_behaves_like "a sponsor signed on threshold email"
156+
157+
it "doesn't include the moderation delay message" do
158+
expect(mail).not_to have_body_text(%r[over the Christmas period it may take us a little longer than usual])
159+
end
160+
end
161+
end
78162
end

0 commit comments

Comments
 (0)