2011-10-30 22:59:03 +00:00
|
|
|
require 'spec_helper'
|
2011-11-29 14:36:51 +00:00
|
|
|
require 'shared_examples/collaborators_controller'
|
2011-10-30 22:59:03 +00:00
|
|
|
|
|
|
|
describe CollaboratorsController do
|
2011-11-24 19:22:37 +00:00
|
|
|
before(:each) do
|
|
|
|
@project = Factory(:project)
|
|
|
|
@another_user = Factory(:user)
|
|
|
|
@update_params = {:read => {@another_user.id => '1'}}
|
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
context 'for guest' do
|
|
|
|
it 'should not be able to perform index action' do
|
|
|
|
get :index, :project_id => @project.id
|
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
|
2011-11-26 00:54:40 +00:00
|
|
|
post :update, {:project_id => @project.id}.merge(@update_params)
|
|
|
|
response.should redirect_to(new_user_session_path)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
context 'for global admin' do
|
2011-11-24 19:22:37 +00:00
|
|
|
before(:each) do
|
|
|
|
@admin = Factory(:admin)
|
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index_action'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update_action'
|
|
|
|
it_should_behave_like 'update_collaborator_relation'
|
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
|
|
|
|
@user = Factory(:user)
|
|
|
|
@user.relations
|
|
|
|
set_session_for(@user)
|
|
|
|
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
|
|
|
r.save!
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index_action'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update_action'
|
|
|
|
it_should_behave_like 'update_collaborator_relation'
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
context 'for owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
|
|
|
r.save!
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index_action'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update_action'
|
|
|
|
it_should_behave_like 'update_collaborator_relation'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
|
|
|
r.save!
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it_should_behave_like 'not_be_able_to_perform_index_action'
|
|
|
|
it_should_behave_like 'not_be_able_to_perform_update_action'
|
|
|
|
it_should_behave_like 'not_update_collaborator_relation'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
|
|
|
r.save!
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it_should_behave_like 'not_be_able_to_perform_index_action'
|
|
|
|
it_should_behave_like 'not_be_able_to_perform_update_action'
|
|
|
|
it_should_behave_like 'not_update_collaborator_relation'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|