Commit f51b6082b49021f41faff079410fdb463a2bc478
Committed by
Joenio Costa
1 parent
6c1289d2
Exists in
master
and in
28 other branches
Order tags alphabetically
(ActionItem1325)
Showing
4 changed files
with
27 additions
and
2 deletions
Show diff stats
app/helpers/tags_helper.rb
@@ -28,7 +28,6 @@ module TagsHelper | @@ -28,7 +28,6 @@ module TagsHelper | ||
28 | # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem | 28 | # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem |
29 | # (pt_BR only). | 29 | # (pt_BR only). |
30 | def tag_cloud(tags, tagname_option, url, options = {}) | 30 | def tag_cloud(tags, tagname_option, url, options = {}) |
31 | - | ||
32 | 31 | ||
33 | return content_tag('em', _('No tags yet.')) + | 32 | return content_tag('em', _('No tags yet.')) + |
34 | ' <a href="' + _('http://en.wikipedia.org/wiki/Tag_%28metadata%29') + | 33 | ' <a href="' + _('http://en.wikipedia.org/wiki/Tag_%28metadata%29') + |
@@ -42,7 +41,7 @@ module TagsHelper | @@ -42,7 +41,7 @@ module TagsHelper | ||
42 | max = tags.values.max.to_f | 41 | max = tags.values.max.to_f |
43 | min = tags.values.min.to_f | 42 | min = tags.values.min.to_f |
44 | 43 | ||
45 | - tags.map do |tag,count| | 44 | + tags.sort_by{ |k,v| k.downcase }.map do |tag,count| |
46 | if ( max == min ) | 45 | if ( max == min ) |
47 | v = 0.5 | 46 | v = 0.5 |
48 | else | 47 | else |
public/designs/themes/base/style.css
test/unit/tags_block_test.rb
@@ -37,4 +37,8 @@ class TagsBlockTest < Test::Unit::TestCase | @@ -37,4 +37,8 @@ class TagsBlockTest < Test::Unit::TestCase | ||
37 | assert_match /profile\/testinguser\/tags\/first-tag/, block.content | 37 | assert_match /profile\/testinguser\/tags\/first-tag/, block.content |
38 | end | 38 | end |
39 | 39 | ||
40 | + should 'order tags alphabetically' do | ||
41 | + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content | ||
42 | + end | ||
43 | + | ||
40 | end | 44 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class TagsHelperTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + include ApplicationHelper | ||
6 | + include TagsHelper | ||
7 | + include ActionController::UrlWriter | ||
8 | + | ||
9 | + def h(s); s; end | ||
10 | + def link_to(text, *args); text; end | ||
11 | + | ||
12 | + should 'order tags alphabetically' do | ||
13 | + result = tag_cloud( | ||
14 | + { 'tag1'=>9, 'Tag3'=>2, 'Tag2'=>2, 'aTag'=>2, 'beTag'=>2 }, | ||
15 | + :id, | ||
16 | + { :host=>'noosfero.org', :controller=>'test', :action=>'tag' } | ||
17 | + ) | ||
18 | + assert_equal %w(aTag beTag tag1 Tag2 Tag3).join("\n"), result | ||
19 | + end | ||
20 | + | ||
21 | +end |