From b4ca3878f6345cd12f597b12f37a3d3cd4eea80f Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Sat, 27 Feb 2016 14:52:59 -0300 Subject: [PATCH] Fix TagsBlock unit test --- test/unit/tags_block_test.rb | 67 ++++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb index 4cb1041..f4ab125 100644 --- a/test/unit/tags_block_test.rb +++ b/test/unit/tags_block_test.rb @@ -27,7 +27,53 @@ class TagsBlockTest < ActiveSupport::TestCase include BoxesHelper + should 'return the max value in the range between zero and limit' do + block = TagsBlock.new + assert_equal 12, block.get_limit + end + + should '' do + block = TagsBlock.new + block.limit = -5 + assert_equal 0, block.get_limit + end +end + +require 'tags_helper' + +class TagsBlockViewTest < ActionView::TestCase + include BoxesHelper + + ActionView::Base.send :include, TagsHelper + + def setup + @user = create_user('testinguser').person + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! + + box = Box.new + box.owner = @user + box.save! + @block = TagsBlock.new + @block.box = box + @block.save + end + attr_reader :block + + should 'return (none) when no tags to display' do + ActionView::Base.any_instance.stubs(:block_title).returns("") + block.owner.expects(:article_tags).returns([]) + assert_equal "\n\n\n", render_block_content(block) + end + + should 'order tags alphabetically' do + ActionView::Base.any_instance.stubs(:block_title).returns("") + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) + end + should 'generate links to tags' do + ActionView::Base.any_instance.stubs(:block_title).returns("") content = render_block_content(block) assert_match /profile\/testinguser\/tags\/first-tag/, content assert_match /profile\/testinguser\/tags\/second-tag/, content @@ -40,6 +86,7 @@ class TagsBlockTest < ActiveSupport::TestCase @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! box = create(Box, :owner => Environment.default) @block = create(TagsBlock, :box => box) + ActionView::Base.any_instance.stubs(:block_title).returns("") content = render_block_content(block) assert_match /3 items[^>]+\/tag\/first-tag/, content @@ -48,28 +95,10 @@ class TagsBlockTest < ActiveSupport::TestCase assert_match /2 item[^>]+\/tag\/other-tag"/, content end - should 'return (none) when no tags to display' do - block.owner.expects(:article_tags).returns([]) - assert_equal '', render_block_content(block) - end should 'generate links when profile has own hostname' do @user.domains << Domain.new(:name => 'testuser.net'); @user.save! + ActionView::Base.any_instance.stubs(:block_title).returns("") assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) end - - should 'order tags alphabetically' do - assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) - end - - should 'return the max value in the range between zero and limit' do - block = TagsBlock.new - assert_equal 12, block.get_limit - end - - should '' do - block = TagsBlock.new - block.limit = -5 - assert_equal 0, block.get_limit - end end -- libgit2 0.21.2