Commit 94a1c70ace4d52132a697d04923b077b5ace69c9
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/171' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/171
Showing
2 changed files
with
33 additions
and
9 deletions
Show diff stats
app/models/tags_block.rb
@@ -20,7 +20,8 @@ class TagsBlock < Block | @@ -20,7 +20,8 @@ class TagsBlock < Block | ||
20 | end | 20 | end |
21 | 21 | ||
22 | def content(args={}) | 22 | def content(args={}) |
23 | - tags = owner.article_tags | 23 | + is_env = owner.class == Environment |
24 | + tags = is_env ? owner.tag_counts : owner.article_tags | ||
24 | return '' if tags.empty? | 25 | return '' if tags.empty? |
25 | 26 | ||
26 | if limit | 27 | if limit |
@@ -29,18 +30,28 @@ class TagsBlock < Block | @@ -29,18 +30,28 @@ class TagsBlock < Block | ||
29 | tags_tmp.map{ |k,v| tags[k] = v } | 30 | tags_tmp.map{ |k,v| tags[k] = v } |
30 | end | 31 | end |
31 | 32 | ||
33 | + url = is_env ? {:host=>owner.default_hostname, :controller=>'search', :action => 'tag'} : | ||
34 | + owner.public_profile_url.merge(:controller => 'profile', :action => 'tags') | ||
35 | + tagname_option = is_env ? :tag : :id | ||
36 | + | ||
32 | block_title(title) + | 37 | block_title(title) + |
33 | "\n<div class='tag_cloud'>\n"+ | 38 | "\n<div class='tag_cloud'>\n"+ |
34 | - tag_cloud( tags, :id, | ||
35 | - owner.public_profile_url.merge(:controller => 'profile', :action => 'tags'), | ||
36 | - :max_size => 16, :min_size => 9 ) + | 39 | + tag_cloud( tags, tagname_option, url, :max_size => 16, :min_size => 9 ) + |
37 | "\n</div><!-- end class='tag_cloud' -->\n"; | 40 | "\n</div><!-- end class='tag_cloud' -->\n"; |
38 | end | 41 | end |
39 | 42 | ||
40 | def footer | 43 | def footer |
41 | - owner_id = owner.identifier | ||
42 | - lambda do | ||
43 | - link_to s_('tags|View all'), :profile => owner_id, :controller => 'profile', :action => 'tags' | 44 | + if owner.class == Environment |
45 | + lambda do | ||
46 | + link_to s_('tags|View all'), | ||
47 | + :controller => 'search', :action => 'tags' | ||
48 | + end | ||
49 | + else | ||
50 | + owner_id = owner.identifier | ||
51 | + lambda do | ||
52 | + link_to s_('tags|View all'), | ||
53 | + :profile => owner_id, :controller => 'profile', :action => 'tags' | ||
54 | + end | ||
44 | end | 55 | end |
45 | end | 56 | end |
46 | 57 |
test/unit/tags_block_test.rb
@@ -22,9 +22,22 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -22,9 +22,22 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
22 | end | 22 | end |
23 | 23 | ||
24 | should 'generate links to tags' do | 24 | should 'generate links to tags' do |
25 | - assert_match /profile\/testinguser\/tags\/first-tag/, block.content | 25 | + assert_match /profile\/testinguser\/tags\/first-tag/, block.content |
26 | assert_match /profile\/testinguser\/tags\/second-tag/, block.content | 26 | assert_match /profile\/testinguser\/tags\/second-tag/, block.content |
27 | - assert_match /profile\/testinguser\/tags\/third-tag/, block.content | 27 | + assert_match /profile\/testinguser\/tags\/third-tag/, block.content |
28 | + end | ||
29 | + | ||
30 | + should 'generate links to tags on a environment page' do | ||
31 | + @otheruser = create_user('othertestinguser').person | ||
32 | + @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save! | ||
33 | + @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! | ||
34 | + box = Box.create!(:owner => Environment.default) | ||
35 | + @block = TagsBlock.create!(:box => box) | ||
36 | + | ||
37 | + assert_match /\/tag\/first-tag" [^>]+"3 items"/, block.content | ||
38 | + assert_match /\/tag\/second-tag" [^>]+"3 items"/, block.content | ||
39 | + assert_match /\/tag\/third-tag" [^>]+"one item"/, block.content | ||
40 | + assert_match /\/tag\/other-tag" [^>]+"2 items"/, block.content | ||
28 | end | 41 | end |
29 | 42 | ||
30 | should 'return (none) when no tags to display' do | 43 | should 'return (none) when no tags to display' do |