From 166b195aa196b98c03e0194d025532ca3de0a91f Mon Sep 17 00:00:00 2001 From: Aurelio A. Heckert Date: Thu, 24 May 2012 21:32:22 -0300 Subject: [PATCH] TagsBlock works as env block --- app/models/tags_block.rb | 25 ++++++++++++++++++------- test/unit/tags_block_test.rb | 17 +++++++++++++++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb index c034dc6..ad89da6 100644 --- a/app/models/tags_block.rb +++ b/app/models/tags_block.rb @@ -20,7 +20,8 @@ class TagsBlock < Block end def content(args={}) - tags = owner.article_tags + is_env = owner.class == Environment + tags = is_env ? owner.tag_counts : owner.article_tags return '' if tags.empty? if limit @@ -29,18 +30,28 @@ class TagsBlock < Block tags_tmp.map{ |k,v| tags[k] = v } end + url = is_env ? {:host=>owner.default_hostname, :controller=>'search', :action => 'tag'} : + owner.public_profile_url.merge(:controller => 'profile', :action => 'tags') + tagname_option = is_env ? :tag : :id + block_title(title) + "\n
\n"+ - tag_cloud( tags, :id, - owner.public_profile_url.merge(:controller => 'profile', :action => 'tags'), - :max_size => 16, :min_size => 9 ) + + tag_cloud( tags, tagname_option, url, :max_size => 16, :min_size => 9 ) + "\n
\n"; end def footer - owner_id = owner.identifier - lambda do - link_to s_('tags|View all'), :profile => owner_id, :controller => 'profile', :action => 'tags' + if owner.class == Environment + lambda do + link_to s_('tags|View all'), + :controller => 'search', :action => 'tags' + end + else + owner_id = owner.identifier + lambda do + link_to s_('tags|View all'), + :profile => owner_id, :controller => 'profile', :action => 'tags' + end end end diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb index c0ada0d..fde7bb7 100644 --- a/test/unit/tags_block_test.rb +++ b/test/unit/tags_block_test.rb @@ -22,9 +22,22 @@ class TagsBlockTest < ActiveSupport::TestCase end should 'generate links to tags' do - assert_match /profile\/testinguser\/tags\/first-tag/, block.content + assert_match /profile\/testinguser\/tags\/first-tag/, block.content assert_match /profile\/testinguser\/tags\/second-tag/, block.content - assert_match /profile\/testinguser\/tags\/third-tag/, block.content + assert_match /profile\/testinguser\/tags\/third-tag/, block.content + end + + should 'generate links to tags on a environment page' do + @otheruser = create_user('othertestinguser').person + @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save! + @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! + box = Box.create!(:owner => Environment.default) + @block = TagsBlock.create!(:box => box) + + assert_match /\/tag\/first-tag" [^>]+"3 items"/, block.content + assert_match /\/tag\/second-tag" [^>]+"3 items"/, block.content + assert_match /\/tag\/third-tag" [^>]+"one item"/, block.content + assert_match /\/tag\/other-tag" [^>]+"2 items"/, block.content end should 'return (none) when no tags to display' do -- libgit2 0.21.2