diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-09-12 08:36:46 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-09-12 08:36:46 +0000 |
commit | 7707457145442d6177ce57c956dbe09af65df1b4 (patch) | |
tree | 2278f27bf20e08bb2f92e42ab728b4427cce6f07 /test | |
parent | 847c7367b429e8df0e0fa1dbf3e415e37dd82bf1 (diff) | |
download | redmine-7707457145442d6177ce57c956dbe09af65df1b4.tar.gz redmine-7707457145442d6177ce57c956dbe09af65df1b4.zip |
User groups branch merged.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2869 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/groups_users.yml | 5 | ||||
-rw-r--r-- | test/fixtures/member_roles.yml | 20 | ||||
-rw-r--r-- | test/fixtures/members.yml | 12 | ||||
-rw-r--r-- | test/fixtures/users.yml | 8 | ||||
-rw-r--r-- | test/functional/groups_controller_test.rb | 107 | ||||
-rw-r--r-- | test/functional/members_controller_test.rb | 17 | ||||
-rw-r--r-- | test/integration/admin_test.rb | 7 | ||||
-rw-r--r-- | test/unit/group_test.rb | 77 | ||||
-rw-r--r-- | test/unit/project_test.rb | 12 |
9 files changed, 248 insertions, 17 deletions
diff --git a/test/fixtures/groups_users.yml b/test/fixtures/groups_users.yml new file mode 100644 index 000000000..3702d6efc --- /dev/null +++ b/test/fixtures/groups_users.yml @@ -0,0 +1,5 @@ +--- +groups_users_001: + group_id: 10 + user_id: 8 +
\ No newline at end of file diff --git a/test/fixtures/member_roles.yml b/test/fixtures/member_roles.yml index 6c91f15a4..e0fc6d064 100644 --- a/test/fixtures/member_roles.yml +++ b/test/fixtures/member_roles.yml @@ -19,5 +19,21 @@ member_roles_005: id: 5 role_id: 1 member_id: 5 - -
\ No newline at end of file +member_roles_006: + id: 6 + role_id: 1 + member_id: 6 +member_roles_007: + id: 7 + role_id: 2 + member_id: 6 +member_roles_008: + id: 8 + role_id: 1 + member_id: 7 + inherited_from: 6 +member_roles_009: + id: 9 + role_id: 2 + member_id: 7 + inherited_from: 7 diff --git a/test/fixtures/members.yml b/test/fixtures/members.yml index b1b19c3f5..3fd785b9a 100644 --- a/test/fixtures/members.yml +++ b/test/fixtures/members.yml @@ -30,4 +30,16 @@ members_005: project_id: 5
user_id: 2
mail_notification: true
+members_006:
+ id: 6
+ created_on: 2006-07-19 19:35:33 +02:00
+ project_id: 5
+ user_id: 10
+ mail_notification: false
+members_007:
+ id: 7
+ created_on: 2006-07-19 19:35:33 +02:00
+ project_id: 5
+ user_id: 8
+ mail_notification: false
\ No newline at end of file diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 8be822844..442ddc155 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -144,5 +144,13 @@ users_009: mail_notification: false
login: miscuser9
type: User
+groups_010:
+ id: 10
+ lastname: A Team
+ type: Group
+groups_011:
+ id: 11
+ lastname: B Team
+ type: Group
\ No newline at end of file diff --git a/test/functional/groups_controller_test.rb b/test/functional/groups_controller_test.rb new file mode 100644 index 000000000..ac61db425 --- /dev/null +++ b/test/functional/groups_controller_test.rb @@ -0,0 +1,107 @@ +# Redmine - project management software +# Copyright (C) 2006-2009 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.dirname(__FILE__) + '/../test_helper' +require 'groups_controller' + +# Re-raise errors caught by the controller. +class GroupsController; def rescue_action(e) raise e end; end + +class GroupsControllerTest < Test::Unit::TestCase + fixtures :projects, :users, :members, :member_roles + + def setup + @controller = GroupsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + @request.session[:user_id] = 1 + end + + def test_index + get :index + assert_response :success + assert_template 'index' + end + + def test_show + get :show, :id => 10 + assert_response :success + assert_template 'show' + end + + def test_new + get :new + assert_response :success + assert_template 'new' + end + + def test_create + assert_difference 'Group.count' do + post :create, :group => {:lastname => 'New group'} + end + assert_redirected_to 'groups' + end + + def test_edit + get :edit, :id => 10 + assert_response :success + assert_template 'edit' + end + + def test_update + post :update, :id => 10 + assert_redirected_to 'groups' + end + + def test_destroy + assert_difference 'Group.count', -1 do + post :destroy, :id => 10 + end + assert_redirected_to 'groups' + end + + def test_add_users + assert_difference 'Group.find(10).users.count', 2 do + post :add_users, :id => 10, :user_ids => ['2', '3'] + end + end + + def test_remove_user + assert_difference 'Group.find(10).users.count', -1 do + post :remove_user, :id => 10, :user_id => '8' + end + end + + def test_new_membership + assert_difference 'Group.find(10).members.count' do + post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} + end + end + + def test_edit_membership + assert_no_difference 'Group.find(10).members.count' do + post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} + end + end + + def test_destroy_membership + assert_difference 'Group.find(10).members.count', -1 do + post :destroy_membership, :id => 10, :membership_id => 6 + end + end +end diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb index 2680c3934..91f36abec 100644 --- a/test/functional/members_controller_test.rb +++ b/test/functional/members_controller_test.rb @@ -48,14 +48,6 @@ class MembersControllerTest < Test::Unit::TestCase assert User.find(7).member_of?(Project.find(1)) end - def test_create_by_user_login - assert_difference 'Member.count' do - post :new, :id => 1, :member => {:role_ids => [1], :user_login => 'someone'} - end - assert_redirected_to '/projects/ecookbook/settings/members' - assert User.find(7).member_of?(Project.find(1)) - end - def test_create_multiple assert_difference 'Member.count', 3 do post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} @@ -79,11 +71,12 @@ class MembersControllerTest < Test::Unit::TestCase assert !User.find(3).member_of?(Project.find(1)) end - def test_autocomplete_for_member_login - get :autocomplete_for_member_login, :id => 1, :user => 'mis' + def test_autocomplete_for_member + get :autocomplete_for_member, :id => 1, :q => 'mis' assert_response :success - assert_template 'autocomplete_for_member_login' + assert_template 'autocomplete_for_member' - assert_tag :ul, :child => {:tag => 'li', :content => /miscuser8/} + assert_tag :label, :content => /User Misc/, + :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } } end end diff --git a/test/integration/admin_test.rb b/test/integration/admin_test.rb index dd14e6661..66c6b21cd 100644 --- a/test/integration/admin_test.rb +++ b/test/integration/admin_test.rb @@ -18,7 +18,7 @@ require "#{File.dirname(__FILE__)}/../test_helper" class AdminTest < ActionController::IntegrationTest - fixtures :users + fixtures :all def test_add_user log_user("admin", "admin") @@ -26,16 +26,17 @@ class AdminTest < ActionController::IntegrationTest assert_response :success assert_template "users/add" post "/users/add", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09" - assert_redirected_to "/users" user = User.find_by_login("psmith") assert_kind_of User, user + assert_redirected_to "/users/#{ user.id }/edit" + logged_user = User.try_to_login("psmith", "psmith09") assert_kind_of User, logged_user assert_equal "Paul", logged_user.firstname post "users/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED } - assert_redirected_to "/users" + assert_redirected_to "/users/#{ user.id }/edit" locked_user = User.try_to_login("psmith", "psmith09") assert_equal nil, locked_user end diff --git a/test/unit/group_test.rb b/test/unit/group_test.rb new file mode 100644 index 000000000..79b9d4180 --- /dev/null +++ b/test/unit/group_test.rb @@ -0,0 +1,77 @@ +# Redmine - project management software +# Copyright (C) 2006-2009 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.dirname(__FILE__) + '/../test_helper' + +class GroupTest < Test::Unit::TestCase + fixtures :all + + def test_create + g = Group.new(:lastname => 'New group') + assert g.save + end + + def test_roles_given_to_new_user + group = Group.find(11) + user = User.find(9) + project = Project.first + + Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) + group.users << user + assert user.member_of?(project) + end + + def test_roles_given_to_existing_user + group = Group.find(11) + user = User.find(9) + project = Project.first + + group.users << user + m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) + assert user.member_of?(project) + end + + def test_roles_updated + group = Group.find(11) + user = User.find(9) + project = Project.first + group.users << user + m = Member.create!(:principal => group, :project => project, :role_ids => [1]) + assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort + + m.role_ids = [1, 2] + assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort + + m.role_ids = [2] + assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort + + m.role_ids = [1] + assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort + end + + def test_roles_removed_when_removing_group_membership + assert User.find(8).member_of?(Project.find(5)) + Member.find_by_project_id_and_user_id(5, 10).destroy + assert !User.find(8).member_of?(Project.find(5)) + end + + def test_roles_removed_when_removing_user_from_group + assert User.find(8).member_of?(Project.find(5)) + User.find(8).groups.clear + assert !User.find(8).member_of?(Project.find(5)) + end +end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 60bc4f1c1..13c63a054 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -63,6 +63,18 @@ class ProjectTest < Test::Unit::TestCase end
end
+ def test_members_should_be_active_users
+ Project.all.each do |project|
+ assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
+ end
+ end
+
+ def test_users_should_be_active_users
+ Project.all.each do |project|
+ assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
+ end
+ end
+
def test_archive
user = @ecookbook.members.first.user
@ecookbook.archive
|