Skip to content

Commit

Permalink
Merge pull request #664 from alphagov/fix-search-result-urls
Browse files Browse the repository at this point in the history
Use correct archived petition urls in search results
  • Loading branch information
pixeltrix authored Jul 20, 2018
2 parents bdc822e + f329711 commit 2679c68
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ def filtered_petition_count(petitions)
noun = petitions.search? ? 'result' : 'petition'
"#{number_with_delimiter(total_entries)} #{noun.pluralize(total_entries)}"
end

def petition_result_path(petition, options = {})
if petition.is_a?(Archived::Petition)
archived_petition_path(petition, options)
else
petition_path(petition, options)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<% case petition.state %>
<% when "open" %>
<p><%= signature_count(:default, petition.signature_count) %></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_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? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
<p><%= waiting_for_in_words(petition.response_threshold_reached_at) %></p>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3><%= link_to petition.action, petition_path(petition, anchor: 'debate-threshold') %></h3>
<h3><%= link_to petition.action, petition_result_path(petition, anchor: 'debate-threshold') %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
<% if debate_outcome = petition.debate_outcome %>
<p>Debated <%= short_date_format(debate_outcome.debated_on) %></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
<p><%= signature_count(:default, petition.signature_count) %></p>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h3><%= link_to petition.action, petition_path(petition) %></h3>
<h3><%= link_to petition.action, petition_result_path(petition) %></h3>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3><%= link_to petition.action, petition_path(petition, reveal_response: "yes", anchor: 'response-threshold') %></h3>
<h3><%= link_to petition.action, petition_result_path(petition, reveal_response: "yes", anchor: 'response-threshold') %></h3>
<p>Government responded – <%= short_date_format(petition.government_response.responded_on) %></p>
<p><%= petition.government_response.summary %></p>
<p><%= signature_count(:default, petition.signature_count) %></p>
30 changes: 30 additions & 0 deletions spec/helpers/search_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,34 @@
end
end
end

describe "#petition_result_path" do
let(:petition) { FactoryBot.create(:petition) }

subject { helper.petition_result_path(petition) }

it "generates the correct url" do
expect(subject).to eq("/petitions/#{petition.id}")
end

context "with an archived petition" do
let(:petition) { FactoryBot.create(:archived_petition) }

it "generates the correct url" do
expect(subject).to eq("/archived/petitions/#{petition.id}")
end
end

context "with options" do
let(:options) do
{ reveal_response: "yes", anchor: 'response-threshold' }
end

subject { helper.petition_result_path(petition, options) }

it "generates the correct url" do
expect(subject).to eq("/petitions/#{petition.id}?reveal_response=yes#response-threshold")
end
end
end
end

0 comments on commit 2679c68

Please sign in to comment.