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.
335 lines
10 KiB
335 lines
10 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
|
#++
|
||
|
|
||
9 years ago
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||
14 years ago
|
|
||
9 years ago
|
describe RolesController, type: :controller do
|
||
|
before do
|
||
11 years ago
|
allow(@controller).to receive(:check_if_login_required)
|
||
|
expect(@controller).to receive(:require_admin)
|
||
14 years ago
|
disable_flash_sweep
|
||
|
end
|
||
|
|
||
9 years ago
|
after do
|
||
12 years ago
|
User.current = nil
|
||
|
end
|
||
|
|
||
9 years ago
|
shared_examples_for 'index' do
|
||
|
it { expect(response).to be_success }
|
||
|
it { expect(assigns(:roles)).to eql(@roles) }
|
||
|
it { expect(response).to render_template 'roles/index' }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
shared_examples_for 'global assigns' do
|
||
|
it { expect(assigns(:global_permissions)).to eql @global_role.setable_permissions }
|
||
|
it { expect(assigns(:global_roles)).to eql @global_roles }
|
||
|
it { expect(assigns(:global_role)).to eql @global_role }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
shared_examples_for 'permission assigns' do
|
||
|
it { expect(assigns(:member_permissions)).to eql @member_role.setable_permissions }
|
||
|
it { expect(assigns(:global_permissions)).to eql GlobalRole.setable_permissions }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
shared_examples_for 'successful create' do
|
||
|
it { expect(response).to be_redirect }
|
||
|
it { expect(response).to redirect_to '/admin/roles' }
|
||
|
it { expect(flash[:notice]).to eql I18n.t(:notice_successful_create) }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
shared_examples_for 'failed create' do
|
||
|
it { expect(response).to be_success }
|
||
|
it { expect(response).to render_template 'new' }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH get' do
|
||
|
describe 'VERB', :index do
|
||
|
before do
|
||
14 years ago
|
mock_role_find
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'html' do
|
||
|
before { get 'index' }
|
||
14 years ago
|
|
||
9 years ago
|
it_should_behave_like 'index'
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'xhr' do
|
||
8 years ago
|
before { get :index, xhr: true }
|
||
14 years ago
|
|
||
9 years ago
|
it_should_behave_like 'index'
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'VERB', :new do
|
||
|
before do
|
||
14 years ago
|
@member_role = mocks_for_creating Role
|
||
11 years ago
|
allow(GlobalRole).to receive(:setable_permissions).and_return([:perm1, :perm2, :perm3])
|
||
14 years ago
|
@non_member_role = mock_model Role
|
||
|
mock_permissions_on @non_member_role
|
||
11 years ago
|
allow(Role).to receive(:non_member).and_return(@non_member_role)
|
||
14 years ago
|
|
||
|
mock_role_find
|
||
9 years ago
|
get 'new'
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
it { expect(response).to be_success }
|
||
|
it { expect(response).to render_template 'roles/new' }
|
||
|
it { expect(assigns(:member_permissions)).to eql @member_role.setable_permissions }
|
||
|
it { expect(assigns(:roles)).to eql @roles }
|
||
|
it { expect(assigns(:role)).to eql @member_role }
|
||
|
it { expect(assigns(:global_permissions)).to eql GlobalRole.setable_permissions }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'VERB', :edit do
|
||
14 years ago
|
before(:each) do
|
||
|
@member_role = mocks_for_creating Role
|
||
|
@global_role = mocks_for_creating GlobalRole
|
||
|
mock_role_find
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH member_role id' do
|
||
|
before do
|
||
|
@params = { 'id' => '1' }
|
||
11 years ago
|
allow(Role).to receive(:find).and_return(@member_role)
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'RESULT' do
|
||
|
describe 'success' do
|
||
|
describe 'html' do
|
||
8 years ago
|
before { get :edit, params: @params }
|
||
14 years ago
|
|
||
9 years ago
|
it { expect(response).to be_success }
|
||
|
it { expect(response).to render_template 'roles/edit' }
|
||
|
it { expect(assigns(:role)).to eql @member_role }
|
||
|
it { expect(assigns(:permissions)).to eql @member_role.setable_permissions }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH post' do
|
||
14 years ago
|
before(:each) do
|
||
|
@member_role = mocks_for_creating Role
|
||
|
@global_role = mocks_for_creating GlobalRole
|
||
|
mock_role_find
|
||
9 years ago
|
allow(Role).to receive(:find).with('1').and_return(@member_role)
|
||
|
allow(Role).to receive(:find).with('2').and_return(@global_role)
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'VERB', :create do
|
||
|
describe 'WITH member_role params' do
|
||
|
before do
|
||
|
@params = { 'role' => { 'name' => 'role',
|
||
|
'permissions' => %w(perm1 perm2 perm3),
|
||
|
'assignable' => '1' } }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'RESULT' do
|
||
|
describe 'success' do
|
||
14 years ago
|
before(:each) do
|
||
8 years ago
|
expect(Role)
|
||
|
.to receive(:new)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(@member_role)
|
||
11 years ago
|
allow(@member_role).to receive(:save).and_return(true)
|
||
|
allow(@member_role).to receive(:errors).and_return([])
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'html' do
|
||
|
before do
|
||
8 years ago
|
post 'create', params: @params
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
it_should_behave_like 'successful create'
|
||
|
it { expect(assigns(:role)).to eql @member_role }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'failure' do
|
||
14 years ago
|
before(:each) do
|
||
8 years ago
|
expect(Role)
|
||
|
.to receive(:new)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(@member_role)
|
||
11 years ago
|
allow(@member_role).to receive(:save).and_return(false)
|
||
9 years ago
|
allow(@member_role).to receive(:errors).and_return(['something is wrong'])
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'html' do
|
||
8 years ago
|
before { post 'create', params: @params }
|
||
14 years ago
|
|
||
9 years ago
|
it_should_behave_like 'failed create'
|
||
|
it { expect(assigns(:role)).to eql @member_role }
|
||
|
it { expect(assigns(:roles)).to eql Role.all }
|
||
|
it_should_behave_like 'permission assigns'
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH global_role params' do
|
||
|
before do
|
||
|
@params = { 'role' => { 'name' => 'role',
|
||
|
'permissions' => %w(perm1 perm2 perm3)
|
||
14 years ago
|
},
|
||
9 years ago
|
'global_role' => '1' }
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'RESULTS' do
|
||
|
describe 'success' do
|
||
14 years ago
|
before(:each) do
|
||
8 years ago
|
expect(GlobalRole)
|
||
|
.to receive(:new)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(@global_role)
|
||
11 years ago
|
allow(@global_role).to receive(:save).and_return(true)
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'html' do
|
||
8 years ago
|
before { post 'create', params: @params }
|
||
14 years ago
|
|
||
9 years ago
|
it_should_behave_like 'successful create'
|
||
14 years ago
|
end
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
describe 'failure' do
|
||
14 years ago
|
before(:each) do
|
||
8 years ago
|
expect(GlobalRole)
|
||
|
.to receive(:new)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(@global_role)
|
||
11 years ago
|
allow(@global_role).to receive(:save).and_return(false)
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'html' do
|
||
8 years ago
|
before { post 'create', params: @params }
|
||
14 years ago
|
|
||
9 years ago
|
it_should_behave_like 'failed create'
|
||
|
it { expect(assigns(:role)).to eql @global_role }
|
||
|
it { expect(assigns(:roles)).to eql Role.all }
|
||
|
it_should_behave_like 'permission assigns'
|
||
14 years ago
|
end
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'VERB', :destroy do
|
||
|
shared_examples_for 'destroy results' do
|
||
|
describe 'success' do
|
||
|
before do
|
||
11 years ago
|
expect(@role).to receive(:destroy)
|
||
8 years ago
|
post 'destroy', params: @params
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
it { expect(response).to be_redirect }
|
||
|
it { expect(response).to redirect_to '/admin/roles' }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH member_role params' do
|
||
|
before do
|
||
|
@params = { 'class' => 'Role', 'id' => '1' }
|
||
14 years ago
|
@role = @member_role
|
||
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'RESULTS' do
|
||
|
it_should_behave_like 'destroy results'
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH global_role params' do
|
||
|
before do
|
||
|
@params = { 'class' => 'Role', 'id' => '2' }
|
||
14 years ago
|
@role = @global_role
|
||
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'RESULTS' do
|
||
|
it_should_behave_like 'destroy results'
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'VERB', :update do
|
||
|
shared_examples_for 'update results' do
|
||
|
describe 'success' do
|
||
|
describe 'html' do
|
||
|
before do
|
||
8 years ago
|
expect(@role)
|
||
|
.to receive(:update_attributes)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(true)
|
||
11 years ago
|
allow(@role).to receive(:errors).and_return([])
|
||
8 years ago
|
post :update, params: @params
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
it { expect(response).to be_redirect }
|
||
|
it { expect(response).to redirect_to '/admin/roles' }
|
||
|
it { expect(flash[:notice]).to eql I18n.t(:notice_successful_update) }
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'failure' do
|
||
|
describe 'html' do
|
||
14 years ago
|
before(:each) do
|
||
8 years ago
|
expect(@role)
|
||
|
.to receive(:update_attributes)
|
||
|
.with(ActionController::Parameters.new(@params['role']).permit!)
|
||
|
.and_return(false)
|
||
9 years ago
|
allow(@role).to receive(:errors).and_return(['something is wrong'])
|
||
8 years ago
|
post :update, params: @params
|
||
14 years ago
|
end
|
||
|
|
||
9 years ago
|
it { expect(response).to render_template 'roles/edit' }
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
9 years ago
|
describe 'WITH member_role params' do
|
||
|
before do
|
||
|
@params = { 'role' => { 'permissions' => %w(permA permB),
|
||
|
'name' => 'schmu' },
|
||
|
'id' => '1' }
|
||
14 years ago
|
@role = @member_role
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'RESULT' do
|
||
|
it_should_behave_like 'update results'
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'WITH global_role params' do
|
||
|
before do
|
||
|
@params = { 'role' => { 'permissions' => %w(permA permB),
|
||
|
'name' => 'schmu' },
|
||
|
'id' => '2' }
|
||
14 years ago
|
@role = @global_role
|
||
|
end
|
||
|
|
||
9 years ago
|
describe 'RESULT' do
|
||
|
it_should_behave_like 'update results'
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
|
end
|
||
13 years ago
|
end
|