From a67c0abcecab9257ff4f0879f736a8560af9a03a Mon Sep 17 00:00:00 2001 From: jjballano Date: Sat, 29 Aug 2015 18:16:02 +0100 Subject: [PATCH 1/2] #225 : Tag cloud ordered by count and name --- app/views/shared/_tag_cloud.html.erb | 2 +- spec/features/tags_spec.rb | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/shared/_tag_cloud.html.erb b/app/views/shared/_tag_cloud.html.erb index 9fb4ff371..806708f1c 100644 --- a/app/views/shared/_tag_cloud.html.erb +++ b/app/views/shared/_tag_cloud.html.erb @@ -2,7 +2,7 @@

<%= t("shared.tags_cloud.tags") %>


- <% tag_cloud Debate.tag_counts, %w[s m l] do |tag, css_class| %> + <% tag_cloud Debate.tag_counts.order('count desc, name asc'), %w[s m l] do |tag, css_class| %> <%= link_to sanitize("#{tag.name} #{tag.taggings_count}"), debates_path(tag: tag.name), class: css_class %> <% end %> diff --git a/spec/features/tags_spec.rb b/spec/features/tags_spec.rb index a15902dc7..d6c1eba8b 100644 --- a/spec/features/tags_spec.rb +++ b/spec/features/tags_spec.rb @@ -47,13 +47,17 @@ feature 'Tags' do 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 .s") { expect(page).to have_content('Medio Ambiente 1') } - within(:css, "#tag-cloud .m") { expect(page).to have_content('Corrupción 5') } - within(:css, "#tag-cloud .l") { expect(page).to have_content('Economía 10') } + within(:css, "#tag-cloud") do + expect(page.find("a:eq(1)")).to have_content("Economía 10") + expect(page.find("a:eq(2)")).to have_content("Corrupción 5") + expect(page.find("a:eq(3)")).to have_content("Educación 5") + expect(page.find("a:eq(4)")).to have_content("Medio Ambiente 1") + end end scenario 'Create' do From 46f334f38c3f0648fffa64d91225f859b882b4a6 Mon Sep 17 00:00:00 2001 From: jjballano Date: Sat, 29 Aug 2015 18:43:23 +0100 Subject: [PATCH 2/2] #225 : refactor --- app/controllers/debates_controller.rb | 1 + app/views/shared/_tag_cloud.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 85ca6d496..9e5247134 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -8,6 +8,7 @@ class DebatesController < ApplicationController def index @debates = Debate.search(params).page(params[:page]).for_render.send("sort_by_#{@order}") @tags = ActsAsTaggableOn::Tag.all + @tag_cloud = Debate.tag_counts.order('count desc, name asc') set_debate_votes(@debates) end diff --git a/app/views/shared/_tag_cloud.html.erb b/app/views/shared/_tag_cloud.html.erb index 806708f1c..737fc3a94 100644 --- a/app/views/shared/_tag_cloud.html.erb +++ b/app/views/shared/_tag_cloud.html.erb @@ -2,7 +2,7 @@

<%= t("shared.tags_cloud.tags") %>


- <% tag_cloud Debate.tag_counts.order('count desc, name asc'), %w[s m l] do |tag, css_class| %> + <% tag_cloud @tag_cloud, %w[s m l] do |tag, css_class| %> <%= link_to sanitize("#{tag.name} #{tag.taggings_count}"), debates_path(tag: tag.name), class: css_class %> <% end %>