Skip to content

Commit 6c59fe1

Browse files
committed
Don't show 'signatures by x' on rejected petitions
Rejected petitions only have creator and sponsor signatures.
1 parent f2a6fb1 commit 6c59fe1

5 files changed

Lines changed: 64 additions & 2 deletions

File tree

app/models/archived/petition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def hidden?
235235
state == HIDDEN_STATE
236236
end
237237

238+
def published?
239+
state.in?(PUBLISHED_STATES)
240+
end
241+
238242
def duration
239243
if parliament.petition_duration?
240244
parliament.petition_duration

app/views/archived/petitions/_petition.json.jbuilder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ json.attributes do
5757
json.debate nil
5858
end
5959

60-
if archived_petition_page?
60+
if archived_petition_page? && petition.published?
6161
json.signatures_by_country petition.signatures_by_country
6262
json.signatures_by_constituency petition.signatures_by_constituency
6363
end

app/views/petitions/_petition.json.jbuilder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ json.attributes do
6363
json.debate nil
6464
end
6565

66-
if petition_page?
66+
if petition_page? && petition.published?
6767
json.signatures_by_country petition.signatures_by_country do |country|
6868
json.name country.name
6969
json.code country.code

spec/requests/archived_petition_show_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@
205205
)
206206
end
207207

208+
it "doesn't include the signatures by constituency data in rejected petitions" do
209+
FactoryBot.create :constituency, :coventry_north_east
210+
FactoryBot.create :constituency, :bethnal_green_and_bow
211+
212+
petition = \
213+
FactoryBot.create :archived_petition, :rejected,
214+
signatures_by_constituency: { 3427 => 123, 3320 => 456 }
215+
216+
get "/archived/petitions/#{petition.id}.json"
217+
expect(response).to be_success
218+
219+
expect(attributes.keys).not_to include("signatures_by_constituency")
220+
end
221+
208222
it "includes the signatures by country data" do
209223
FactoryBot.create :location, name: "United Kingdom", code: "gb"
210224
FactoryBot.create :location, name: "France", code: "fr"
@@ -233,5 +247,19 @@
233247
)
234248
)
235249
end
250+
251+
it "doesn't include the signatures by country data in rejected petitions" do
252+
FactoryBot.create :location, name: "United Kingdom", code: "gb"
253+
FactoryBot.create :location, name: "France", code: "fr"
254+
255+
petition = \
256+
FactoryBot.create :archived_petition, :rejected,
257+
signatures_by_country: { "gb" => 123456, "fr" => 789 }
258+
259+
get "/archived/petitions/#{petition.id}.json"
260+
expect(response).to be_success
261+
262+
expect(attributes.keys).not_to include("signatures_by_country")
263+
end
236264
end
237265
end

spec/requests/petition_show_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@
205205
)
206206
end
207207

208+
it "doesn't include the signatures by constituency data in rejected petitions" do
209+
petition = FactoryBot.create :rejected_petition
210+
211+
FactoryBot.create :constituency, :coventry_north_east
212+
FactoryBot.create :constituency, :bethnal_green_and_bow
213+
214+
FactoryBot.create :constituency_petition_journal, constituency_id: 3427, signature_count: 123, petition: petition
215+
FactoryBot.create :constituency_petition_journal, constituency_id: 3320, signature_count: 456, petition: petition
216+
217+
get "/petitions/#{petition.id}.json"
218+
expect(response).to be_success
219+
220+
expect(attributes.keys).not_to include("signatures_by_constituency")
221+
end
222+
208223
it "includes the signatures by country data" do
209224
petition = FactoryBot.create :open_petition
210225

@@ -234,5 +249,20 @@
234249
)
235250
)
236251
end
252+
253+
it "doesn't include the signatures by country data in rejected petitions" do
254+
petition = FactoryBot.create :rejected_petition
255+
256+
gb = FactoryBot.create :location, name: "United Kingdom", code: "gb"
257+
fr = FactoryBot.create :location, name: "France", code: "fr"
258+
259+
FactoryBot.create :country_petition_journal, location: gb, signature_count: 123456, petition: petition
260+
FactoryBot.create :country_petition_journal, location: fr, signature_count: 789, petition: petition
261+
262+
get "/petitions/#{petition.id}.json"
263+
expect(response).to be_success
264+
265+
expect(attributes.keys).not_to include("signatures_by_country")
266+
end
237267
end
238268
end

0 commit comments

Comments
 (0)