Commit 335b1bedf51360d6a69cbf32e804a95610e53dfe
Committed by
Rafael Reggiani Manzo
1 parent
c90084dc
Exists in
web_steps_improvements
and in
9 other branches
fixing unit tests for Block models (50% done)
Showing
11 changed files
with
85 additions
and
47 deletions
Show diff stats
app/views/blocks/profile_list.html.erb
1 | <%= block_title(block.view_title) %> | 1 | <%= block_title(block.view_title) %> |
2 | 2 | ||
3 | <% | 3 | <% |
4 | - count=0 | ||
5 | - list = block.profile_list.map {|item| count+=1 block.send(:profile_image_link, item, :minor)}.join("\n ") | 4 | + list = block.profile_list.map do |item| |
5 | + profile_image_link(item, :minor) | ||
6 | + end.join("\n ") | ||
6 | %> | 7 | %> |
7 | 8 | ||
8 | <div> | 9 | <div> |
app/views/blocks/tags.html.erb
@@ -14,11 +14,11 @@ | @@ -14,11 +14,11 @@ | ||
14 | <div class='tag_cloud'> | 14 | <div class='tag_cloud'> |
15 | <% if is_env %> | 15 | <% if is_env %> |
16 | <%= tag_cloud(tags, :tag, | 16 | <%= tag_cloud(tags, :tag, |
17 | - {:host=>block.owner.default_hostname, :controller=>'search', :action => 'tag'}, | 17 | + {:host => block.owner.default_hostname, :controller=>'search', :action => 'tag'}, |
18 | :max_size => 16, :min_size => 9) %> | 18 | :max_size => 16, :min_size => 9) %> |
19 | <% else %> | 19 | <% else %> |
20 | <%= tag_cloud(tags, :id, | 20 | <%= tag_cloud(tags, :id, |
21 | - owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'), | 21 | + block.owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'), |
22 | :max_size => 16, :min_size => 9) %> | 22 | :max_size => 16, :min_size => 9) %> |
23 | <% end %> | 23 | <% end %> |
24 | </div> | 24 | </div> |
test/unit/categories_block_test.rb
@@ -17,11 +17,13 @@ class CategoriesBlockTest < ActiveSupport::TestCase | @@ -17,11 +17,13 @@ class CategoriesBlockTest < ActiveSupport::TestCase | ||
17 | assert_not_nil category_block.help | 17 | assert_not_nil category_block.help |
18 | end | 18 | end |
19 | 19 | ||
20 | + include BoxesHelper | ||
21 | + | ||
20 | should 'display category block' do | 22 | should 'display category block' do |
21 | block = CategoriesBlock.new | 23 | block = CategoriesBlock.new |
22 | 24 | ||
23 | self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block}) | 25 | self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block}) |
24 | - instance_eval(& block.content) | 26 | + render_block_content(block) |
25 | end | 27 | end |
26 | 28 | ||
27 | should 'be editable' do | 29 | should 'be editable' do |
test/unit/disabled_enterprise_message_block_test.rb
@@ -6,16 +6,25 @@ class DisabledEnterpriseMessageBlockTest < ActiveSupport::TestCase | @@ -6,16 +6,25 @@ class DisabledEnterpriseMessageBlockTest < ActiveSupport::TestCase | ||
6 | assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description | 6 | assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description |
7 | end | 7 | end |
8 | 8 | ||
9 | + include BoxesHelper | ||
10 | + | ||
9 | should 'display message for disabled enterprise' do | 11 | should 'display message for disabled enterprise' do |
10 | - e = Environment.default | ||
11 | - e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises') | ||
12 | - block = DisabledEnterpriseMessageBlock.new | ||
13 | - p = Profile.new | ||
14 | - block.expects(:owner).returns(p) | ||
15 | - p.expects(:environment).returns(e) | ||
16 | - | ||
17 | - expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => 'This message is for disabled enterprises'}) | ||
18 | - instance_eval(&block.content) | 12 | + environment = Environment.default |
13 | + environment.message_for_disabled_enterprise = 'This message is for disabled enterprises' | ||
14 | + environment.save | ||
15 | + | ||
16 | + enterprise = fast_create(Enterprise, :identifier => 'disabled-enterprise', :environment_id => environment.id) | ||
17 | + enterprise.boxes << Box.new | ||
18 | + enterprise.boxes.first.blocks << DisabledEnterpriseMessageBlock.new | ||
19 | + block = enterprise.boxes.first.blocks.first | ||
20 | + | ||
21 | + ApplicationHelper.class_eval do | ||
22 | + def profile | ||
23 | + return Enterprise['disabled-enterprise'] | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + assert_match 'This message is for disabled enterprises', render_block_content(block) | ||
19 | end | 28 | end |
20 | 29 | ||
21 | should 'not be editable' do | 30 | should 'not be editable' do |
test/unit/highlights_block_test.rb
@@ -80,11 +80,13 @@ class HighlightsBlockTest < ActiveSupport::TestCase | @@ -80,11 +80,13 @@ class HighlightsBlockTest < ActiveSupport::TestCase | ||
80 | assert_equal 'always', block.display | 80 | assert_equal 'always', block.display |
81 | end | 81 | end |
82 | 82 | ||
83 | + include BoxesHelper | ||
84 | + | ||
83 | should 'display highlights block' do | 85 | should 'display highlights block' do |
84 | block = HighlightsBlock.new | 86 | block = HighlightsBlock.new |
85 | self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block}) | 87 | self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block}) |
86 | 88 | ||
87 | - instance_eval(& block.content) | 89 | + render_block_content(block) |
88 | end | 90 | end |
89 | 91 | ||
90 | should 'not list non existent image' do | 92 | should 'not list non existent image' do |
@@ -167,7 +169,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase | @@ -167,7 +169,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase | ||
167 | block.images = [i1] | 169 | block.images = [i1] |
168 | block.save! | 170 | block.save! |
169 | 171 | ||
170 | - assert_tag_in_string instance_eval(& block.content), :tag => 'img', :attributes => { :src => "/social/img_address" } | 172 | + assert_tag_in_string render_block_content(block), :tag => 'img', :attributes => { :src => "/social/img_address" } |
171 | end | 173 | end |
172 | 174 | ||
173 | [Environment, Profile].each do |klass| | 175 | [Environment, Profile].each do |klass| |
test/unit/my_network_block_test.rb
@@ -19,14 +19,6 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | @@ -19,14 +19,6 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | ||
19 | assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title | 19 | assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title |
20 | end | 20 | end |
21 | 21 | ||
22 | - should 'display my-profile' do | ||
23 | - self.expects(:render).with(:file => 'blocks/my_network', :locals => { | ||
24 | - :title => 'My network', | ||
25 | - :owner => owner | ||
26 | - }) | ||
27 | - instance_eval(&block.content) | ||
28 | - end | ||
29 | - | ||
30 | should 'be able to update display setting' do | 22 | should 'be able to update display setting' do |
31 | user = create_user('testinguser').person | 23 | user = create_user('testinguser').person |
32 | box = fast_create(Box, :owner_id => user.id) | 24 | box = fast_create(Box, :owner_id => user.id) |
@@ -37,3 +29,22 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | @@ -37,3 +29,22 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | ||
37 | end | 29 | end |
38 | 30 | ||
39 | end | 31 | end |
32 | + | ||
33 | +class MyNetworkBlockViewTest < ActionView::TestCase | ||
34 | + include BoxesHelper | ||
35 | + | ||
36 | + def setup | ||
37 | + @block = MyNetworkBlock.new | ||
38 | + @owner = Person.new(:identifier => 'testuser') | ||
39 | + @block.stubs(:owner).returns(@owner) | ||
40 | + owner.stubs(:environment).returns(Environment.default) | ||
41 | + end | ||
42 | + attr_reader :owner, :block | ||
43 | + | ||
44 | + should 'display my-profile' do | ||
45 | + ActionView::Base.any_instance.stubs(:block_title).with(anything).returns(true) | ||
46 | + ActionView::Base.any_instance.stubs(:user).with(anything).returns(owner) | ||
47 | + ActionView::Base.any_instance.stubs(:render_profile_actions) | ||
48 | + assert_match "#{Environment.default.top_url}/profile/testuser", render_block_content(block) | ||
49 | + end | ||
50 | +end |
test/unit/profile_info_block_test.rb
@@ -16,9 +16,11 @@ class ProfileInfoBlockTest < ActiveSupport::TestCase | @@ -16,9 +16,11 @@ class ProfileInfoBlockTest < ActiveSupport::TestCase | ||
16 | assert_not_equal Block.description, ProfileInfoBlock.description | 16 | assert_not_equal Block.description, ProfileInfoBlock.description |
17 | end | 17 | end |
18 | 18 | ||
19 | + include BoxesHelper | ||
20 | + | ||
19 | should 'display profile information' do | 21 | should 'display profile information' do |
20 | - self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block}) | ||
21 | - instance_eval(& block.content) | 22 | + self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block }) |
23 | + render_block_content(block) | ||
22 | end | 24 | end |
23 | 25 | ||
24 | end | 26 | end |
test/unit/profile_list_block_test.rb
@@ -20,6 +20,8 @@ class ProfileListBlockTest < ActiveSupport::TestCase | @@ -20,6 +20,8 @@ class ProfileListBlockTest < ActiveSupport::TestCase | ||
20 | assert_equal 20, block.limit | 20 | assert_equal 20, block.limit |
21 | end | 21 | end |
22 | 22 | ||
23 | + include BoxesHelper | ||
24 | + | ||
23 | should 'list people' do | 25 | should 'list people' do |
24 | env = fast_create(Environment) | 26 | env = fast_create(Environment) |
25 | 27 | ||
@@ -30,15 +32,16 @@ class ProfileListBlockTest < ActiveSupport::TestCase | @@ -30,15 +32,16 @@ class ProfileListBlockTest < ActiveSupport::TestCase | ||
30 | block = ProfileListBlock.new | 32 | block = ProfileListBlock.new |
31 | block.stubs(:owner).returns(env) | 33 | block.stubs(:owner).returns(env) |
32 | 34 | ||
33 | - self.expects(:profile_image_link).with(person1, :minor).once | ||
34 | - self.expects(:profile_image_link).with(person2, :minor).once | ||
35 | - self.expects(:profile_image_link).with(person3, :minor).once | ||
36 | - | ||
37 | - self.stubs(:tag).returns('<div></div>') | ||
38 | - self.expects(:content_tag).returns('<div></div>').at_least_once | ||
39 | - self.expects(:block_title).returns('block title').at_least_once | 35 | + ApplicationHelper.class_eval do |
36 | + def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) | ||
37 | + "<#{profile.name}>" | ||
38 | + end | ||
39 | + end | ||
40 | 40 | ||
41 | - assert_kind_of String, instance_eval(&block.content) | 41 | + content = render_block_content(block) |
42 | + assert_match '<testperson1>', content | ||
43 | + assert_match '<testperson2>', content | ||
44 | + assert_match '<testperson3>', content | ||
42 | end | 45 | end |
43 | 46 | ||
44 | should 'list private profiles' do | 47 | should 'list private profiles' do |
test/unit/profile_search_block_test.rb
@@ -10,14 +10,16 @@ class ProfileSearchBlockTest < ActiveSupport::TestCase | @@ -10,14 +10,16 @@ class ProfileSearchBlockTest < ActiveSupport::TestCase | ||
10 | assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title | 10 | assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title |
11 | end | 11 | end |
12 | 12 | ||
13 | + include BoxesHelper | ||
14 | + | ||
13 | should 'render profile search' do | 15 | should 'render profile search' do |
14 | person = fast_create(Person) | 16 | person = fast_create(Person) |
15 | 17 | ||
16 | block = ProfileSearchBlock.new | 18 | block = ProfileSearchBlock.new |
17 | block.stubs(:owner).returns(person) | 19 | block.stubs(:owner).returns(person) |
18 | 20 | ||
19 | - self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :title => block.title}) | ||
20 | - instance_eval(& block.content) | 21 | + self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :block => block }) |
22 | + render_block_content(block) | ||
21 | end | 23 | end |
22 | 24 | ||
23 | should 'provide view_title' do | 25 | should 'provide view_title' do |
test/unit/raw_html_block_test.rb
@@ -17,9 +17,11 @@ class RawHTMLBlockTest < ActiveSupport::TestCase | @@ -17,9 +17,11 @@ class RawHTMLBlockTest < ActiveSupport::TestCase | ||
17 | assert_equal html, block.html | 17 | assert_equal html, block.html |
18 | end | 18 | end |
19 | 19 | ||
20 | + include BoxesHelper | ||
21 | + | ||
20 | should 'return html as content' do | 22 | should 'return html as content' do |
21 | block = RawHTMLBlock.new(:html => "HTML") | 23 | block = RawHTMLBlock.new(:html => "HTML") |
22 | - assert_match(/HTML$/, block.content) | 24 | + assert_match /HTML$/, render_block_content(block) |
23 | end | 25 | end |
24 | 26 | ||
25 | should 'not be editable for users without permission' do | 27 | should 'not be editable for users without permission' do |
test/unit/tags_block_test.rb
@@ -25,10 +25,13 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -25,10 +25,13 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
25 | assert_not_equal Block.new.default_title, TagsBlock.new.default_title | 25 | assert_not_equal Block.new.default_title, TagsBlock.new.default_title |
26 | end | 26 | end |
27 | 27 | ||
28 | + include BoxesHelper | ||
29 | + | ||
28 | should 'generate links to tags' do | 30 | should 'generate links to tags' do |
29 | - assert_match /profile\/testinguser\/tags\/first-tag/, block.content | ||
30 | - assert_match /profile\/testinguser\/tags\/second-tag/, block.content | ||
31 | - assert_match /profile\/testinguser\/tags\/third-tag/, block.content | 31 | + content = render_block_content(block) |
32 | + assert_match /profile\/testinguser\/tags\/first-tag/, content | ||
33 | + assert_match /profile\/testinguser\/tags\/second-tag/, content | ||
34 | + assert_match /profile\/testinguser\/tags\/third-tag/, content | ||
32 | end | 35 | end |
33 | 36 | ||
34 | should 'generate links to tags on a environment page' do | 37 | should 'generate links to tags on a environment page' do |
@@ -38,24 +41,25 @@ class TagsBlockTest < ActiveSupport::TestCase | @@ -38,24 +41,25 @@ class TagsBlockTest < ActiveSupport::TestCase | ||
38 | box = create(Box, :owner => Environment.default) | 41 | box = create(Box, :owner => Environment.default) |
39 | @block = create(TagsBlock, :box => box) | 42 | @block = create(TagsBlock, :box => box) |
40 | 43 | ||
41 | - assert_match /3 items[^>]+\/tag\/first-tag/, block.content | ||
42 | - assert_match /3 items[^>]+\/tag\/second-tag/, block.content | ||
43 | - assert_match /one item[^>]+\/tag\/third-tag/, block.content | ||
44 | - assert_match /2 item[^>]+\/tag\/other-tag"/, block.content | 44 | + content = render_block_content(block) |
45 | + assert_match /3 items[^>]+\/tag\/first-tag/, content | ||
46 | + assert_match /3 items[^>]+\/tag\/second-tag/, content | ||
47 | + assert_match /one item[^>]+\/tag\/third-tag/, content | ||
48 | + assert_match /2 item[^>]+\/tag\/other-tag"/, content | ||
45 | end | 49 | end |
46 | 50 | ||
47 | should 'return (none) when no tags to display' do | 51 | should 'return (none) when no tags to display' do |
48 | block.owner.expects(:article_tags).returns([]) | 52 | block.owner.expects(:article_tags).returns([]) |
49 | - assert_equal '', block.content | 53 | + assert_equal '', render_block_content(block) |
50 | end | 54 | end |
51 | 55 | ||
52 | should 'generate links when profile has own hostname' do | 56 | should 'generate links when profile has own hostname' do |
53 | @user.domains << Domain.new(:name => 'testuser.net'); @user.save! | 57 | @user.domains << Domain.new(:name => 'testuser.net'); @user.save! |
54 | - assert_match /profile\/testinguser\/tags\/first-tag/, block.content | 58 | + assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) |
55 | end | 59 | end |
56 | 60 | ||
57 | should 'order tags alphabetically' do | 61 | should 'order tags alphabetically' do |
58 | - assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content | 62 | + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) |
59 | end | 63 | end |
60 | 64 | ||
61 | should 'return the max value in the range between zero and limit' do | 65 | should 'return the max value in the range between zero and limit' do |