Commit b4ca3878f6345cd12f597b12f37a3d3cd4eea80f
1 parent
9f003eb0
Exists in
web_steps_improvements
and in
9 other branches
Fix TagsBlock unit test
By removing the content method, it is now necessary to turn the test into a view one using the BoxesHelper method and properly stubbing other helpers. This was inspired by the same conversion made by commit 23cca52cdaea5cc3b46e4982f30ad3426891e2f2 on MyNetworkBlock test.
Showing
1 changed file
with
48 additions
and
19 deletions
Show diff stats
test/unit/tags_block_test.rb
@@ -27,7 +27,53 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -27,7 +27,53 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
27 | 27 | ||
28 | include BoxesHelper | 28 | include BoxesHelper |
29 | 29 | ||
30 | + should 'return the max value in the range between zero and limit' do | ||
31 | + block = TagsBlock.new | ||
32 | + assert_equal 12, block.get_limit | ||
33 | + end | ||
34 | + | ||
35 | + should '' do | ||
36 | + block = TagsBlock.new | ||
37 | + block.limit = -5 | ||
38 | + assert_equal 0, block.get_limit | ||
39 | + end | ||
40 | +end | ||
41 | + | ||
42 | +require 'tags_helper' | ||
43 | + | ||
44 | +class TagsBlockViewTest < ActionView::TestCase | ||
45 | + include BoxesHelper | ||
46 | + | ||
47 | + ActionView::Base.send :include, TagsHelper | ||
48 | + | ||
49 | + def setup | ||
50 | + @user = create_user('testinguser').person | ||
51 | + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! | ||
52 | + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! | ||
53 | + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! | ||
54 | + | ||
55 | + box = Box.new | ||
56 | + box.owner = @user | ||
57 | + box.save! | ||
58 | + @block = TagsBlock.new | ||
59 | + @block.box = box | ||
60 | + @block.save | ||
61 | + end | ||
62 | + attr_reader :block | ||
63 | + | ||
64 | + should 'return (none) when no tags to display' do | ||
65 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
66 | + block.owner.expects(:article_tags).returns([]) | ||
67 | + assert_equal "\n\n\n", render_block_content(block) | ||
68 | + end | ||
69 | + | ||
70 | + should 'order tags alphabetically' do | ||
71 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
72 | + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) | ||
73 | + end | ||
74 | + | ||
30 | should 'generate links to tags' do | 75 | should 'generate links to tags' do |
76 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
31 | content = render_block_content(block) | 77 | content = render_block_content(block) |
32 | assert_match /profile\/testinguser\/tags\/first-tag/, content | 78 | assert_match /profile\/testinguser\/tags\/first-tag/, content |
33 | assert_match /profile\/testinguser\/tags\/second-tag/, content | 79 | assert_match /profile\/testinguser\/tags\/second-tag/, content |
@@ -40,6 +86,7 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -40,6 +86,7 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
40 | @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! | 86 | @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! |
41 | box = create(Box, :owner => Environment.default) | 87 | box = create(Box, :owner => Environment.default) |
42 | @block = create(TagsBlock, :box => box) | 88 | @block = create(TagsBlock, :box => box) |
89 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
43 | 90 | ||
44 | content = render_block_content(block) | 91 | content = render_block_content(block) |
45 | assert_match /3 items[^>]+\/tag\/first-tag/, content | 92 | assert_match /3 items[^>]+\/tag\/first-tag/, content |
@@ -48,28 +95,10 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -48,28 +95,10 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
48 | assert_match /2 item[^>]+\/tag\/other-tag"/, content | 95 | assert_match /2 item[^>]+\/tag\/other-tag"/, content |
49 | end | 96 | end |
50 | 97 | ||
51 | - should 'return (none) when no tags to display' do | ||
52 | - block.owner.expects(:article_tags).returns([]) | ||
53 | - assert_equal '', render_block_content(block) | ||
54 | - end | ||
55 | 98 | ||
56 | should 'generate links when profile has own hostname' do | 99 | should 'generate links when profile has own hostname' do |
57 | @user.domains << Domain.new(:name => 'testuser.net'); @user.save! | 100 | @user.domains << Domain.new(:name => 'testuser.net'); @user.save! |
101 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
58 | assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) | 102 | assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) |
59 | end | 103 | end |
60 | - | ||
61 | - should 'order tags alphabetically' do | ||
62 | - assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) | ||
63 | - end | ||
64 | - | ||
65 | - should 'return the max value in the range between zero and limit' do | ||
66 | - block = TagsBlock.new | ||
67 | - assert_equal 12, block.get_limit | ||
68 | - end | ||
69 | - | ||
70 | - should '' do | ||
71 | - block = TagsBlock.new | ||
72 | - block.limit = -5 | ||
73 | - assert_equal 0, block.get_limit | ||
74 | - end | ||
75 | end | 104 | end |