From 450b157a5e2ef993b2f1373f01b4656df6a18deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Sat, 30 Jan 2021 14:04:55 +0100 Subject: [PATCH] Fix tag links on legislation proposals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On commit 1a902a96 we removed this helper to make use of polymorphic routes but when it's called for Legislation::Proposal fails as the namespace does not match the model namespace. Now we recover the removed helper but only the parts that do not work with polymorphic_url helper. Co-Authored-By: Javi Martín --- app/helpers/tags_helper.rb | 10 ++++++++++ app/views/shared/_tags.html.erb | 2 +- spec/system/legislation/proposals_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/helpers/tags_helper.rb diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 000000000..464a155d0 --- /dev/null +++ b/app/helpers/tags_helper.rb @@ -0,0 +1,10 @@ +module TagsHelper + def taggables_path(taggable, tag_name) + case taggable.class.name + when "Legislation::Proposal" + legislation_process_proposals_path(taggable.process, search: tag_name) + else + polymorphic_path(taggable.class, search: tag_name) + end + end +end diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb index 103455017..f4ac1773e 100644 --- a/app/views/shared/_tags.html.erb +++ b/app/views/shared/_tags.html.erb @@ -7,7 +7,7 @@ <% taggable.tag_list_with_limit(limit).each do |tag| %>
  • <%= link_to sanitize(tag.name), - polymorphic_path(taggable.class, search: tag.name) %>
  • + taggables_path(taggable, tag.name) %> <% end %> <% if taggable.tags_count_out_of_limit(limit) > 0 %> diff --git a/spec/system/legislation/proposals_spec.rb b/spec/system/legislation/proposals_spec.rb index db773cf69..22c83211d 100644 --- a/spec/system/legislation/proposals_spec.rb +++ b/spec/system/legislation/proposals_spec.rb @@ -210,4 +210,27 @@ describe "Legislation Proposals" do expect(page).to have_link(process.title) end end + + scenario "Shows proposal tags as proposals filter", :js do + create(:legislation_proposal, process: process, tag_list: "Culture", title: "Open concert") + create(:legislation_proposal, process: process, tag_list: "Sports", title: "Baseball field") + + visit legislation_process_proposals_path(process) + + expect(page).to have_content "Open concert" + expect(page).to have_content "Baseball field" + + click_link "Culture" + + expect(page).not_to have_content "Baseball field" + expect(page).to have_content "Open concert" + end + + scenario "Show proposal tags on show", :js do + proposal = create(:legislation_proposal, process: process, tag_list: "Culture") + + visit legislation_process_proposal_path(proposal.process, proposal) + + expect(page).to have_link("Culture") + end end