diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index de03f4efb..286d2a297 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -73,7 +73,7 @@ module CommentableActions end def tag_cloud - TagCloud.new(resource_model, params[:search]).tags + TagCloud.new(resource_model, params[:search]) end def load_geozones diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index f6363a864..da7824622 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -11,18 +11,4 @@ module TagsHelper end end - def taggable_counter_field(taggable_type) - "#{taggable_type.underscore.pluralize}_count" - end - - def tag_cloud(tags, classes, counter_field = :taggings_count) - return [] if tags.empty? - - max_count = tags.sort_by(&counter_field).last.send(counter_field).to_f - - tags.each do |tag| - index = ((tag.send(counter_field) / max_count) * (classes.size - 1)) - yield tag, classes[index.nan? ? 0 : index.round] - end - end end diff --git a/app/views/shared/_tag_cloud.html.erb b/app/views/shared/_tag_cloud.html.erb index 34e90c714..6b27de955 100644 --- a/app/views/shared/_tag_cloud.html.erb +++ b/app/views/shared/_tag_cloud.html.erb @@ -3,8 +3,8 @@
- <% tag_cloud @tag_cloud, %w[s m l] do |tag, css_class| %> - <%= link_to taggable_path(taggable, tag.name), class: css_class do %> + <% @tag_cloud.tags.each do |tag| %> + <%= link_to taggable_path(taggable, tag.name) do %> <%= tag.name %> <% end %> <% end %> diff --git a/spec/features/tags_spec.rb b/spec/features/tags_spec.rb index a6ecc739f..0b95e1de4 100644 --- a/spec/features/tags_spec.rb +++ b/spec/features/tags_spec.rb @@ -54,22 +54,6 @@ feature 'Tags' do expect(page).to have_content "Hacienda" end - scenario 'Tag Cloud' do - 1.times { create(:debate, tag_list: 'Medio Ambiente') } - 5.times { create(:debate, tag_list: 'Corrupción') } - 5.times { create(:debate, tag_list: 'Educación') } - 10.times { create(:debate, tag_list: 'Economía') } - - visit debates_path - - within(:css, "#tag-cloud") do - expect(page.find("a:eq(1)")).to have_content("Economía") - expect(page.find("a:eq(2)")).to have_content("Corrupción") - expect(page.find("a:eq(3)")).to have_content("Educación") - expect(page.find("a:eq(4)")).to have_content("Medio Ambiente") - end - end - scenario 'Create' do user = create(:user) login_as(user) @@ -199,6 +183,23 @@ feature 'Tags' do end end + scenario "tag links" do + proposal1 = create(:proposal, tag_list: 'Medio Ambiente') + proposal2 = create(:proposal, tag_list: 'Medio Ambiente') + proposal3 = create(:proposal, tag_list: 'Economía') + + visit proposals_path + + within "#tag-cloud" do + click_link "Medio Ambiente" + end + + expect(page).to have_css ".proposal", count: 2 + expect(page).to have_content proposal1.title + expect(page).to have_content proposal2.title + expect(page).to_not have_content proposal3.title + end + end end