2011-10-30 22:59:03 +00:00
|
|
|
require 'spec_helper'
|
2011-12-05 09:29:17 +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-12-05 09:29:17 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index#collaborators'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update#collaborators'
|
2011-11-29 14:36:51 +00:00
|
|
|
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)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-05 09:29:17 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index#collaborators'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update#collaborators'
|
2011-11-29 14:36:51 +00:00
|
|
|
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)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-12-05 09:29:17 +00:00
|
|
|
it_should_behave_like 'be_able_to_perform_index#collaborators'
|
|
|
|
it_should_behave_like 'be_able_to_perform_update#collaborators'
|
2011-11-29 14:36:51 +00:00
|
|
|
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)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-12-05 09:29:17 +00:00
|
|
|
it_should_behave_like 'not_be_able_to_perform_index#collaborators'
|
|
|
|
it_should_behave_like 'not_be_able_to_perform_update#collaborators'
|
2011-11-29 14:36:51 +00:00
|
|
|
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)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-12-05 09:29:17 +00:00
|
|
|
it_should_behave_like 'not_be_able_to_perform_index#collaborators'
|
|
|
|
it_should_behave_like 'not_be_able_to_perform_update#collaborators'
|
2011-11-29 14:36:51 +00:00
|
|
|
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
|