Merge pull request #289 from jjballano/225-reorder-tags

#225 : Tag cloud ordered by count and name
This commit is contained in:
Juanjo Bazán
2015-08-29 19:47:19 +02:00
3 changed files with 9 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ class DebatesController < ApplicationController
def index def index
@debates = Debate.search(params).page(params[:page]).for_render.send("sort_by_#{@order}") @debates = Debate.search(params).page(params[:page]).for_render.send("sort_by_#{@order}")
@tags = ActsAsTaggableOn::Tag.all @tags = ActsAsTaggableOn::Tag.all
@tag_cloud = Debate.tag_counts.order('count desc, name asc')
set_debate_votes(@debates) set_debate_votes(@debates)
end end

View File

@@ -2,7 +2,7 @@
<div class="sidebar-divider"></div> <div class="sidebar-divider"></div>
<h3><%= t("shared.tags_cloud.tags") %></h3> <h3><%= t("shared.tags_cloud.tags") %></h3>
<br> <br>
<% tag_cloud Debate.tag_counts, %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} <span class='label round info'>#{tag.taggings_count}</span>"), debates_path(tag: tag.name), class: css_class %> <%= link_to sanitize("#{tag.name} <span class='label round info'>#{tag.taggings_count}</span>"), debates_path(tag: tag.name), class: css_class %>
<% end %> <% end %>
</div> </div>

View File

@@ -47,13 +47,17 @@ feature 'Tags' do
scenario 'Tag Cloud' do scenario 'Tag Cloud' do
1.times { create(:debate, tag_list: 'Medio Ambiente') } 1.times { create(:debate, tag_list: 'Medio Ambiente') }
5.times { create(:debate, tag_list: 'Corrupción') } 5.times { create(:debate, tag_list: 'Corrupción') }
5.times { create(:debate, tag_list: 'Educación') }
10.times { create(:debate, tag_list: 'Economía') } 10.times { create(:debate, tag_list: 'Economía') }
visit debates_path visit debates_path
within(:css, "#tag-cloud .s") { expect(page).to have_content('Medio Ambiente 1') } within(:css, "#tag-cloud") do
within(:css, "#tag-cloud .m") { expect(page).to have_content('Corrupción 5') } expect(page.find("a:eq(1)")).to have_content("Economía 10")
within(:css, "#tag-cloud .l") { expect(page).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 end
scenario 'Create' do scenario 'Create' do