From d53e71f1d625bb9cc9e6756dc7dd297d9259bff0 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Tue, 22 Mar 2016 11:23:11 -0300 Subject: [PATCH] Remove PeopleBlock#footer --- plugins/people_block/lib/friends_block.rb | 8 -------- plugins/people_block/lib/members_block.rb | 9 --------- plugins/people_block/lib/people_block.rb | 7 ------- plugins/people_block/lib/people_block_base.rb | 52 ---------------------------------------------------- plugins/people_block/test/unit/friends_block_test.rb | 23 ++++++++++------------- plugins/people_block/test/unit/members_block_test.rb | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- plugins/people_block/test/unit/people_block_test.rb | 21 ++++++++++----------- plugins/people_block/views/blocks/footers/friends.html.erb | 8 ++++---- plugins/people_block/views/blocks/footers/members.html.erb | 6 +++--- 9 files changed, 78 insertions(+), 158 deletions(-) diff --git a/plugins/people_block/lib/friends_block.rb b/plugins/people_block/lib/friends_block.rb index 594c90d..811c2d1 100644 --- a/plugins/people_block/lib/friends_block.rb +++ b/plugins/people_block/lib/friends_block.rb @@ -20,14 +20,6 @@ class FriendsBlock < PeopleBlockBase owner.suggested_profiles.of_person.enabled.limit(3).includes(:suggestion) end - def footer - profile = self.owner - suggestions = self.suggestions - proc do - render :file => 'blocks/footers/friends', :locals => { :profile => profile, :suggestions => suggestions } - end - end - def self.expire_on { :profile => [:profile] } end diff --git a/plugins/people_block/lib/members_block.rb b/plugins/people_block/lib/members_block.rb index 4514597..9cee06b 100644 --- a/plugins/people_block/lib/members_block.rb +++ b/plugins/people_block/lib/members_block.rb @@ -20,15 +20,6 @@ class MembersBlock < PeopleBlockBase role ? owner.members.with_role(role.id) : owner.members end - def footer - profile = self.owner - role_key = visible_role - s = show_join_leave_button - proc do - render :file => 'blocks/footers/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key} - end - end - def role visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil end diff --git a/plugins/people_block/lib/people_block.rb b/plugins/people_block/lib/people_block.rb index b70c774..cbfb61d 100644 --- a/plugins/people_block/lib/people_block.rb +++ b/plugins/people_block/lib/people_block.rb @@ -15,11 +15,4 @@ class PeopleBlock < PeopleBlockBase def profiles owner.people end - - def footer - proc do - render :file => 'blocks/footers/people' - end - end - end diff --git a/plugins/people_block/lib/people_block_base.rb b/plugins/people_block/lib/people_block_base.rb index 0531e43..9b88a63 100644 --- a/plugins/people_block/lib/people_block_base.rb +++ b/plugins/people_block/lib/people_block_base.rb @@ -42,58 +42,6 @@ class PeopleBlockBase < Block profiles.visible.count end -=begin - def content(args={}) - profiles = self.profile_list - title = self.view_title - - if !self.name.blank? && !self.address.blank? - name = self.name - expanded_address = expand_address(self.address) - end - - proc do - count = 0 - list = profiles.map {|item| - count += 1 - send(:profile_image_link, item, :minor ) - }.join("\n") - if list.empty? - list = content_tag 'div', c_('None'), :class => 'common-profile-list-block-none' - else - if !name.blank? && !expanded_address.blank? - list << content_tag( - 'div', - content_tag( - 'li', - content_tag( - 'div', - link_to( - content_tag('span', name, :class => 'banner-span' ), - expanded_address, - :title => name - ), - :class => 'banner-div' - ), - :class => 'vcard' - ), - :class => 'common-profile-list-block' - ) - end - list = content_tag 'ul', list - end - block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both')) - end - end -=end - def expand_address(address) - if address !~ /^[a-z]+:\/\// && address !~ /^\// - 'http://' + address - else - address - end - end - def extra_option { } end diff --git a/plugins/people_block/test/unit/friends_block_test.rb b/plugins/people_block/test/unit/friends_block_test.rb index f813af7..54b435a 100644 --- a/plugins/people_block/test/unit/friends_block_test.rb +++ b/plugins/people_block/test/unit/friends_block_test.rb @@ -60,19 +60,6 @@ class FriendsBlockTest < ActionView::TestCase assert_equal 20, block.limit end - should 'link to "all friends"' do - person1 = create_user('mytestperson').person - - block = FriendsBlock.new - block.stubs(:suggestions).returns([]) - block.expects(:owner).returns(person1).at_least_once - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select '[href=/profile/mytestperson/friends]' - end - end - should 'count number of owner friends' do owner = fast_create(Person) friend1 = fast_create(Person) @@ -156,4 +143,14 @@ class FriendsBlockViewTest < ActionView::TestCase assert_match(/#{friend1.name}/, content) assert_match(/#{friend2.name}/, content) end + + should 'link to "all friends"' do + person1 = create_user('mytestperson').person + + block = FriendsBlock.new + block.stubs(:suggestions).returns([]) + block.expects(:owner).returns(person1).at_least_once + + assert_tag_in_string render_block_footer(block), tag: 'a', attributes: {class: 'view-all', href: '/profile/mytestperson/friends' } + end end diff --git a/plugins/people_block/test/unit/members_block_test.rb b/plugins/people_block/test/unit/members_block_test.rb index 1dcae46..b15eb41 100644 --- a/plugins/people_block/test/unit/members_block_test.rb +++ b/plugins/people_block/test/unit/members_block_test.rb @@ -119,57 +119,6 @@ class MembersBlockTest < ActionView::TestCase assert_equal 1, block.profile_count end - should 'provide link to members page without a visible_role selected' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.save! - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select "[href=/profile/mytestuser/members#members-tab]" - end - end - - should 'provide link to members page when visible_role is profile_member' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.visible_role = 'profile_member' - block.save! - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select '[href=/profile/mytestuser/members#members-tab]' - end - end - - should 'provide link to members page when visible_role is profile_moderator' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.visible_role = 'profile_moderator' - block.save! - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select '[href=/profile/mytestuser/members#members-tab]' - end - end - - should 'provide link to admins page when visible_role is profile_admin' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.visible_role = 'profile_admin' - block.save! - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select '[href=/profile/mytestuser/members#admins-tab]' - end - end - should 'provide a role to be displayed (and default to nil)' do env = fast_create(Environment) env.boxes << Box.new @@ -306,4 +255,55 @@ class MembersBlockViewTest < ActionView::TestCase assert_match(/#{person1.name}/, content) assert_match(/#{person2.name}/, content) end + + should 'provide link to members page without a visible_role selected' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.save! + + render_block_footer(block) + assert_select 'a.view-all' do |elements| + assert_select "[href=/profile/mytestuser/members#members-tab]" + end + end + + should 'provide link to members page when visible_role is profile_member' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.visible_role = 'profile_member' + block.save! + + render_block_footer(block) + assert_select 'a.view-all' do |elements| + assert_select '[href=/profile/mytestuser/members#members-tab]' + end + end + + should 'provide link to members page when visible_role is profile_moderator' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.visible_role = 'profile_moderator' + block.save! + + render_block_footer(block) + assert_select 'a.view-all' do |elements| + assert_select '[href=/profile/mytestuser/members#members-tab]' + end + end + + should 'provide link to admins page when visible_role is profile_admin' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.visible_role = 'profile_admin' + block.save! + + render_block_footer(block) + assert_select 'a.view-all' do |elements| + assert_select '[href=/profile/mytestuser/members#admins-tab]' + end + end end diff --git a/plugins/people_block/test/unit/people_block_test.rb b/plugins/people_block/test/unit/people_block_test.rb index 1350c38..433214f 100644 --- a/plugins/people_block/test/unit/people_block_test.rb +++ b/plugins/people_block/test/unit/people_block_test.rb @@ -85,17 +85,6 @@ class PeopleBlockTest < ActionView::TestCase end - should 'link to "all people"' do - env = fast_create(Environment) - block = PeopleBlock.new - - instance_eval(&block.footer) - assert_select 'a.view-all' do |elements| - assert_select '[href=/search/people]' - end - end - - should 'count number of public and private people' do owner = fast_create(Environment) private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id) @@ -146,4 +135,14 @@ class PeopleBlockViewTest < ActionView::TestCase assert_match(/#{person1.name}/, content) assert_match(/#{person2.name}/, content) end + + should 'link to "all people"' do + env = fast_create(Environment) + block = PeopleBlock.new + + render_block_footer(block) + assert_select 'a.view-all' do |elements| + assert_select '[href=/search/people]' + end + end end diff --git a/plugins/people_block/views/blocks/footers/friends.html.erb b/plugins/people_block/views/blocks/footers/friends.html.erb index 1908442..b01a7b6 100644 --- a/plugins/people_block/views/blocks/footers/friends.html.erb +++ b/plugins/people_block/views/blocks/footers/friends.html.erb @@ -1,13 +1,13 @@ -<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> +<%= link_to s_('friends|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> -<% if !suggestions.empty? && user == profile %> +<% if !block.suggestions.empty? && user == block.owner %>

<%= _('Some suggestions for you') %>

- <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :friends_suggestions } %> + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => block.suggestions, :collection => :friends_suggestions } %>
- <%= link_to _('See all suggestions'), profile.people_suggestions_url %> + <%= link_to _('See all suggestions'), block.owner.people_suggestions_url %>
<% end %> diff --git a/plugins/people_block/views/blocks/footers/members.html.erb b/plugins/people_block/views/blocks/footers/members.html.erb index 89ed71b..9384a8d 100644 --- a/plugins/people_block/views/blocks/footers/members.html.erb +++ b/plugins/people_block/views/blocks/footers/members.html.erb @@ -1,6 +1,6 @@ -<% anchor = role_key == "profile_admin" ? "admins-tab" : "members-tab" %> -<%= link_to c_('View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> +<% anchor = block.visible_role == "profile_admin" ? "admins-tab" : "members-tab" %> +<%= link_to c_('View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> -<% if show_join_leave_button %> +<% if block.show_join_leave_button %> <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> <% end %> -- libgit2 0.21.2