2011-10-30 22:59:03 +00:00
|
|
|
require 'spec_helper'
|
2011-12-13 15:03:06 +00:00
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
shared_context "collaborators controller" do
|
|
|
|
before(:each) do
|
|
|
|
stub_symlink_methods
|
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@another_user = FactoryGirl.create(:user)
|
2012-09-06 11:53:03 +01:00
|
|
|
@group = FactoryGirl.create(:group)
|
2012-08-15 14:52:32 +01:00
|
|
|
@member_user = FactoryGirl.create(:user)
|
|
|
|
# Create relation with 'writer' rights
|
2014-01-21 04:51:49 +00:00
|
|
|
@collaborator = Collaborator.create(actor: @member_user, project: @project, role: 'writer')
|
2012-08-15 14:52:32 +01:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
@user_params = {
|
2014-01-21 04:51:49 +00:00
|
|
|
actor_id: @another_user.id.to_s,
|
|
|
|
actor_type: 'user',
|
|
|
|
role: 'reader'
|
2012-08-15 14:52:32 +01:00
|
|
|
}
|
|
|
|
@group_params = {
|
2014-01-21 04:51:49 +00:00
|
|
|
actor_id: @group.id.to_s,
|
|
|
|
actor_type: 'group',
|
|
|
|
role: 'reader'
|
2012-08-15 14:52:32 +01:00
|
|
|
} if @group
|
|
|
|
@create_params = {
|
2014-03-19 07:19:03 +00:00
|
|
|
name_with_owner: @project.name_with_owner,
|
2014-01-21 04:51:49 +00:00
|
|
|
format: :json
|
2012-08-15 14:52:32 +01:00
|
|
|
}
|
2014-03-19 07:11:16 +00:00
|
|
|
@update_params = @create_params.merge(collaborator: { role: 'reader' })
|
2012-08-15 14:52:32 +01:00
|
|
|
end
|
2012-04-24 16:38:50 +01:00
|
|
|
end
|
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
shared_examples_for 'project admin user' do
|
|
|
|
it 'should be able to view collaborators list' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2012-04-24 16:18:55 +01:00
|
|
|
response.should be_success
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @collaborator.id}.merge(@update_params)
|
2012-04-24 16:02:51 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add new collaborator with reader role' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @create_params.merge(collaborator: @user_params)
|
|
|
|
@project.relations.exists?(actor_type: 'User', actor_id: @another_user.id, role: 'reader').should be_true
|
2012-04-24 16:02:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add new group with reader role' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @create_params.merge(collaborator: @group_params)
|
|
|
|
@project.relations.exists?(actor_type: 'Group', actor_id: @group.id, role: 'reader').should be_true
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to set reader role for any user' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @collaborator.id}.merge(@update_params)
|
|
|
|
@another_user.relations.exists? target_id: @project.id, target_type: 'Project', role: 'read'
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user with no rights for this project' do
|
|
|
|
it 'should not be able to view collaborators list' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2012-04-24 16:02:51 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @collaborator.id}.merge(@update_params)
|
2012-04-24 16:02:51 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to set reader role for any user' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @collaborator.id}.merge(@update_params)
|
|
|
|
!@another_user.relations.exists? target_id: @project.id, target_type: 'Project', role: 'read'
|
2011-12-13 15:03:06 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
describe Projects::CollaboratorsController do
|
2012-08-15 14:52:32 +01:00
|
|
|
include_context "collaborators controller"
|
2011-10-30 22:59:03 +00:00
|
|
|
|
2012-04-24 16:02:51 +01:00
|
|
|
context 'for guest' do
|
2012-09-06 11:53:03 +01:00
|
|
|
before(:each) do
|
|
|
|
set_session_for(User.new)
|
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
it 'should not be able to perform index action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2011-11-26 00:54:40 +00:00
|
|
|
response.should redirect_to(new_user_session_path)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @collaborator.id}.merge(@update_params)
|
2012-04-24 16:02:51 +01:00
|
|
|
response.code.should == '401'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
context 'for global admin' do
|
2012-04-24 16:02:51 +01:00
|
|
|
before(:each) do
|
2012-09-06 11:53:03 +01:00
|
|
|
@user.role = "admin"
|
|
|
|
@user.save
|
2012-04-24 16:02:51 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
it_should_behave_like 'project admin user'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
context 'for admin user' do
|
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'admin')
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
it_should_behave_like 'project admin user'
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
context 'for owner user' do
|
2012-04-24 16:02:51 +01:00
|
|
|
before(:each) do
|
2012-09-06 11:53:03 +01:00
|
|
|
@user = @project.owner # owner should be user
|
2012-04-24 16:02:51 +01:00
|
|
|
set_session_for(@user)
|
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
it_should_behave_like 'project admin user'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
2012-04-24 16:02:51 +01:00
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'reader')
|
2012-04-24 16:02:51 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
it_should_behave_like 'user with no rights for this project'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
2012-04-24 16:02:51 +01:00
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'writer')
|
2012-04-24 16:02:51 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-13 15:03:06 +00:00
|
|
|
it_should_behave_like 'user with no rights for this project'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|