rosa-build/spec/controllers/projects/collaborators_controller_sp...

138 lines
4.1 KiB
Ruby
Raw Normal View History

2011-10-30 22:59:03 +00:00
require 'spec_helper'
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)
@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-09-06 11:53:03 +01:00
@user = FactoryGirl.create(:user)
set_session_for(@user)
2014-01-21 04:51:49 +00:00
@user_params = {
2014-01-21 04:51:49 +00:00
actor_id: @another_user.id.to_s,
actor_type: 'user',
role: 'reader'
}
@group_params = {
2014-01-21 04:51:49 +00:00
actor_id: @group.id.to_s,
actor_type: 'group',
role: 'reader'
} if @group
@create_params = {
2014-01-21 04:51:49 +00:00
owner_name: @project.owner.uname, project_name: @project.name,
format: :json
}
2014-01-21 04:51:49 +00:00
@update_params = @create_params.merge(collaborator: {role: 'reader'})
end
end
shared_examples_for 'project admin user' do
it 'should be able to view collaborators list' do
2014-01-21 04:51:49 +00:00
get :index, owner_name: @project.owner.uname, project_name: @project.name
2012-04-24 16:18:55 +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, {id: @collaborator.id}.merge(@update_params)
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
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
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'
end
end
shared_examples_for 'user with no rights for this project' do
it 'should not be able to view collaborators list' do
2014-01-21 04:51:49 +00:00
get :index, owner_name: @project.owner.uname, project_name: @project.name
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, {id: @collaborator.id}.merge(@update_params)
response.should redirect_to(forbidden_path)
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'
end
end
2011-10-30 22:59:03 +00:00
describe Projects::CollaboratorsController do
include_context "collaborators controller"
2011-10-30 22:59:03 +00:00
context 'for guest' do
2012-09-06 11:53:03 +01:00
before(:each) do
set_session_for(User.new)
end
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
response.should redirect_to(new_user_session_path)
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)
response.code.should == '401'
end
end
context 'for global admin' do
before(:each) do
2012-09-06 11:53:03 +01:00
@user.role = "admin"
@user.save
end
it_should_behave_like 'project admin user'
end
context 'for admin user' do
before(:each) do
2014-01-21 04:51:49 +00:00
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
end
it_should_behave_like 'project admin user'
end
context 'for owner user' do
before(:each) do
2012-09-06 11:53:03 +01:00
@user = @project.owner # owner should be user
set_session_for(@user)
end
it_should_behave_like 'project admin user'
end
context 'for reader user' do
before(:each) do
2014-01-21 04:51:49 +00:00
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
end
it_should_behave_like 'user with no rights for this project'
end
context 'for writer user' do
before(:each) do
2014-01-21 04:51:49 +00:00
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
end
it_should_behave_like 'user with no rights for this project'
end
2011-10-30 22:59:03 +00:00
end