Fix tag links on legislation proposals

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 <javim@elretirao.net>
This commit is contained in:
Senén Rodero Rodríguez
2021-01-30 14:04:55 +01:00
committed by Javi Martín
parent 35db41827c
commit 450b157a5e
3 changed files with 34 additions and 1 deletions

View File

@@ -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

View File

@@ -7,7 +7,7 @@
<% taggable.tag_list_with_limit(limit).each do |tag| %>
<li>
<%= link_to sanitize(tag.name),
polymorphic_path(taggable.class, search: tag.name) %></li>
taggables_path(taggable, tag.name) %></li>
<% end %>
<% if taggable.tags_count_out_of_limit(limit) > 0 %>

View File

@@ -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