summaryrefslogtreecommitdiffstats
path: root/test/functional/principal_memberships_controller_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-23 21:46:40 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-23 21:46:40 +0000
commitc2e73160daa7782d7a91f2b6a974a936c6f084da (patch)
tree62e174df69aba43cb5a84f2ddd278dc4562963f0 /test/functional/principal_memberships_controller_test.rb
parentca5946d82ebb96464a3d283be657bc24ce0c47f1 (diff)
downloadredmine-c2e73160daa7782d7a91f2b6a974a936c6f084da.tar.gz
redmine-c2e73160daa7782d7a91f2b6a974a936c6f084da.zip
Adds a single controller for users and groups memberships and support for adding multiple projects at once (#11702).
git-svn-id: http://svn.redmine.org/redmine/trunk@13498 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/principal_memberships_controller_test.rb')
-rw-r--r--test/functional/principal_memberships_controller_test.rb209
1 files changed, 209 insertions, 0 deletions
diff --git a/test/functional/principal_memberships_controller_test.rb b/test/functional/principal_memberships_controller_test.rb
new file mode 100644
index 000000000..fe89c1153
--- /dev/null
+++ b/test/functional/principal_memberships_controller_test.rb
@@ -0,0 +1,209 @@
+# Redmine - project management software
+# Copyright (C) 2006-2014 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class PrincipalMembershipsControllerTest < ActionController::TestCase
+ fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
+
+ def setup
+ @request.session[:user_id] = 1
+ end
+
+ def test_new_user_membership
+ get :new, :user_id => 7
+ assert_response :success
+ assert_select 'label', :text => 'eCookbook' do
+ assert_select 'input[name=?][value=1]:not([disabled])', 'membership[project_ids][]'
+ end
+ end
+
+ def test_new_user_membership_should_disable_user_projects
+ Member.create!(:user_id => 7, :project_id => 1, :role_ids => [1])
+
+ get :new, :user_id => 7
+ assert_response :success
+ assert_select 'label', :text => 'eCookbook' do
+ assert_select 'input[name=?][value=1][disabled=disabled]', 'membership[project_ids][]'
+ end
+ end
+
+ def test_xhr_new_user_membership
+ xhr :get, :new, :user_id => 7
+ assert_response :success
+ assert_equal 'text/javascript', response.content_type
+ end
+
+ def test_create_user_membership
+ assert_difference 'Member.count' do
+ post :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2]}
+ end
+ assert_redirected_to '/users/7/edit?tab=memberships'
+ member = Member.order('id DESC').first
+ assert_equal User.find(7), member.principal
+ assert_equal [2], member.role_ids
+ assert_equal 3, member.project_id
+ end
+
+ def test_create_user_membership_with_multiple_roles
+ assert_difference 'Member.count' do
+ post :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2, 3]}
+ end
+ member = Member.order('id DESC').first
+ assert_equal User.find(7), member.principal
+ assert_equal [2, 3], member.role_ids.sort
+ assert_equal 3, member.project_id
+ end
+
+ def test_create_user_membership_with_multiple_projects_and_roles
+ assert_difference 'Member.count', 2 do
+ post :create, :user_id => 7, :membership => {:project_ids => [1, 3], :role_ids => [2, 3]}
+ end
+ members = Member.order('id DESC').limit(2).sort_by(&:project_id)
+ assert_equal 1, members[0].project_id
+ assert_equal 3, members[1].project_id
+ members.each do |member|
+ assert_equal User.find(7), member.principal
+ assert_equal [2, 3], member.role_ids.sort
+ end
+ end
+
+ def test_xhr_create_user_membership
+ assert_difference 'Member.count' do
+ xhr :post, :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2]}, :format => 'js'
+ assert_response :success
+ assert_template 'create'
+ assert_equal 'text/javascript', response.content_type
+ end
+ member = Member.order('id DESC').first
+ assert_equal User.find(7), member.principal
+ assert_equal [2], member.role_ids
+ assert_equal 3, member.project_id
+ assert_include 'tab-content-memberships', response.body
+ end
+
+ def test_xhr_create_user_membership_with_failure
+ assert_no_difference 'Member.count' do
+ xhr :post, :create, :user_id => 7, :membership => {:project_ids => [3]}, :format => 'js'
+ assert_response :success
+ assert_template 'create'
+ assert_equal 'text/javascript', response.content_type
+ end
+ assert_include 'alert', response.body, "Alert message not sent"
+ assert_include 'Role can\\\'t be empty', response.body, "Error message not sent"
+ end
+
+ def test_update_user_membership
+ assert_no_difference 'Member.count' do
+ put :update, :user_id => 2, :id => 1, :membership => {:role_ids => [2]}
+ assert_redirected_to '/users/2/edit?tab=memberships'
+ end
+ assert_equal [2], Member.find(1).role_ids
+ end
+
+ def test_xhr_update_user_membership
+ assert_no_difference 'Member.count' do
+ xhr :put, :update, :user_id => 2, :id => 1, :membership => {:role_ids => [2]}, :format => 'js'
+ assert_response :success
+ assert_template 'update'
+ assert_equal 'text/javascript', response.content_type
+ end
+ assert_equal [2], Member.find(1).role_ids
+ assert_include 'tab-content-memberships', response.body
+ end
+
+ def test_destroy_user_membership
+ assert_difference 'Member.count', -1 do
+ delete :destroy, :user_id => 2, :id => 1
+ end
+ assert_redirected_to '/users/2/edit?tab=memberships'
+ assert_nil Member.find_by_id(1)
+ end
+
+ def test_xhr_destroy_user_membership_js_format
+ assert_difference 'Member.count', -1 do
+ xhr :delete, :destroy, :user_id => 2, :id => 1
+ assert_response :success
+ assert_template 'destroy'
+ assert_equal 'text/javascript', response.content_type
+ end
+ assert_nil Member.find_by_id(1)
+ assert_include 'tab-content-memberships', response.body
+ end
+
+ def test_xhr_new_group_membership
+ xhr :get, :new, :group_id => 10
+ assert_response :success
+ assert_equal 'text/javascript', response.content_type
+ end
+
+ def test_create_group_membership
+ assert_difference 'Group.find(10).members.count' do
+ post :create, :group_id => 10, :membership => {:project_ids => [2], :role_ids => ['1', '2']}
+ end
+ end
+
+ def test_xhr_create_group_membership
+ assert_difference 'Group.find(10).members.count' do
+ xhr :post, :create, :group_id => 10, :membership => {:project_ids => [2], :role_ids => ['1', '2']}
+ assert_response :success
+ assert_template 'create'
+ assert_equal 'text/javascript', response.content_type
+ end
+ assert_match /OnlineStore/, response.body
+ end
+
+ def test_xhr_create_group_membership_with_failure
+ assert_no_difference 'Group.find(10).members.count' do
+ xhr :post, :create, :group_id => 10, :membership => {:project_ids => [999], :role_ids => ['1', '2']}
+ assert_response :success
+ assert_template 'create'
+ assert_equal 'text/javascript', response.content_type
+ end
+ assert_match /alert/, response.body, "Alert message not sent"
+ end
+
+ def test_update_group_membership
+ assert_no_difference 'Group.find(10).members.count' do
+ put :update, :group_id => 10, :id => 6, :membership => {:role_ids => ['1', '3']}
+ end
+ end
+
+ def test_xhr_update_group_membership
+ assert_no_difference 'Group.find(10).members.count' do
+ xhr :post, :update, :group_id => 10, :id => 6, :membership => {:role_ids => ['1', '3']}
+ assert_response :success
+ assert_template 'update'
+ assert_equal 'text/javascript', response.content_type
+ end
+ end
+
+ def test_destroy_group_membership
+ assert_difference 'Group.find(10).members.count', -1 do
+ delete :destroy, :group_id => 10, :id => 6
+ end
+ end
+
+ def test_xhr_destroy_group_membership
+ assert_difference 'Group.find(10).members.count', -1 do
+ xhr :delete, :destroy, :group_id => 10, :id => 6
+ assert_response :success
+ assert_template 'destroy'
+ assert_equal 'text/javascript', response.content_type
+ end
+ end
+end