Commit 7024df4e1acc430e2c4b2a3f76c7480b29141770
1 parent
2942e278
Exists in
web_steps_improvements
and in
8 other branches
Remove PeopleBlock#content
This method was producing view code from within the model which is a violation of MVC. Part of the code was extracted into the new helper and most of it became a view. This follow the standard for using BoxesHelper#render_block_content.
Showing
16 changed files
with
177 additions
and
83 deletions
Show diff stats
plugins/people_block/lib/friends_block.rb
| ... | ... | @@ -24,7 +24,7 @@ class FriendsBlock < PeopleBlockBase |
| 24 | 24 | profile = self.owner |
| 25 | 25 | suggestions = self.suggestions |
| 26 | 26 | proc do |
| 27 | - render :file => 'blocks/friends', :locals => { :profile => profile, :suggestions => suggestions } | |
| 27 | + render :file => 'blocks/footers/friends', :locals => { :profile => profile, :suggestions => suggestions } | |
| 28 | 28 | end |
| 29 | 29 | end |
| 30 | 30 | ... | ... |
plugins/people_block/lib/members_block.rb
| ... | ... | @@ -25,7 +25,7 @@ class MembersBlock < PeopleBlockBase |
| 25 | 25 | role_key = visible_role |
| 26 | 26 | s = show_join_leave_button |
| 27 | 27 | proc do |
| 28 | - render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key} | |
| 28 | + render :file => 'blocks/footers/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key} | |
| 29 | 29 | end |
| 30 | 30 | end |
| 31 | 31 | ... | ... |
plugins/people_block/lib/people_block.rb
plugins/people_block/lib/people_block_base.rb
| ... | ... | @@ -42,6 +42,7 @@ class PeopleBlockBase < Block |
| 42 | 42 | profiles.visible.count |
| 43 | 43 | end |
| 44 | 44 | |
| 45 | +=begin | |
| 45 | 46 | def content(args={}) |
| 46 | 47 | profiles = self.profile_list |
| 47 | 48 | title = self.view_title |
| ... | ... | @@ -84,7 +85,7 @@ class PeopleBlockBase < Block |
| 84 | 85 | block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both')) |
| 85 | 86 | end |
| 86 | 87 | end |
| 87 | - | |
| 88 | +=end | |
| 88 | 89 | def expand_address(address) |
| 89 | 90 | if address !~ /^[a-z]+:\/\// && address !~ /^\// |
| 90 | 91 | 'http://' + address | ... | ... |
| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | +module PeopleBlockHelper | |
| 2 | + def profiles_images_list(profiles) | |
| 3 | + profiles.map { |profile| profile_image_link(profile, :minor) }.join("\n") | |
| 4 | + end | |
| 5 | + | |
| 6 | + def set_address_protocol(address) | |
| 7 | + !URI.parse(address).scheme ? 'http://'+address : address | |
| 8 | + end | |
| 9 | +end | ... | ... |
plugins/people_block/test/unit/friends_block_test.rb
| ... | ... | @@ -60,26 +60,6 @@ class FriendsBlockTest < ActionView::TestCase |
| 60 | 60 | assert_equal 20, block.limit |
| 61 | 61 | end |
| 62 | 62 | |
| 63 | - should 'list friends from person' do | |
| 64 | - owner = fast_create(Person) | |
| 65 | - friend1 = fast_create(Person) | |
| 66 | - friend2 = fast_create(Person) | |
| 67 | - owner.add_friend(friend1) | |
| 68 | - owner.add_friend(friend2) | |
| 69 | - | |
| 70 | - block = FriendsBlock.new | |
| 71 | - | |
| 72 | - block.expects(:owner).returns(owner).at_least_once | |
| 73 | - expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) | |
| 74 | - expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) | |
| 75 | - expects(:block_title).with(anything).returns('') | |
| 76 | - | |
| 77 | - content = instance_eval(&block.content) | |
| 78 | - | |
| 79 | - assert_match(/#{friend1.name}/, content) | |
| 80 | - assert_match(/#{friend2.name}/, content) | |
| 81 | - end | |
| 82 | - | |
| 83 | 63 | should 'link to "all friends"' do |
| 84 | 64 | person1 = create_user('mytestperson').person |
| 85 | 65 | |
| ... | ... | @@ -151,3 +131,29 @@ class FriendsBlockTest < ActionView::TestCase |
| 151 | 131 | include NoosferoTestHelper |
| 152 | 132 | |
| 153 | 133 | end |
| 134 | + | |
| 135 | +require 'boxes_helper' | |
| 136 | + | |
| 137 | +class FriendsBlockViewTest < ActionView::TestCase | |
| 138 | + include BoxesHelper | |
| 139 | + | |
| 140 | + should 'list friends from person' do | |
| 141 | + owner = fast_create(Person) | |
| 142 | + friend1 = fast_create(Person) | |
| 143 | + friend2 = fast_create(Person) | |
| 144 | + owner.add_friend(friend1) | |
| 145 | + owner.add_friend(friend2) | |
| 146 | + | |
| 147 | + block = FriendsBlock.new | |
| 148 | + | |
| 149 | + block.expects(:owner).returns(owner).at_least_once | |
| 150 | + ActionView::Base.any_instance.expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) | |
| 151 | + ActionView::Base.any_instance.expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) | |
| 152 | + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('') | |
| 153 | + | |
| 154 | + content = render_block_content(block) | |
| 155 | + | |
| 156 | + assert_match(/#{friend1.name}/, content) | |
| 157 | + assert_match(/#{friend2.name}/, content) | |
| 158 | + end | |
| 159 | +end | ... | ... |
plugins/people_block/test/unit/members_block_test.rb
| ... | ... | @@ -90,26 +90,6 @@ class MembersBlockTest < ActionView::TestCase |
| 90 | 90 | end |
| 91 | 91 | |
| 92 | 92 | |
| 93 | - should 'list members from community' do | |
| 94 | - owner = fast_create(Community) | |
| 95 | - person1 = fast_create(Person) | |
| 96 | - person2 = fast_create(Person) | |
| 97 | - owner.add_member(person1) | |
| 98 | - owner.add_member(person2) | |
| 99 | - | |
| 100 | - block = MembersBlock.new | |
| 101 | - | |
| 102 | - block.expects(:owner).returns(owner).at_least_once | |
| 103 | - expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
| 104 | - expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
| 105 | - expects(:block_title).with(anything).returns('') | |
| 106 | - | |
| 107 | - content = instance_eval(&block.content) | |
| 108 | - | |
| 109 | - assert_match(/#{person1.name}/, content) | |
| 110 | - assert_match(/#{person2.name}/, content) | |
| 111 | - end | |
| 112 | - | |
| 113 | 93 | should 'count number of public and private members' do |
| 114 | 94 | owner = fast_create(Community) |
| 115 | 95 | private_p = fast_create(Person, {:public_profile => false}) |
| ... | ... | @@ -299,3 +279,31 @@ class MembersBlockTest < ActionView::TestCase |
| 299 | 279 | include NoosferoTestHelper |
| 300 | 280 | |
| 301 | 281 | end |
| 282 | + | |
| 283 | +require 'boxes_helper' | |
| 284 | + | |
| 285 | +class MembersBlockViewTest < ActionView::TestCase | |
| 286 | + include BoxesHelper | |
| 287 | + | |
| 288 | + should 'list members from community' do | |
| 289 | + owner = fast_create(Community) | |
| 290 | + person1 = fast_create(Person) | |
| 291 | + person2 = fast_create(Person) | |
| 292 | + owner.add_member(person1) | |
| 293 | + owner.add_member(person2) | |
| 294 | + profile = Profile.new | |
| 295 | + profile.identifier = 42 | |
| 296 | + | |
| 297 | + block = MembersBlock.new | |
| 298 | + | |
| 299 | + block.expects(:owner).returns(owner).at_least_once | |
| 300 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
| 301 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
| 302 | + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('') | |
| 303 | + | |
| 304 | + content = render_block_content(block) | |
| 305 | + | |
| 306 | + assert_match(/#{person1.name}/, content) | |
| 307 | + assert_match(/#{person2.name}/, content) | |
| 308 | + end | |
| 309 | +end | ... | ... |
plugins/people_block/test/unit/people_block_helper_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +require 'test_helper' | |
| 2 | + | |
| 3 | +class PeopleBlockHelperTest < ActionView::TestCase | |
| 4 | + include PeopleBlockHelper | |
| 5 | + | |
| 6 | + should 'list profiles as images links' do | |
| 7 | + owner = fast_create(Environment) | |
| 8 | + profiles = [ | |
| 9 | + fast_create(Person, :environment_id => owner.id), | |
| 10 | + fast_create(Person, :environment_id => owner.id), | |
| 11 | + fast_create(Person, :environment_id => owner.id) | |
| 12 | + ] | |
| 13 | + link_html = "<a href=#><img src='' /></a>" | |
| 14 | + | |
| 15 | + profiles.each do |profile| | |
| 16 | + expects(:profile_image_link).with(profile, :minor).returns(link_html) | |
| 17 | + end | |
| 18 | + | |
| 19 | + list = profiles_images_list(profiles) | |
| 20 | + | |
| 21 | + assert_equal list, ([link_html]*profiles.count).join("\n") | |
| 22 | + end | |
| 23 | + | |
| 24 | + should 'prepend the protocol to urls missing it' do | |
| 25 | + address = 'noosfero.org' | |
| 26 | + | |
| 27 | + assert_equal set_address_protocol(address), 'http://'+address | |
| 28 | + end | |
| 29 | + | |
| 30 | + should 'leave urls already with protocol unchanged' do | |
| 31 | + address = 'http://noosfero.org' | |
| 32 | + ssl_address = 'https://noosfero.org' | |
| 33 | + | |
| 34 | + assert_equal set_address_protocol(address), address | |
| 35 | + assert_equal set_address_protocol(ssl_address), ssl_address | |
| 36 | + end | |
| 37 | +end | |
| 0 | 38 | \ No newline at end of file | ... | ... |
plugins/people_block/test/unit/people_block_test.rb
| ... | ... | @@ -85,25 +85,6 @@ class PeopleBlockTest < ActionView::TestCase |
| 85 | 85 | end |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - should 'list people from environment' do | |
| 89 | - owner = fast_create(Environment) | |
| 90 | - person1 = fast_create(Person, :environment_id => owner.id) | |
| 91 | - person2 = fast_create(Person, :environment_id => owner.id) | |
| 92 | - | |
| 93 | - block = PeopleBlock.new | |
| 94 | - | |
| 95 | - block.expects(:owner).returns(owner).at_least_once | |
| 96 | - expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
| 97 | - expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
| 98 | - expects(:block_title).with(anything).returns('') | |
| 99 | - | |
| 100 | - content = instance_exec(&block.content) | |
| 101 | - | |
| 102 | - assert_match(/#{person1.name}/, content) | |
| 103 | - assert_match(/#{person2.name}/, content) | |
| 104 | - end | |
| 105 | - | |
| 106 | - | |
| 107 | 88 | should 'link to "all people"' do |
| 108 | 89 | env = fast_create(Environment) |
| 109 | 90 | block = PeopleBlock.new |
| ... | ... | @@ -142,3 +123,27 @@ class PeopleBlockTest < ActionView::TestCase |
| 142 | 123 | include NoosferoTestHelper |
| 143 | 124 | |
| 144 | 125 | end |
| 126 | + | |
| 127 | +require 'boxes_helper' | |
| 128 | + | |
| 129 | +class PeopleBlockViewTest < ActionView::TestCase | |
| 130 | + include BoxesHelper | |
| 131 | + | |
| 132 | + should 'list people from environment' do | |
| 133 | + owner = fast_create(Environment) | |
| 134 | + person1 = fast_create(Person, :environment_id => owner.id) | |
| 135 | + person2 = fast_create(Person, :environment_id => owner.id) | |
| 136 | + | |
| 137 | + block = PeopleBlock.new | |
| 138 | + | |
| 139 | + block.expects(:owner).returns(owner).at_least_once | |
| 140 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
| 141 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
| 142 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
| 143 | + | |
| 144 | + content = render_block_content(block) | |
| 145 | + | |
| 146 | + assert_match(/#{person1.name}/, content) | |
| 147 | + assert_match(/#{person2.name}/, content) | |
| 148 | + end | |
| 149 | +end | ... | ... |
plugins/people_block/views/blocks/footers/friends.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> | |
| 2 | + | |
| 3 | +<% if !suggestions.empty? && user == profile %> | |
| 4 | + <div class='suggestions-block common-profile-list-block'> | |
| 5 | + <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
| 6 | + <div class='profiles-suggestions'> | |
| 7 | + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :friends_suggestions } %> | |
| 8 | + </div> | |
| 9 | + <div class='more-suggestions'> | |
| 10 | + <%= link_to _('See all suggestions'), profile.people_suggestions_url %> | |
| 11 | + </div> | |
| 12 | + </div> | |
| 13 | +<% end %> | ... | ... |
plugins/people_block/views/blocks/footers/members.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | +<% anchor = role_key == "profile_admin" ? "admins-tab" : "members-tab" %> | |
| 2 | +<%= link_to c_('View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> | |
| 3 | + | |
| 4 | +<% if show_join_leave_button %> | |
| 5 | + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> | |
| 6 | +<% end %> | ... | ... |
plugins/people_block/views/blocks/footers/people.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %> | ... | ... |
plugins/people_block/views/blocks/friends.html.erb
| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | -<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> | |
| 2 | - | |
| 3 | -<% if !suggestions.empty? && user == profile %> | |
| 4 | - <div class='suggestions-block common-profile-list-block'> | |
| 5 | - <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
| 6 | - <div class='profiles-suggestions'> | |
| 7 | - <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :friends_suggestions } %> | |
| 8 | - </div> | |
| 9 | - <div class='more-suggestions'> | |
| 10 | - <%= link_to _('See all suggestions'), profile.people_suggestions_url %> | |
| 11 | - </div> | |
| 12 | - </div> | |
| 13 | -<% end %> |
plugins/people_block/views/blocks/members.html.erb
| ... | ... | @@ -1,6 +0,0 @@ |
| 1 | -<% anchor = role_key == "profile_admin" ? "admins-tab" : "members-tab" %> | |
| 2 | -<%= link_to c_('View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> | |
| 3 | - | |
| 4 | -<% if show_join_leave_button %> | |
| 5 | - <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> | |
| 6 | -<% end %> |
plugins/people_block/views/blocks/people.html.erb
| ... | ... | @@ -1 +0,0 @@ |
| 1 | -<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %> |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +<% extend PeopleBlockHelper %> | |
| 2 | + | |
| 3 | +<%= block_title(block.view_title) %> | |
| 4 | + | |
| 5 | +<div> | |
| 6 | + <% unless block.profiles.count == 0 %> | |
| 7 | + <ul> | |
| 8 | + <%= profiles_images_list(block.profiles) %> | |
| 9 | + | |
| 10 | + <% unless block.name.blank? || block.address.blank? %> | |
| 11 | + <div class="common-profile-list-block"> | |
| 12 | + <li class="vcard"> | |
| 13 | + <div class="banner-div"> | |
| 14 | + <%= link_to( | |
| 15 | + content_tag('span', block.name, :class => 'banner-span' ), | |
| 16 | + set_address_protocol(block.address), | |
| 17 | + title: block.name | |
| 18 | + ) %> | |
| 19 | + </div> | |
| 20 | + </li> | |
| 21 | + </div> | |
| 22 | + <% end %> | |
| 23 | + </ul> | |
| 24 | + <% else %> | |
| 25 | + <div class="common-profile-list-block-none"><%= c_('None') %></div> | |
| 26 | + <% end %> | |
| 27 | + <br style="clear:both" /> | |
| 28 | +</div> | ... | ... |