From 496d5a24c7fa5c8ec87ccf327079e5b3f64e43fd Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 16 Jan 2014 16:50:52 +0000 Subject: [PATCH] join_button: removing footer content from model --- app/models/members_block.rb | 11 +++-------- app/models/profile_list_block.rb | 2 +- app/views/blocks/members.rhtml | 5 +++++ app/views/blocks/profile_info_actions/_join_leave_community.rhtml | 4 +--- test/unit/members_block_test.rb | 15 ++++++--------- 5 files changed, 16 insertions(+), 21 deletions(-) create mode 100644 app/views/blocks/members.rhtml diff --git a/app/models/members_block.rb b/app/models/members_block.rb index c0dbcd5..d37c85b 100644 --- a/app/models/members_block.rb +++ b/app/models/members_block.rb @@ -15,15 +15,10 @@ class MembersBlock < ProfileListBlock def footer profile = self.owner - show_button_block = show_join_leave_button + s = show_join_leave_button lambda do - if show_button_block - @view_all = link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' - render "blocks/profile_info_actions/join_leave_community" - else - link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' - end + render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s} end end @@ -41,4 +36,4 @@ class MembersBlock < ProfileListBlock } end -end \ No newline at end of file +end diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index 36ed38f..9dd7c26 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -62,7 +62,7 @@ class ProfileListBlock < Block title.gsub('{#}', profile_count.to_s) end - # override in subclasses! See MembersBlock for exemple + # override in subclasses! See MembersBlock for example def extra_option {} end diff --git a/app/views/blocks/members.rhtml b/app/views/blocks/members.rhtml new file mode 100644 index 0000000..4bd47e1 --- /dev/null +++ b/app/views/blocks/members.rhtml @@ -0,0 +1,5 @@ +<%= link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' %> + +<% if show_join_leave_button %> + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> +<% end %> diff --git a/app/views/blocks/profile_info_actions/_join_leave_community.rhtml b/app/views/blocks/profile_info_actions/_join_leave_community.rhtml index b8b52e1..047749a 100644 --- a/app/views/blocks/profile_info_actions/_join_leave_community.rhtml +++ b/app/views/blocks/profile_info_actions/_join_leave_community.rhtml @@ -1,5 +1,3 @@ -<%= @view_all unless @view_all.nil? %> - <% if logged_in? %> <% if profile.members.include?(user) %> <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, @@ -26,4 +24,4 @@ <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, :class => 'button with-text icon-add', :title => _('Join this community') %> -<% end %> \ No newline at end of file +<% end %> diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb index 854720f..d6005db 100644 --- a/test/unit/members_block_test.rb +++ b/test/unit/members_block_test.rb @@ -14,16 +14,13 @@ class MembersBlockTest < ActiveSupport::TestCase assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title end - should 'link to "all members" page' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.save! - - expects(:_).with('View all').returns('View all') - expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'profile', :action => 'members').returns('link-to-members') + should 'display members file' do + community = fast_create(Community) + block = MembersBlock.create + block.expects(:owner).returns(community) - assert_equal 'link-to-members', instance_eval(&block.footer) + self.expects(:render).with(:file => 'blocks/members', :locals => { :profile => community, :show_join_leave_button => false}).returns('file-with-members-list') + assert_equal 'file-with-members-list', instance_eval(&block.footer) end should 'pick random members' do -- libgit2 0.21.2