Skip to content

Commit f659fe1

Browse files
authored
Merge pull request #1542 from alphagov/change-debate-outcome-sort-order
Sort debated petitions by debate date, not outcome date
2 parents 54beb85 + b81ba4b commit f659fe1

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

app/helpers/timeline_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def petition_timeline(petition)
3737
else
3838
events << PetitionEvent.new(:parliament_did_not_debate, petition.debate_outcome_at, debate_outcome)
3939
end
40+
elsif petition.debated?
41+
events << PetitionEvent.new(:parliament_debated_pending_outcome, petition.scheduled_debate_date, petition)
4042
end
4143

4244
petition.emails.each do |email|

app/models/archived/petition.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ class Petition < ActiveRecord::Base
5858
facet :all, -> { by_most_signatures }
5959
facet :awaiting_response, -> { awaiting_response.by_waiting_for_response_longest }
6060
facet :awaiting_debate, -> { awaiting_debate.by_most_relevant_debate_date }
61-
facet :with_debate_outcome, -> { with_debate_outcome.by_most_recent_debate_outcome }
61+
facet :with_debate_outcome, -> { with_debate_outcome.by_most_recent_debate }
6262
facet :with_debated_outcome, -> { with_debated_outcome.by_most_recent_debate_outcome }
6363
facet :published, -> { published.by_most_signatures }
6464
facet :stopped, -> { stopped.by_most_signatures }
6565
facet :closed, -> { closed.by_most_signatures }
6666
facet :rejected, -> { rejected.by_most_signatures }
6767
facet :hidden, -> { hidden.by_most_recent }
6868
facet :with_response, -> { with_response.by_most_signatures }
69-
facet :debated, -> { debated.by_most_recent_debate_outcome }
69+
facet :debated, -> { debated.by_most_recent_debate }
7070
facet :not_debated, -> { not_debated.by_most_recent_debate_outcome }
7171
facet :by_most_signatures, -> { by_most_signatures }
7272
facet :by_created_at, -> { by_created_at }
@@ -111,6 +111,10 @@ def by_most_recently_published
111111
reorder('published_at DESC NULLS LAST')
112112
end
113113

114+
def by_most_recent_debate
115+
reorder(scheduled_debate_date: :desc, debate_outcome_at: :desc, created_at: :desc)
116+
end
117+
114118
def by_most_recent_debate_outcome
115119
reorder(debate_outcome_at: :desc, created_at: :desc)
116120
end

app/models/petition.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class Petition < ActiveRecord::Base
6363
facet :with_response, -> { with_response.by_most_recent_response }
6464

6565
facet :awaiting_debate, -> { awaiting_debate.by_most_relevant_debate_date }
66-
facet :with_debate_outcome, -> { with_debate_outcome.by_most_recent_debate_outcome }
66+
facet :with_debate_outcome, -> { with_debate_outcome.by_most_recent_debate }
6767
facet :with_debated_outcome, -> { with_debated_outcome.by_most_recent_debate_outcome }
68-
facet :debated, -> { debated.by_most_recent_debate_outcome }
68+
facet :debated, -> { debated.by_most_recent_debate }
6969
facet :not_debated, -> { not_debated.by_most_recent_debate_outcome }
7070

7171
facet :collecting_sponsors, -> { collecting_sponsors.by_most_recent }
@@ -172,6 +172,10 @@ def by_most_recently_published
172172
reorder('published_at DESC NULLS LAST')
173173
end
174174

175+
def by_most_recent_debate
176+
reorder(scheduled_debate_date: :desc, debate_outcome_at: :desc, created_at: :desc)
177+
end
178+
175179
def by_most_recent_debate_outcome
176180
reorder(debate_outcome_at: :desc, created_at: :desc)
177181
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<li id="debate">
2+
<%= time_tag(petition.scheduled_debate_date) do %>
3+
<strong><%= short_date_format(petition.scheduled_debate_date) %></strong>
4+
<% end %>
5+
6+
<div>
7+
<h3>
8+
Parliament debated this petition
9+
</h3>
10+
11+
<p>
12+
You can watch the debate online on the <a href="https://www.youtube.com/UKParliament">UK Parliament YouTube channel</a>.
13+
</p>
14+
</div>
15+
</li>

features/step_definitions/debate_outcome_steps.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
public_engagement_url: "https://committees.parliament.uk/public-engagement",
1111
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition"
1212
)
13-
@petition.update(debate_outcome_at: debated_days_ago.days.ago)
13+
14+
@petition.update!(
15+
debate_outcome_at: debated_days_ago.days.ago,
16+
scheduled_debate_date: debated_days_ago.days.ago.to_date
17+
)
1418
end
1519

1620
Given(/^an archived petition "(.*?)" has been debated (\d+) days ago?$/) do |petition_action, debated_days_ago|
1721
@petition = FactoryBot.create(:archived_petition, :debated,
1822
action: petition_action,
23+
scheduled_debate_date: debated_days_ago.days.ago.to_date,
1924
debate_outcome_at: debated_days_ago.days.ago,
2025
debated_on: debated_days_ago.days.ago.to_date,
2126
opened_at: debated_days_ago.days.ago - 1.month,

0 commit comments

Comments
 (0)