Commit 94a1c70ace4d52132a697d04923b077b5ace69c9

Authored by Rodrigo Souto
2 parents 3b7ee15c 166b195a

Merge commit 'refs/merge-requests/171' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/171
app/models/tags_block.rb
... ... @@ -20,7 +20,8 @@ class TagsBlock < Block
20 20 end
21 21  
22 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 25 return '' if tags.empty?
25 26  
26 27 if limit
... ... @@ -29,18 +30,28 @@ class TagsBlock < Block
29 30 tags_tmp.map{ |k,v| tags[k] = v }
30 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 37 block_title(title) +
33 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 40 "\n</div><!-- end class='tag_cloud' -->\n";
38 41 end
39 42  
40 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 55 end
45 56 end
46 57  
... ...
test/unit/tags_block_test.rb
... ... @@ -22,9 +22,22 @@ class TagsBlockTest &lt; ActiveSupport::TestCase
22 22 end
23 23  
24 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 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 41 end
29 42  
30 43 should 'return (none) when no tags to display' do
... ...