kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.2 KiB
101 lines
3.2 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
15 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
15 years ago
|
|
||
11 years ago
|
describe Group, type: :model do
|
||
|
before do
|
||
12 years ago
|
@group = FactoryGirl.create :group
|
||
|
@member = FactoryGirl.build :member
|
||
11 years ago
|
@work_package = FactoryGirl.create :work_package
|
||
12 years ago
|
@roles = FactoryGirl.create_list :role, 2
|
||
10 years ago
|
@member.force_attributes = { principal: @group, role_ids: @roles.map(&:id) }
|
||
12 years ago
|
@member.save!
|
||
|
@project = @member.project
|
||
|
@user = FactoryGirl.create :user
|
||
|
@group.users << @user
|
||
|
@group.save!
|
||
|
end
|
||
15 years ago
|
|
||
11 years ago
|
it 'should create' do
|
||
10 years ago
|
g = Group.new(lastname: 'New group')
|
||
15 years ago
|
assert g.save
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should roles given to new user' do
|
||
12 years ago
|
user = FactoryGirl.build :user
|
||
12 years ago
|
@group.users << user
|
||
13 years ago
|
|
||
12 years ago
|
assert user.member_of? @project
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should roles given to existing user' do
|
||
12 years ago
|
assert @user.member_of? @project
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should roles updated' do
|
||
12 years ago
|
group = FactoryGirl.create :group
|
||
|
member = FactoryGirl.build :member
|
||
|
roles = FactoryGirl.create_list :role, 2
|
||
10 years ago
|
role_ids = roles.map(&:id)
|
||
10 years ago
|
member.force_attributes = { principal: group, role_ids: role_ids }
|
||
12 years ago
|
member.save!
|
||
|
user = FactoryGirl.create :user
|
||
15 years ago
|
group.users << user
|
||
12 years ago
|
group.save!
|
||
13 years ago
|
|
||
12 years ago
|
member.role_ids = [role_ids.first]
|
||
10 years ago
|
assert_equal [role_ids.first], user.reload.roles_for_project(member.project).map(&:id).sort
|
||
14 years ago
|
|
||
12 years ago
|
member.role_ids = role_ids
|
||
10 years ago
|
assert_equal role_ids, user.reload.roles_for_project(member.project).map(&:id).sort
|
||
14 years ago
|
|
||
12 years ago
|
member.role_ids = [role_ids.last]
|
||
10 years ago
|
assert_equal [role_ids.last], user.reload.roles_for_project(member.project).map(&:id).sort
|
||
14 years ago
|
|
||
12 years ago
|
member.role_ids = [role_ids.first]
|
||
10 years ago
|
assert_equal [role_ids.first], user.reload.roles_for_project(member.project).map(&:id).sort
|
||
15 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should roles removed when removing group membership' do
|
||
12 years ago
|
assert @user.member_of?(@project)
|
||
|
@member.destroy
|
||
|
@user.reload
|
||
|
@project.reload
|
||
|
assert !@user.member_of?(@project)
|
||
15 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should roles removed when removing user from group' do
|
||
12 years ago
|
assert @user.member_of?(@project)
|
||
10 years ago
|
@user.groups.destroy_all
|
||
12 years ago
|
@user.reload
|
||
|
@project.reload
|
||
|
assert !@user.member_of?(@project)
|
||
15 years ago
|
end
|
||
|
end
|