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.
112 lines
4.4 KiB
112 lines
4.4 KiB
11 years ago
|
#-- copyright
|
||
11 years ago
|
# OpenProject Global Roles Plugin
|
||
11 years ago
|
#
|
||
11 years ago
|
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
|
||
11 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
11 years ago
|
# modify it under the terms of the GNU General Public License
|
||
|
# version 3.
|
||
11 years ago
|
#
|
||
11 years ago
|
# 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.
|
||
11 years ago
|
#++
|
||
|
|
||
14 years ago
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||
|
|
||
9 years ago
|
describe PrincipalRolesController, type: :controller do
|
||
7 years ago
|
let(:current_user) { FactoryBot.build_stubbed(:admin) }
|
||
7 years ago
|
|
||
14 years ago
|
before(:each) do
|
||
7 years ago
|
login_as(current_user)
|
||
14 years ago
|
|
||
14 years ago
|
@principal_role = mock_model PrincipalRole
|
||
14 years ago
|
|
||
11 years ago
|
allow(@principal_role).to receive(:id).and_return(23)
|
||
|
allow(PrincipalRole).to receive(:find).and_return @principal_role
|
||
14 years ago
|
end
|
||
|
|
||
10 years ago
|
describe '#post' do
|
||
14 years ago
|
before :each do
|
||
9 years ago
|
@params = { 'principal_role' => { 'principal_id' => '3', 'role_ids' => ['7'] } }
|
||
14 years ago
|
end
|
||
|
|
||
7 years ago
|
describe '#create' do
|
||
|
before :each do
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'SUCCESS' do
|
||
7 years ago
|
before :each do
|
||
|
@global_role = mock_model(GlobalRole)
|
||
|
allow(@global_role).to receive(:id).and_return(42)
|
||
|
##
|
||
|
# Note this test uses doubles which may break depending on the loaded plugins.
|
||
|
# Specifically extra stubs have been added for these tests to work with the
|
||
|
# openproject-impermanent_memberships plugin which would be otherwise unexpected.
|
||
|
# Those stubs are marked with the comment "only necessary with impermanent-memberships".
|
||
|
#
|
||
|
# If this problem occurs again with another plugin (or the same, really) this should be fixed for good
|
||
7 years ago
|
# by using FactoryBot to create actual model instances.
|
||
7 years ago
|
# I'm only patching this up right now because I don't want to spend any more time on it and
|
||
|
# the added methods are orthogonal to the test, also additional, unused stubs won't break things
|
||
|
# as opposed to missing ones.
|
||
|
#
|
||
7 years ago
|
# And yet: @TODO Don't use doubles but FactoryBot.
|
||
7 years ago
|
allow(@global_role).to receive(:id).and_return(42)
|
||
|
allow(@global_role).to receive(:permanent?).and_return(false) # only necessary with impermanent-memberships
|
||
|
allow(Role).to receive(:find).and_return([@global_role])
|
||
|
allow(PrincipalRole).to receive(:new).and_return(@principal_role)
|
||
|
@user = mock_model User
|
||
|
allow(@user).to receive(:valid?).and_return(true)
|
||
|
allow(@user).to receive(:logged?).and_return(true)
|
||
|
allow(@user).to receive(:global_roles).and_return([]) # only necessary with impermanent-memberships
|
||
|
allow(Principal).to receive(:find).and_return(@user)
|
||
|
allow(@principal_role).to receive(:role=)
|
||
|
allow(@principal_role).to receive(:role).and_return(@global_role)
|
||
|
allow(@principal_role).to receive(:principal_id=)
|
||
|
allow(@principal_role).to receive(:save)
|
||
|
allow(@principal_role).to receive(:role_id).and_return(@global_role.id)
|
||
|
allow(@principal_role).to receive(:valid?).and_return(true)
|
||
14 years ago
|
end
|
||
|
|
||
7 years ago
|
before :each do
|
||
|
post :create, params: @params
|
||
14 years ago
|
end
|
||
7 years ago
|
|
||
|
it { expect(response).to redirect_to tab_edit_user_path(@user, tab: 'global_roles') }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe '#delete' do
|
||
14 years ago
|
before :each do
|
||
11 years ago
|
allow(@principal_role).to receive(:principal_id).and_return(1)
|
||
11 years ago
|
@user = mock_model User
|
||
11 years ago
|
allow(@user).to receive(:logged?).and_return(true)
|
||
9 years ago
|
# only necessary with impermanent-memberships
|
||
|
allow(@user).to receive(:global_roles).and_return([])
|
||
11 years ago
|
allow(Principal).to receive(:find).and_return(@user)
|
||
|
allow(@principal_role).to receive(:destroy)
|
||
9 years ago
|
|
||
|
# only necessary with impermanent-memberships
|
||
|
allow(@principal_role).to receive(:role).and_return(Struct.new(:id, :permanent?).new(42, false))
|
||
|
@params = { 'id' => '1' }
|
||
14 years ago
|
end
|
||
|
|
||
10 years ago
|
describe '#destroy' do
|
||
9 years ago
|
describe 'SUCCESS' do
|
||
7 years ago
|
before :each do
|
||
|
delete :destroy, params: @params
|
||
14 years ago
|
end
|
||
7 years ago
|
|
||
|
it { expect(response).to redirect_to tab_edit_user_path(@user, tab: 'global_roles') }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
13 years ago
|
end
|