[Git][noosfero/noosfero][master] 3 commits: Fix task list in profile editor controller

Leandro Nunes gitlab at mg.gitlab.com
Thu Aug 4 17:07:16 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
7faaddca by Victor Costa at 2016-08-04T15:44:26-03:00
Fix task list in profile editor controller

- - - - -
0595bfe6 by Victor Costa at 2016-08-04T16:05:11-03:00
Limit task list in profile editor

- - - - -
02903b02 by Leandro Nunes at 2016-08-04T20:06:53+00:00
Merge branch 'fix_task_list' into 'master'

Limit task list in profile editor



See merge request !998
- - - - -


3 changed files:

- app/controllers/my_profile/profile_editor_controller.rb
- app/views/profile_editor/_pending_tasks.html.erb
- test/functional/profile_editor_controller_test.rb


Changes:

=====================================
app/controllers/my_profile/profile_editor_controller.rb
=====================================
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -12,7 +12,7 @@ class ProfileEditorController < MyProfileController
   include CategoriesHelper
 
   def index
-    @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
+    @pending_tasks = Task.to(profile).pending.without_spam
     @show_appearance_option = user.is_admin?(environment) || environment.enabled?('enable_appearance')
     @show_header_footer_option = user.is_admin?(environment) || (!profile.enterprise? && !environment.enabled?('disable_header_and_footer'))
   end


=====================================
app/views/profile_editor/_pending_tasks.html.erb
=====================================
--- a/app/views/profile_editor/_pending_tasks.html.erb
+++ b/app/views/profile_editor/_pending_tasks.html.erb
@@ -2,9 +2,9 @@
 
 <% unless @pending_tasks.empty? %>
   <div class='pending-tasks'>
-    <h2><%= _('You have pending requests') %></h2>
+    <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2>
     <ul>
-      <%= safe_join(@pending_tasks.map {|task| content_tag('li', task_information(task).html_safe)}) %>
+      <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task).html_safe)}) %>
     </ul>
     <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %>
   </div>


=====================================
test/functional/profile_editor_controller_test.rb
=====================================
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -391,8 +391,6 @@ class ProfileEditorControllerTest < ActionController::TestCase
     user2 = create_user('usertwo').person
     AddFriend.create!(:person => user1, :friend => user2)
     @controller.stubs(:user).returns(user2)
-    user2.stubs(:has_permission?).with('edit_profile', anything).returns(true)
-    user2.expects(:has_permission?).with(:manage_friends, anything).returns(true)
     login_as('usertwo')
     get :index, :profile => 'usertwo'
     assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }
@@ -400,16 +398,34 @@ class ProfileEditorControllerTest < ActionController::TestCase
 
   should 'not show task if user has no permission' do
     user1 = profile
+    community = fast_create(Community)
     user2 = create_user('usertwo').person
-    task = AddFriend.create!(:person => user1, :friend => user2)
+    task = AddMember.create!(person: user1, organization: community)
     @controller.stubs(:user).returns(user2)
-    user2.stubs(:has_permission?).with('edit_profile', anything).returns(true)
-    user2.expects(:has_permission?).with(:manage_friends, anything).returns(false)
+    give_permission(user2, 'invite_members', community)
     login_as('usertwo')
     get :index, :profile => 'usertwo'
     assert_no_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }
   end
 
+  should 'limit task list' do
+    user2 = create_user('usertwo').person
+    6.times { AddFriend.create!(:person => create_user.person, :friend => user2) }
+    login_as('usertwo')
+    get :index, :profile => 'usertwo'
+    assert_select '.pending-tasks > ul > li', 5
+  end
+
+  should 'display task count in task list' do
+    user2 = create_user('usertwo').person
+    6.times { AddFriend.create!(:person => create_user.person, :friend => user2) }
+    login_as('usertwo')
+    get :index, :profile => 'usertwo'
+    assert_select '.pending-tasks h2' do |elements|
+      assert_match /6/, elements.first.content
+    end
+  end
+
   should 'show favorite enterprises button for person' do
     get :index, :profile => profile.identifier
     assert_tag :tag => 'a', :content => 'Favorite Enterprises'



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/f16ec7f40f8a718f3860db79ebf6a17ce30f462e...02903b02b2290e7a7af8fb0fd253fc4dbe1465ad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160804/6b631469/attachment-0001.html>


More information about the Noosfero-dev mailing list