diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 046890df8..cee6db199 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,17 +1,4 @@ module ApplicationHelper - - def tags(debate, limit = nil) - tag_names = debate.tag_list_with_limit(limit) - - tag_names.sort.map do |tag| - link_to sanitize(tag), debates_path(tag: tag) - end.join('').html_safe.tap do |output| - if limit && extra_tags = debate.tags_count_out_of_limit(limit) - output.concat(link_to("#{extra_tags}+", debate_path(debate))) - end - end - end - def percentage(vote, debate) return "0%" if debate.total_votes == 0 debate.send(vote).percent_of(debate.total_votes).to_s + "%" diff --git a/app/models/debate.rb b/app/models/debate.rb index 2d9dab815..aa7630cd5 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -47,8 +47,12 @@ class Debate < ActiveRecord::Base end def tags_count_out_of_limit(limit = nil) - count = tags.count - limit - count < 0 ? 0 : count + if limit + count = tags.count - limit + count < 0 ? 0 : count + else + 0 + end end protected diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb index 93c94b571..6a61bd4b4 100644 --- a/app/views/shared/_tags.html.erb +++ b/app/views/shared/_tags.html.erb @@ -1,5 +1,13 @@ <%- limit ||= nil %> <% if debate.tags.any? %> - <%= tags(debate, limit) %> + + <% debate.tag_list_with_limit(limit).each do |tag| %> + <%= link_to sanitize(tag), debates_path(tag: tag) %> + <% end %> + + <% if debate.tags_count_out_of_limit(limit) > 0 %> + <%= link_to "#{debate.tags_count_out_of_limit(limit)}+", debate_path(debate) %> + <% end %> + <% end %> diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index ccbee0a93..de3e05943 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -138,14 +138,13 @@ feature 'Debates' do create :debate, tag_list: all_tags } - scenario 'Index page show up to 5 tags per debate' do + scenario 'Index page shows up to 5 tags per debate' do debate visible_tags = ["Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] visit debates_path - expect(page).to have_selector('.debate', count: 1) - within('.debate') do + within('.debate .tags') do visible_tags.each do |tag| expect(page).to have_content tag end @@ -153,6 +152,20 @@ feature 'Debates' do end end + scenario 'Index page shows 3 tags with no plus link' do + tag_list = ["Medio Ambiente", "Corrupción", "Fiestas populares"] + debate = create :debate, tag_list: tag_list + + visit debates_path + + within('.debate .tags') do + tag_list.each do |tag| + expect(page).to have_content tag + end + expect(page).not_to have_content '+' + end + end + scenario 'Debate#show shows the full tag list' do visit debate_path(debate)