2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
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
|
|
|
|
@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)
|
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
@user_params = {
|
|
|
|
:actor_id => @another_user.id.to_s,
|
|
|
|
:actor_type => 'user',
|
|
|
|
:role => 'reader'
|
|
|
|
}
|
|
|
|
@group_params = {
|
|
|
|
:actor_id => @group.id.to_s,
|
|
|
|
:actor_type => 'group',
|
|
|
|
:role => 'reader'
|
|
|
|
} if @group
|
|
|
|
@create_params = {
|
|
|
|
:owner_name => @project.owner.uname, :project_name => @project.name,
|
|
|
|
:format => :json
|
|
|
|
}
|
2012-09-06 11:53:03 +01: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
|
2012-05-02 10:18:07 +01:00
|
|
|
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
|
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
|
2012-08-15 14:52:32 +01: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
|
|
|
|
post :create, @create_params.merge(:collaborator => @user_params)
|
2012-04-26 02:38:33 +01:00
|
|
|
@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
|
|
|
|
post :create, @create_params.merge(:collaborator => @group_params)
|
2012-04-26 02:38:33 +01:00
|
|
|
@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
|
2012-08-15 14:52:32 +01:00
|
|
|
put :update, {:id => @collaborator.id}.merge(@update_params)
|
2011-12-15 09:38:40 +00:00
|
|
|
@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
|
2012-05-02 10:18:07 +01:00
|
|
|
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
|
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
|
2012-08-15 14:52:32 +01: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
|
2012-08-15 14:52:32 +01:00
|
|
|
put :update, {:id => @collaborator.id}.merge(@update_params)
|
2011-12-13 15:03:06 +00:00
|
|
|
!@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
|
|
|
|
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
|
2012-05-02 10:18:07 +01:00
|
|
|
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
|
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
|
2012-08-15 14:52:32 +01: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
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => '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
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => '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
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => '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
|