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.
194 lines
6.6 KiB
194 lines
6.6 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
|
#
|
||
19 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'
|
||
19 years ago
|
|
||
11 years ago
|
describe Member, type: :model do
|
||
|
before do
|
||
12 years ago
|
Role.non_member.add_permission! :view_work_packages # non_member users may be watchers of work units
|
||
12 years ago
|
Role.non_member.add_permission! :view_wiki_pages # non_member users may be watchers of wikis
|
||
11 years ago
|
@project = FactoryGirl.create :project_with_types
|
||
10 years ago
|
@user = FactoryGirl.create :user, member_in_project: @project
|
||
12 years ago
|
@member = @project.members.first
|
||
|
@role = @member.roles.first
|
||
|
@role.add_permission! :view_wiki_pages
|
||
19 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should create' do
|
||
12 years ago
|
member = Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { project_id: @project.id,
|
||
|
user_id: FactoryGirl.create(:user).id,
|
||
|
role_ids: [@role.id] }
|
||
12 years ago
|
end
|
||
16 years ago
|
assert member.save
|
||
|
member.reload
|
||
14 years ago
|
|
||
12 years ago
|
assert_equal 1, member.roles.size
|
||
|
assert_equal @role, member.roles.first
|
||
15 years ago
|
end
|
||
19 years ago
|
|
||
11 years ago
|
it 'should update' do
|
||
12 years ago
|
assert_equal @project.name, @member.project.name
|
||
|
assert_equal @role.name, @member.roles.first.name
|
||
|
assert_equal @user.login, @member.user.login
|
||
14 years ago
|
|
||
12 years ago
|
@member.mail_notification = !@member.mail_notification
|
||
|
assert @member.save
|
||
19 years ago
|
end
|
||
16 years ago
|
|
||
11 years ago
|
it 'should update roles' do
|
||
12 years ago
|
assert_equal 1, @member.roles.size
|
||
|
@member.role_ids = [@role.id, FactoryGirl.create(:role).id]
|
||
|
assert @member.save
|
||
|
assert_equal 2, @member.reload.roles.size
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should validate' do
|
||
12 years ago
|
members = []
|
||
|
user_id = FactoryGirl.create(:user).id
|
||
|
2.times do
|
||
|
members << Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { project_id: @project.id,
|
||
|
user_id: user_id,
|
||
|
role_ids: [@role.id] }
|
||
12 years ago
|
end
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
|
assert members.first.save
|
||
|
# same user can't have more than one membership for a project
|
||
|
assert !members.last.save
|
||
14 years ago
|
|
||
12 years ago
|
member = Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { project_id: @project,
|
||
|
user_id: FactoryGirl.create(:user).id,
|
||
|
role_ids: [] }
|
||
12 years ago
|
end
|
||
16 years ago
|
# must have one role at least
|
||
15 years ago
|
assert !member.save
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy' do
|
||
16 years ago
|
assert_difference 'Member.count', -1 do
|
||
15 years ago
|
assert_difference 'MemberRole.count', -1 do
|
||
12 years ago
|
@member.destroy
|
||
16 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
assert_raise(ActiveRecord::RecordNotFound) { Member.find(@member.id) }
|
||
19 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'removing permissions' do
|
||
11 years ago
|
before do
|
||
11 years ago
|
@private_project = FactoryGirl.create :project_with_types,
|
||
10 years ago
|
is_public: true # has to be public first to successfully create things. Will be set to private later
|
||
12 years ago
|
@watcher_user = FactoryGirl.create(:user)
|
||
|
|
||
|
# watchers for public issue
|
||
11 years ago
|
public_issue = FactoryGirl.create :work_package
|
||
12 years ago
|
public_issue.project.is_public = true
|
||
|
public_issue.project.save!
|
||
10 years ago
|
Watcher.create!(watchable: public_issue, user: @watcher_user)
|
||
12 years ago
|
|
||
|
# watchers for private things
|
||
10 years ago
|
Watcher.create!(watchable: FactoryGirl.create(:work_package, project: @private_project), user: @watcher_user)
|
||
|
board = FactoryGirl.create :board, project: @private_project
|
||
|
@message = FactoryGirl.create :message, board: board
|
||
|
Watcher.create!(watchable: @message, user: @watcher_user)
|
||
|
Watcher.create!(watchable: FactoryGirl.create(:wiki, project: @private_project), user: @watcher_user)
|
||
12 years ago
|
@private_project.reload # to access @private_project.wiki
|
||
10 years ago
|
Watcher.create!(watchable: FactoryGirl.create(:wiki_page, wiki: @private_project.wiki), user: @watcher_user)
|
||
|
@private_role = FactoryGirl.create :role, permissions: [:view_wiki_pages, :view_work_packages]
|
||
12 years ago
|
|
||
|
@private_project.is_public = false
|
||
|
@private_project.save
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'of user' do
|
||
11 years ago
|
before do
|
||
12 years ago
|
(@member = Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { project_id: @private_project.id,
|
||
|
user_id: @watcher_user.id,
|
||
|
role_ids: [@private_role.id, FactoryGirl.create(:role).id] }
|
||
12 years ago
|
end).save!
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'by deleting membership' do
|
||
11 years ago
|
it 'should prune watchers' do
|
||
15 years ago
|
assert_difference 'Watcher.count', -4 do
|
||
|
@member.destroy
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'by updating roles' do
|
||
11 years ago
|
it 'should prune watchers' do
|
||
12 years ago
|
@private_role.remove_permission! :view_wiki_pages
|
||
15 years ago
|
assert_difference 'Watcher.count', -2 do
|
||
12 years ago
|
@member.role_ids = [@private_role.id]
|
||
|
@member.save
|
||
15 years ago
|
end
|
||
12 years ago
|
assert !@message.watched_by?(@watcher_user)
|
||
15 years ago
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'of group' do
|
||
11 years ago
|
before do
|
||
12 years ago
|
@group = FactoryGirl.create :group
|
||
12 years ago
|
@member = (Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { project_id: @private_project.id,
|
||
|
user_id: @group.id,
|
||
|
role_ids: [@private_role.id, FactoryGirl.create(:role).id] }
|
||
12 years ago
|
end)
|
||
|
|
||
12 years ago
|
@group.members << @member
|
||
|
@group.users << @watcher_user
|
||
|
assert @group.save
|
||
15 years ago
|
end
|
||
|
|
||
10 years ago
|
context 'by deleting membership' do
|
||
11 years ago
|
it 'should prune watchers' do
|
||
15 years ago
|
assert_difference 'Watcher.count', -4 do
|
||
|
@member.destroy
|
||
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
15 years ago
|
|
||
10 years ago
|
context 'by updating roles' do
|
||
11 years ago
|
it 'should prune watchers' do
|
||
12 years ago
|
@private_role.remove_permission! :view_wiki_pages
|
||
15 years ago
|
assert_difference 'Watcher.count', -2 do
|
||
12 years ago
|
@member.role_ids = [@private_role.id]
|
||
15 years ago
|
@member.save
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
19 years ago
|
end
|