diff --git a/app/views/blocks/profile_list.html.erb b/app/views/blocks/profile_list.html.erb
index 6243b9a..8edcdaa 100644
--- a/app/views/blocks/profile_list.html.erb
+++ b/app/views/blocks/profile_list.html.erb
@@ -1,8 +1,9 @@
<%= block_title(block.view_title) %>
<%
- count=0
- list = block.profile_list.map {|item| count+=1 block.send(:profile_image_link, item, :minor)}.join("\n ")
+ list = block.profile_list.map do |item|
+ profile_image_link(item, :minor)
+ end.join("\n ")
%>
diff --git a/app/views/blocks/tags.html.erb b/app/views/blocks/tags.html.erb
index 46eebfc..db30dfd 100644
--- a/app/views/blocks/tags.html.erb
+++ b/app/views/blocks/tags.html.erb
@@ -14,11 +14,11 @@
<% if is_env %>
<%= tag_cloud(tags, :tag,
- {:host=>block.owner.default_hostname, :controller=>'search', :action => 'tag'},
+ {:host => block.owner.default_hostname, :controller=>'search', :action => 'tag'},
:max_size => 16, :min_size => 9) %>
<% else %>
<%= tag_cloud(tags, :id,
- owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'),
+ block.owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'),
:max_size => 16, :min_size => 9) %>
<% end %>
diff --git a/test/unit/categories_block_test.rb b/test/unit/categories_block_test.rb
index 8117500..79d02d1 100644
--- a/test/unit/categories_block_test.rb
+++ b/test/unit/categories_block_test.rb
@@ -17,11 +17,13 @@ class CategoriesBlockTest < ActiveSupport::TestCase
assert_not_nil category_block.help
end
+ include BoxesHelper
+
should 'display category block' do
block = CategoriesBlock.new
self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block})
- instance_eval(& block.content)
+ render_block_content(block)
end
should 'be editable' do
diff --git a/test/unit/disabled_enterprise_message_block_test.rb b/test/unit/disabled_enterprise_message_block_test.rb
index 56c14d2..16ddb4a 100644
--- a/test/unit/disabled_enterprise_message_block_test.rb
+++ b/test/unit/disabled_enterprise_message_block_test.rb
@@ -6,16 +6,25 @@ class DisabledEnterpriseMessageBlockTest < ActiveSupport::TestCase
assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description
end
+ include BoxesHelper
+
should 'display message for disabled enterprise' do
- e = Environment.default
- e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises')
- block = DisabledEnterpriseMessageBlock.new
- p = Profile.new
- block.expects(:owner).returns(p)
- p.expects(:environment).returns(e)
-
- expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => 'This message is for disabled enterprises'})
- instance_eval(&block.content)
+ environment = Environment.default
+ environment.message_for_disabled_enterprise = 'This message is for disabled enterprises'
+ environment.save
+
+ enterprise = fast_create(Enterprise, :identifier => 'disabled-enterprise', :environment_id => environment.id)
+ enterprise.boxes << Box.new
+ enterprise.boxes.first.blocks << DisabledEnterpriseMessageBlock.new
+ block = enterprise.boxes.first.blocks.first
+
+ ApplicationHelper.class_eval do
+ def profile
+ return Enterprise['disabled-enterprise']
+ end
+ end
+
+ assert_match 'This message is for disabled enterprises', render_block_content(block)
end
should 'not be editable' do
diff --git a/test/unit/highlights_block_test.rb b/test/unit/highlights_block_test.rb
index 437224e..747dc34 100644
--- a/test/unit/highlights_block_test.rb
+++ b/test/unit/highlights_block_test.rb
@@ -80,11 +80,13 @@ class HighlightsBlockTest < ActiveSupport::TestCase
assert_equal 'always', block.display
end
+ include BoxesHelper
+
should 'display highlights block' do
block = HighlightsBlock.new
self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block})
- instance_eval(& block.content)
+ render_block_content(block)
end
should 'not list non existent image' do
@@ -167,7 +169,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase
block.images = [i1]
block.save!
- assert_tag_in_string instance_eval(& block.content), :tag => 'img', :attributes => { :src => "/social/img_address" }
+ assert_tag_in_string render_block_content(block), :tag => 'img', :attributes => { :src => "/social/img_address" }
end
[Environment, Profile].each do |klass|
diff --git a/test/unit/my_network_block_test.rb b/test/unit/my_network_block_test.rb
index 8513a3d..9dd5eae 100644
--- a/test/unit/my_network_block_test.rb
+++ b/test/unit/my_network_block_test.rb
@@ -19,14 +19,6 @@ class MyNetworkBlockTest < ActiveSupport::TestCase
assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title
end
- should 'display my-profile' do
- self.expects(:render).with(:file => 'blocks/my_network', :locals => {
- :title => 'My network',
- :owner => owner
- })
- instance_eval(&block.content)
- end
-
should 'be able to update display setting' do
user = create_user('testinguser').person
box = fast_create(Box, :owner_id => user.id)
@@ -37,3 +29,22 @@ class MyNetworkBlockTest < ActiveSupport::TestCase
end
end
+
+class MyNetworkBlockViewTest < ActionView::TestCase
+ include BoxesHelper
+
+ def setup
+ @block = MyNetworkBlock.new
+ @owner = Person.new(:identifier => 'testuser')
+ @block.stubs(:owner).returns(@owner)
+ owner.stubs(:environment).returns(Environment.default)
+ end
+ attr_reader :owner, :block
+
+ should 'display my-profile' do
+ ActionView::Base.any_instance.stubs(:block_title).with(anything).returns(true)
+ ActionView::Base.any_instance.stubs(:user).with(anything).returns(owner)
+ ActionView::Base.any_instance.stubs(:render_profile_actions)
+ assert_match "#{Environment.default.top_url}/profile/testuser", render_block_content(block)
+ end
+end
diff --git a/test/unit/profile_info_block_test.rb b/test/unit/profile_info_block_test.rb
index 9e52da0..71c0600 100644
--- a/test/unit/profile_info_block_test.rb
+++ b/test/unit/profile_info_block_test.rb
@@ -16,9 +16,11 @@ class ProfileInfoBlockTest < ActiveSupport::TestCase
assert_not_equal Block.description, ProfileInfoBlock.description
end
+ include BoxesHelper
+
should 'display profile information' do
- self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block})
- instance_eval(& block.content)
+ self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block })
+ render_block_content(block)
end
end
diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb
index a5af4dd..76a6718 100644
--- a/test/unit/profile_list_block_test.rb
+++ b/test/unit/profile_list_block_test.rb
@@ -20,6 +20,8 @@ class ProfileListBlockTest < ActiveSupport::TestCase
assert_equal 20, block.limit
end
+ include BoxesHelper
+
should 'list people' do
env = fast_create(Environment)
@@ -30,15 +32,16 @@ class ProfileListBlockTest < ActiveSupport::TestCase
block = ProfileListBlock.new
block.stubs(:owner).returns(env)
- self.expects(:profile_image_link).with(person1, :minor).once
- self.expects(:profile_image_link).with(person2, :minor).once
- self.expects(:profile_image_link).with(person3, :minor).once
-
- self.stubs(:tag).returns('
')
- self.expects(:content_tag).returns('
').at_least_once
- self.expects(:block_title).returns('block title').at_least_once
+ ApplicationHelper.class_eval do
+ def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
+ "<#{profile.name}>"
+ end
+ end
- assert_kind_of String, instance_eval(&block.content)
+ content = render_block_content(block)
+ assert_match '
', content
+ assert_match '', content
+ assert_match '', content
end
should 'list private profiles' do
diff --git a/test/unit/profile_search_block_test.rb b/test/unit/profile_search_block_test.rb
index f2ceccd..a43e3d9 100644
--- a/test/unit/profile_search_block_test.rb
+++ b/test/unit/profile_search_block_test.rb
@@ -10,14 +10,16 @@ class ProfileSearchBlockTest < ActiveSupport::TestCase
assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title
end
+ include BoxesHelper
+
should 'render profile search' do
person = fast_create(Person)
block = ProfileSearchBlock.new
block.stubs(:owner).returns(person)
- self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :title => block.title})
- instance_eval(& block.content)
+ self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :block => block })
+ render_block_content(block)
end
should 'provide view_title' do
diff --git a/test/unit/raw_html_block_test.rb b/test/unit/raw_html_block_test.rb
index d21d78f..600317d 100644
--- a/test/unit/raw_html_block_test.rb
+++ b/test/unit/raw_html_block_test.rb
@@ -17,9 +17,11 @@ class RawHTMLBlockTest < ActiveSupport::TestCase
assert_equal html, block.html
end
+ include BoxesHelper
+
should 'return html as content' do
block = RawHTMLBlock.new(:html => "HTML")
- assert_match(/HTML$/, block.content)
+ assert_match /HTML$/, render_block_content(block)
end
should 'not be editable for users without permission' do
diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb
index fe8d874..4cb1041 100644
--- a/test/unit/tags_block_test.rb
+++ b/test/unit/tags_block_test.rb
@@ -25,10 +25,13 @@ class TagsBlockTest < ActiveSupport::TestCase
assert_not_equal Block.new.default_title, TagsBlock.new.default_title
end
+ include BoxesHelper
+
should 'generate links to tags' do
- 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
+ content = render_block_content(block)
+ assert_match /profile\/testinguser\/tags\/first-tag/, content
+ assert_match /profile\/testinguser\/tags\/second-tag/, content
+ assert_match /profile\/testinguser\/tags\/third-tag/, content
end
should 'generate links to tags on a environment page' do
@@ -38,24 +41,25 @@ class TagsBlockTest < ActiveSupport::TestCase
box = create(Box, :owner => Environment.default)
@block = create(TagsBlock, :box => box)
- assert_match /3 items[^>]+\/tag\/first-tag/, block.content
- assert_match /3 items[^>]+\/tag\/second-tag/, block.content
- assert_match /one item[^>]+\/tag\/third-tag/, block.content
- assert_match /2 item[^>]+\/tag\/other-tag"/, block.content
+ content = render_block_content(block)
+ assert_match /3 items[^>]+\/tag\/first-tag/, content
+ assert_match /3 items[^>]+\/tag\/second-tag/, content
+ assert_match /one item[^>]+\/tag\/third-tag/, content
+ 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 '', block.content
+ 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!
- assert_match /profile\/testinguser\/tags\/first-tag/, block.content
+ 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 =~ block.content
+ 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
--
libgit2 0.21.2