2013-04-12 14:26:18 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-04-15 12:47:53 +01:00
|
|
|
shared_examples_for 'hooks user with project admin rights' do
|
|
|
|
it 'should be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, {owner_name: @project.owner.uname, project_name: @project.name}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform new action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, {owner_name: @project.owner.uname, project_name: @project.name, hook: {name: 'web'}}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform edit action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, {owner_name: @project.owner.uname, project_name: @project.name, id: @hook.id}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {owner_name: @project.owner.uname, project_name: @project.name, id: @hook.id}.merge(@update_params)
|
|
|
|
response.should redirect_to(project_hooks_path(@project, name: 'web'))
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform create action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, {owner_name: @project.owner.uname, project_name: @project.name}.merge(@create_params)
|
|
|
|
response.should redirect_to(project_hooks_path(@project, name: 'web'))
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'hooks user without project admin rights' do
|
|
|
|
it 'should not be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, {owner_name: @project.owner.uname, project_name: @project.name}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform new action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, {owner_name: @project.owner.uname, project_name: @project.name, hook: {name: 'web'}}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform edit action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, {owner_name: @project.owner.uname, project_name: @project.name, id: @hook.id}
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {owner_name: @project.owner.uname, project_name: @project.name, id: @hook.id}.merge(@update_params)
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform create action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, {owner_name: @project.owner.uname, project_name: @project.name}.merge(@create_params)
|
2013-04-15 12:47:53 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Projects::HooksController do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
stub_symlink_methods
|
|
|
|
|
|
|
|
@project = FactoryGirl.create(:project)
|
2014-01-21 04:51:49 +00:00
|
|
|
@hook = FactoryGirl.create(:hook, project: @project)
|
2013-04-15 12:47:53 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@create_params = {hook: {name: 'web', data: {url: 'create'}}}
|
|
|
|
@update_params = {hook: {data: {url: 'update'}}}
|
2013-04-15 12:47:53 +01:00
|
|
|
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'registered user' do
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
end # context 'registered user'
|
|
|
|
|
|
|
|
context 'for project members' do
|
|
|
|
|
|
|
|
context 'for global admin' do
|
|
|
|
before do
|
|
|
|
@user.role = "admin"
|
|
|
|
@user.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
|
|
|
before do
|
|
|
|
@user = @project.owner
|
|
|
|
set_session_for(@user) # owner should be user
|
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
end # context 'for project members'
|
|
|
|
|
|
|
|
context 'for group' do
|
|
|
|
before do
|
|
|
|
@group = FactoryGirl.create(:group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group is owner of the project' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project, owner: @group)
|
|
|
|
@hook = FactoryGirl.create(:hook, project: @project)
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with reader role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'admin'
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with admin role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group is member of the project' do
|
|
|
|
context 'with admin rights' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create actor_id: @group.id, actor_type: @group.class.to_s, role: 'admin'
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with reader role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'reader'
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with admin role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reader rights' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create actor_id: @group.id, actor_type: @group.class.to_s, role: 'reader'
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with reader role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'admin'
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user with project admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group member user with admin role' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
|
2013-04-15 12:47:53 +01:00
|
|
|
end
|
|
|
|
it_should_behave_like 'hooks user without project admin rights'
|
|
|
|
end
|
|
|
|
end
|
2013-04-12 14:26:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|