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.
562 lines
18 KiB
562 lines
18 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 User, type: :model do
|
||
12 years ago
|
include MiniTest::Assertions # refute
|
||
|
|
||
12 years ago
|
fixtures :all
|
||
15 years ago
|
|
||
11 years ago
|
before do
|
||
15 years ago
|
@admin = User.find(1)
|
||
|
@jsmith = User.find(2)
|
||
|
@dlopper = User.find(3)
|
||
|
end
|
||
15 years ago
|
|
||
11 years ago
|
specify 'object_daddy creation' do
|
||
9 years ago
|
FactoryGirl.create(:user, firstname: 'Testing connection')
|
||
|
FactoryGirl.create(:user, firstname: 'Testing connection')
|
||
10 years ago
|
assert_equal 2, User.where(firstname: 'Testing connection').count
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should truth' do
|
||
15 years ago
|
assert_kind_of User, @jsmith
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should mail should be stripped' do
|
||
15 years ago
|
u = User.new
|
||
10 years ago
|
u.mail = ' foo@bar.com '
|
||
|
assert_equal 'foo@bar.com', u.mail
|
||
15 years ago
|
end
|
||
15 years ago
|
|
||
11 years ago
|
it 'should create' do
|
||
10 years ago
|
user = User.new(firstname: 'new', lastname: 'user', mail: 'newuser@somenet.foo')
|
||
14 years ago
|
|
||
10 years ago
|
user.login = 'jsmith'
|
||
10 years ago
|
user.password = 'adminADMIN!'
|
||
|
user.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
# login uniqueness
|
||
|
assert !user.save
|
||
|
assert_equal 1, user.errors.count
|
||
14 years ago
|
|
||
10 years ago
|
user.login = 'newuser'
|
||
10 years ago
|
user.password = 'adminADMIN!'
|
||
|
user.password_confirmation = 'NOTadminADMIN!'
|
||
15 years ago
|
# password confirmation
|
||
|
assert !user.save
|
||
|
assert_equal 1, user.errors.count
|
||
|
|
||
10 years ago
|
user.password = 'adminADMIN!'
|
||
|
user.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
assert user.save
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'User#before_create' do
|
||
11 years ago
|
it 'should set the mail_notification to the default Setting' do
|
||
9 years ago
|
@user1 = FactoryGirl.create(:user, mail_notification: nil)
|
||
14 years ago
|
assert_equal 'only_my_events', @user1.mail_notification
|
||
|
|
||
10 years ago
|
with_settings default_notification_option: 'all' do
|
||
9 years ago
|
@user2 = FactoryGirl.create(:user)
|
||
14 years ago
|
assert_equal 'all', @user2.mail_notification
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'User.login' do
|
||
11 years ago
|
it 'should be case-insensitive.' do
|
||
10 years ago
|
u = User.new(firstname: 'new', lastname: 'user', mail: 'newuser@somenet.foo')
|
||
15 years ago
|
u.login = 'newuser'
|
||
10 years ago
|
u.password = 'adminADMIN!'
|
||
|
u.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
assert u.save
|
||
14 years ago
|
|
||
10 years ago
|
u = User.new(firstname: 'Similar', lastname: 'User', mail: 'similaruser@somenet.foo')
|
||
15 years ago
|
u.login = 'NewUser'
|
||
10 years ago
|
u.password = 'adminADMIN!'
|
||
|
u.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
assert !u.save
|
||
10 years ago
|
assert_includes u.errors[:login], I18n.translate('activerecord.errors.messages.taken')
|
||
15 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should mail uniqueness should not be case sensitive' do
|
||
10 years ago
|
u = User.new(firstname: 'new', lastname: 'user', mail: 'newuser@somenet.foo')
|
||
15 years ago
|
u.login = 'newuser1'
|
||
10 years ago
|
u.password = 'adminADMIN!'
|
||
|
u.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
assert u.save
|
||
14 years ago
|
|
||
10 years ago
|
u = User.new(firstname: 'new', lastname: 'user', mail: 'newUser@Somenet.foo')
|
||
15 years ago
|
u.login = 'newuser2'
|
||
10 years ago
|
u.password = 'adminADMIN!'
|
||
|
u.password_confirmation = 'adminADMIN!'
|
||
15 years ago
|
assert !u.save
|
||
10 years ago
|
assert_includes u.errors[:mail], I18n.translate('activerecord.errors.messages.taken')
|
||
15 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should update' do
|
||
10 years ago
|
assert_equal 'admin', @admin.login
|
||
|
@admin.login = 'john'
|
||
|
assert @admin.save, @admin.errors.full_messages.join('; ')
|
||
15 years ago
|
@admin.reload
|
||
10 years ago
|
assert_equal 'john', @admin.login
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy' do
|
||
15 years ago
|
User.find(2).destroy
|
||
10 years ago
|
assert_nil User.find_by(id: 2)
|
||
|
assert Member.where(user_id: 2).empty?
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should validate login presence' do
|
||
10 years ago
|
@admin.login = ''
|
||
15 years ago
|
assert !@admin.save
|
||
|
assert_equal 1, @admin.errors.count
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should validate mail notification inclusion' do
|
||
14 years ago
|
u = User.new
|
||
|
u.mail_notification = 'foo'
|
||
|
u.save
|
||
12 years ago
|
refute_empty u.errors[:mail_notification]
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'User#try_to_login' do
|
||
11 years ago
|
it 'should fall-back to case-insensitive if user login is not found as-typed.' do
|
||
10 years ago
|
user = User.try_to_login('AdMin', 'adminADMIN!')
|
||
15 years ago
|
assert_kind_of User, user
|
||
10 years ago
|
assert_equal 'admin', user.login
|
||
15 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should select the exact matching user first' do
|
||
9 years ago
|
case_sensitive_user = FactoryGirl.create(:user, login: 'changed', password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
|
||
15 years ago
|
# bypass validations to make it appear like existing data
|
||
|
case_sensitive_user.update_attribute(:login, 'ADMIN')
|
||
|
|
||
10 years ago
|
user = User.try_to_login('ADMIN', 'adminADMIN!')
|
||
15 years ago
|
assert_kind_of User, user
|
||
10 years ago
|
assert_equal 'ADMIN', user.login
|
||
15 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should password' do
|
||
10 years ago
|
user = User.try_to_login('admin', 'adminADMIN!')
|
||
15 years ago
|
assert_kind_of User, user
|
||
10 years ago
|
assert_equal 'admin', user.login
|
||
|
user.password = 'newpassPASS!'
|
||
15 years ago
|
assert user.save
|
||
14 years ago
|
|
||
10 years ago
|
user = User.try_to_login('admin', 'newpassPASS!')
|
||
15 years ago
|
assert_kind_of User, user
|
||
10 years ago
|
assert_equal 'admin', user.login
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should name format' do
|
||
15 years ago
|
assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
|
||
|
Setting.user_format = :firstname_lastname
|
||
|
assert_equal 'John Smith', @jsmith.reload.name
|
||
|
Setting.user_format = :username
|
||
|
assert_equal 'jsmith', @jsmith.reload.name
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should lock' do
|
||
10 years ago
|
user = User.try_to_login('jsmith', 'jsmith')
|
||
15 years ago
|
assert_equal @jsmith, user
|
||
14 years ago
|
|
||
12 years ago
|
@jsmith.status = User::STATUSES[:locked]
|
||
15 years ago
|
assert @jsmith.save
|
||
14 years ago
|
|
||
10 years ago
|
user = User.try_to_login('jsmith', 'jsmith')
|
||
14 years ago
|
assert_equal nil, user
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '.try_to_login' do
|
||
|
context 'with good credentials' do
|
||
11 years ago
|
it 'should return the user' do
|
||
10 years ago
|
user = User.try_to_login('admin', 'adminADMIN!')
|
||
14 years ago
|
assert_kind_of User, user
|
||
10 years ago
|
assert_equal 'admin', user.login
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'with wrong credentials' do
|
||
11 years ago
|
it 'should return nil' do
|
||
10 years ago
|
assert_nil User.try_to_login('admin', 'foo')
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
15 years ago
|
if ldap_configured?
|
||
10 years ago
|
context '#try_to_login using LDAP' do
|
||
|
context 'with failed connection to the LDAP server' do
|
||
11 years ago
|
it 'should return nil' do
|
||
12 years ago
|
@auth_source = LdapAuthSource.find(1)
|
||
10 years ago
|
allow_any_instance_of(AuthSource).to receive(:initialize_ldap_con).and_raise(Net::LDAP::LdapError, 'Cannot connect')
|
||
14 years ago
|
|
||
15 years ago
|
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with an unsuccessful authentication' do
|
||
11 years ago
|
it 'should return nil' do
|
||
15 years ago
|
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'on the fly registration' do
|
||
11 years ago
|
before do
|
||
12 years ago
|
@auth_source = LdapAuthSource.find(1)
|
||
15 years ago
|
end
|
||
|
|
||
10 years ago
|
context 'with a successful authentication' do
|
||
11 years ago
|
it "should create a new user account if it doesn't exist" do
|
||
15 years ago
|
assert_difference('User.count') do
|
||
15 years ago
|
user = User.try_to_login('edavis', '123456')
|
||
|
assert !user.admin?
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should retrieve existing user' do
|
||
15 years ago
|
user = User.try_to_login('edavis', '123456')
|
||
|
user.admin = true
|
||
|
user.save!
|
||
14 years ago
|
|
||
15 years ago
|
assert_no_difference('User.count') do
|
||
|
user = User.try_to_login('edavis', '123456')
|
||
|
assert user.admin?
|
||
15 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
else
|
||
10 years ago
|
puts 'Skipping LDAP tests.'
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should create anonymous' do
|
||
15 years ago
|
AnonymousUser.delete_all
|
||
|
anon = User.anonymous
|
||
|
assert !anon.new_record?
|
||
|
assert_kind_of AnonymousUser, anon
|
||
|
end
|
||
15 years ago
|
|
||
10 years ago
|
it { is_expected.to have_one :rss_token }
|
||
15 years ago
|
|
||
11 years ago
|
it 'should rss key' do
|
||
15 years ago
|
assert_nil @jsmith.rss_token
|
||
|
key = @jsmith.rss_key
|
||
|
assert_equal 40, key.length
|
||
14 years ago
|
|
||
15 years ago
|
@jsmith.reload
|
||
|
assert_equal key, @jsmith.rss_key
|
||
|
end
|
||
15 years ago
|
|
||
10 years ago
|
it { is_expected.to have_one :api_token }
|
||
14 years ago
|
|
||
10 years ago
|
context 'User#api_key' do
|
||
11 years ago
|
it "should generate a new one if the user doesn't have one" do
|
||
9 years ago
|
user = FactoryGirl.create(:user, api_token: nil)
|
||
15 years ago
|
assert_nil user.api_token
|
||
|
|
||
|
key = user.api_key
|
||
|
assert_equal 40, key.length
|
||
|
user.reload
|
||
|
assert_equal key, user.api_key
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should return the existing api token value' do
|
||
9 years ago
|
user = FactoryGirl.create(:user)
|
||
|
token = FactoryGirl.create(:token, action: 'api')
|
||
15 years ago
|
user.api_token = token
|
||
|
assert user.save
|
||
14 years ago
|
|
||
15 years ago
|
assert_equal token.value, user.api_key
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'User#find_by_api_key' do
|
||
11 years ago
|
it 'should return nil if no matching key is found' do
|
||
15 years ago
|
assert_nil User.find_by_api_key('zzzzzzzzz')
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should return nil if the key is found for an inactive user' do
|
||
9 years ago
|
user = FactoryGirl.create(:user, status: User::STATUSES[:locked])
|
||
|
token = FactoryGirl.create(:token, action: 'api')
|
||
15 years ago
|
user.api_token = token
|
||
|
user.save
|
||
|
|
||
|
assert_nil User.find_by_api_key(token.value)
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should return the user if the key is found for an active user' do
|
||
9 years ago
|
user = FactoryGirl.create(:user, status: User::STATUSES[:active])
|
||
|
token = FactoryGirl.create(:token, action: 'api')
|
||
15 years ago
|
user.api_token = token
|
||
|
user.save
|
||
14 years ago
|
|
||
15 years ago
|
assert_equal user, User.find_by_api_key(token.value)
|
||
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should roles for project' do
|
||
15 years ago
|
# user with a role
|
||
|
roles = @jsmith.roles_for_project(Project.find(1))
|
||
|
assert_kind_of Role, roles.first
|
||
10 years ago
|
assert_equal 'Manager', roles.first.name
|
||
14 years ago
|
|
||
15 years ago
|
# user with no role
|
||
10 years ago
|
assert_nil @dlopper.roles_for_project(Project.find(2)).detect(&:member?)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should projects by role for user with role' do
|
||
14 years ago
|
user = User.find(2)
|
||
|
assert_kind_of Hash, user.projects_by_role
|
||
|
assert_equal 2, user.projects_by_role.size
|
||
10 years ago
|
assert_equal [1, 5], user.projects_by_role[Role.find(1)].map(&:id).sort
|
||
|
assert_equal [2], user.projects_by_role[Role.find(2)].map(&:id).sort
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should projects by role for user with no role' do
|
||
9 years ago
|
user = FactoryGirl.create(:user)
|
||
14 years ago
|
assert_equal({}, user.projects_by_role)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should projects by role for anonymous' do
|
||
14 years ago
|
assert_equal({}, User.anonymous.projects_by_role)
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should valid notification options' do
|
||
14 years ago
|
# without memberships
|
||
|
assert_equal 5, User.find(7).valid_notification_options.size
|
||
|
# with memberships
|
||
|
assert_equal 6, User.find(2).valid_notification_options.size
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should valid notification options class method' do
|
||
14 years ago
|
assert_equal 5, User.valid_notification_options.size
|
||
|
assert_equal 5, User.valid_notification_options(User.find(7)).size
|
||
|
assert_equal 6, User.valid_notification_options(User.find(2)).size
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should mail notification all' do
|
||
14 years ago
|
@jsmith.mail_notification = 'all'
|
||
15 years ago
|
@jsmith.notified_project_ids = []
|
||
|
@jsmith.save
|
||
|
@jsmith.reload
|
||
9 years ago
|
assert @jsmith.projects.first.recipients.include?(@jsmith)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should mail notification selected' do
|
||
14 years ago
|
@jsmith.mail_notification = 'selected'
|
||
15 years ago
|
@jsmith.notified_project_ids = [1]
|
||
|
@jsmith.save
|
||
|
@jsmith.reload
|
||
9 years ago
|
assert Project.find(1).recipients.include?(@jsmith)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should mail notification only my events' do
|
||
14 years ago
|
@jsmith.mail_notification = 'only_my_events'
|
||
15 years ago
|
@jsmith.notified_project_ids = []
|
||
|
@jsmith.save
|
||
|
@jsmith.reload
|
||
9 years ago
|
assert !@jsmith.projects.first.recipients.include?(@jsmith)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should comments sorting preference' do
|
||
15 years ago
|
assert !@jsmith.wants_comments_in_reverse_order?
|
||
|
@jsmith.pref.comments_sorting = 'asc'
|
||
|
assert !@jsmith.wants_comments_in_reverse_order?
|
||
|
@jsmith.pref.comments_sorting = 'desc'
|
||
|
assert @jsmith.wants_comments_in_reverse_order?
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should find by mail should be case insensitive' do
|
||
10 years ago
|
u = User.find_by_mail('JSmith@somenet.foo')
|
||
9 years ago
|
refute_nil u
|
||
15 years ago
|
assert_equal 'jsmith@somenet.foo', u.mail
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '#allowed_to?' do
|
||
|
context 'with a unique project' do
|
||
11 years ago
|
it 'should return false if project is archived' do
|
||
14 years ago
|
project = Project.find(1)
|
||
10 years ago
|
allow_any_instance_of(Project).to receive(:status).and_return(Project::STATUS_ARCHIVED)
|
||
12 years ago
|
assert ! @admin.allowed_to?(:view_work_packages, Project.find(1))
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return false if related module is disabled' do
|
||
14 years ago
|
project = Project.find(1)
|
||
10 years ago
|
project.enabled_module_names = ['work_package_tracking']
|
||
11 years ago
|
assert @admin.allowed_to?(:add_work_packages, project)
|
||
14 years ago
|
assert ! @admin.allowed_to?(:view_wiki_pages, project)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should authorize nearly everything for admin users' do
|
||
14 years ago
|
project = Project.find(1)
|
||
10 years ago
|
project.enabled_module_names = ['work_package_tracking', 'news', 'wiki', 'repository']
|
||
14 years ago
|
assert ! @admin.member_of?(project)
|
||
11 years ago
|
%w(edit_work_packages delete_work_packages manage_news manage_repository manage_wiki).each do |p|
|
||
14 years ago
|
assert @admin.allowed_to?(p.to_sym, project)
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should authorize normal users depending on their roles' do
|
||
14 years ago
|
project = Project.find(1)
|
||
10 years ago
|
project.enabled_module_names = ['boards']
|
||
|
assert @jsmith.allowed_to?(:delete_messages, project) # Manager
|
||
|
assert ! @dlopper.allowed_to?(:delete_messages, project) # Developper
|
||
14 years ago
|
end
|
||
13 years ago
|
|
||
11 years ago
|
it 'should only managers are allowed to export tickets' do
|
||
13 years ago
|
project = Project.find(1)
|
||
10 years ago
|
project.enabled_module_names = ['work_package_tracking']
|
||
|
assert @jsmith.allowed_to?(:export_work_packages, project) # Manager
|
||
|
assert ! @dlopper.allowed_to?(:export_work_packages, project) # Developper
|
||
13 years ago
|
end
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'with multiple projects' do
|
||
11 years ago
|
it 'should return false if array is empty' do
|
||
14 years ago
|
assert ! @admin.allowed_to?(:view_project, [])
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return true only if user has permission on all these projects' do
|
||
13 years ago
|
Project.all.each do |project|
|
||
10 years ago
|
project.enabled_module_names = ['work_package_tracking']
|
||
13 years ago
|
project.save!
|
||
|
end
|
||
|
|
||
14 years ago
|
assert @admin.allowed_to?(:view_project, Project.all)
|
||
10 years ago
|
assert ! @dlopper.allowed_to?(:view_project, Project.all) # cannot see Project(2)
|
||
|
assert @jsmith.allowed_to?(:edit_work_packages, @jsmith.projects) # Manager or Developer everywhere
|
||
|
assert ! @jsmith.allowed_to?(:delete_work_package_watchers, @jsmith.projects) # Dev cannot delete_work_package_watchers
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should behave correctly with arrays of 1 project' do
|
||
10 years ago
|
assert !User.anonymous.allowed_to?(:delete_work_packages, [Project.first])
|
||
14 years ago
|
end
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'with options[:global]' do
|
||
11 years ago
|
it 'should authorize if user has at least one role that has this permission' do
|
||
10 years ago
|
@dlopper2 = User.find(5) # only Developper on a project, not Manager anywhere
|
||
14 years ago
|
@anonymous = User.find(6)
|
||
10 years ago
|
assert @jsmith.allowed_to?(:delete_work_package_watchers, nil, global: true)
|
||
|
assert ! @dlopper2.allowed_to?(:delete_work_package_watchers, nil, global: true)
|
||
|
assert @dlopper2.allowed_to?(:add_work_packages, nil, global: true)
|
||
|
assert ! @anonymous.allowed_to?(:add_work_packages, nil, global: true)
|
||
|
assert @anonymous.allowed_to?(:view_work_packages, nil, global: true)
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'User#notify_about?' do
|
||
|
context 'Issues' do
|
||
11 years ago
|
before do
|
||
14 years ago
|
@project = Project.find(1)
|
||
9 years ago
|
@author = FactoryGirl.create(:user)
|
||
|
@assignee = FactoryGirl.create(:user)
|
||
10 years ago
|
@issue = FactoryGirl.create(:work_package, project: @project, assigned_to: @assignee, author: @author)
|
||
14 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should be true for a user with :all' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'all')
|
||
14 years ago
|
assert @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be false for a user with :none' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'none')
|
||
14 years ago
|
assert ! @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it "should be false for a user with :only_my_events and isn't an author, creator, or assignee" do
|
||
9 years ago
|
@user = FactoryGirl.create(:user, mail_notification: 'only_my_events')
|
||
12 years ago
|
(Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { user: @user, project: @project, role_ids: [1] }
|
||
12 years ago
|
end).save!
|
||
14 years ago
|
assert ! @user.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :only_my_events and is the author' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'only_my_events')
|
||
14 years ago
|
assert @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :only_my_events and is the assignee' do
|
||
14 years ago
|
@assignee.update_attribute(:mail_notification, 'only_my_events')
|
||
14 years ago
|
assert @assignee.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :only_assigned and is the assignee' do
|
||
14 years ago
|
@assignee.update_attribute(:mail_notification, 'only_assigned')
|
||
14 years ago
|
assert @assignee.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be false for a user with :only_assigned and is not the assignee' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'only_assigned')
|
||
14 years ago
|
assert ! @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :only_owner and is the author' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'only_owner')
|
||
14 years ago
|
assert @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be false for a user with :only_owner and is not the author' do
|
||
14 years ago
|
@assignee.update_attribute(:mail_notification, 'only_owner')
|
||
14 years ago
|
assert ! @assignee.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :selected and is the author' do
|
||
14 years ago
|
@author.update_attribute(:mail_notification, 'selected')
|
||
|
assert @author.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be true for a user with :selected and is the assignee' do
|
||
14 years ago
|
@assignee.update_attribute(:mail_notification, 'selected')
|
||
|
assert @assignee.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be false for a user with :selected and is not the author or assignee' do
|
||
9 years ago
|
@user = FactoryGirl.create(:user, mail_notification: 'selected')
|
||
12 years ago
|
(Member.new.tap do |m|
|
||
10 years ago
|
m.force_attributes = { user: @user, project: @project, role_ids: [1] }
|
||
12 years ago
|
end).save!
|
||
14 years ago
|
assert ! @user.notify_about?(@issue)
|
||
|
end
|
||
14 years ago
|
end
|
||
|
|
||
10 years ago
|
context 'other events' do
|
||
11 years ago
|
it 'should be added and tested'
|
||
14 years ago
|
end
|
||
|
end
|
||
15 years ago
|
end
|