[issue #347] Fixed CollaboratorsController spec.

This commit is contained in:
George Vinogradov 2012-04-24 19:02:51 +04:00
parent 326b35b4f8
commit f4e23bca14
1 changed files with 94 additions and 49 deletions

View File

@ -4,16 +4,26 @@ require 'spec_helper'
shared_examples_for 'project admin user' do
it 'should be able to view collaborators list' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
response.should be_succes
end
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(edit_project_collaborators_path(@project))
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
response.should be_success
end
it 'should add new collaborator with reader role' do
post :create, @create_params.merge(:collaborator => @user_params)
@project.relations.exists?(:object_type => 'User', :object_id => @another_user.id, :role => 'reader').should be_true
end
it 'should add new group with reader role' do
post :create, @create_params.merge(:collaborator => @group_params)
@project.relations.exists?(:object_type => 'Group', :object_id => @group.id, :role => 'reader').should be_true
end
it 'should be able to set reader role for any user' do
post :update, {:project_id => @project.id}.merge(@update_params)
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end
end
@ -21,45 +31,63 @@ end
shared_examples_for 'user with no rights for this project' do
it 'should not be able to view collaborators list' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
response.should redirect_to(forbidden_path)
end
it 'should not be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(edit_project_collaborators_path(@project))
put :update, {:project_id => @project.id, :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
post :update, {:project_id => @project.id}.merge(@update_params)
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
!@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end
end
describe CollaboratorsController do
before(:each) do
before(:each) do
stub_rsync_methods
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@update_params = {:user => {@another_user.id => :reader}}
end
@member_user = FactoryGirl.create(:user)
@update_params = {:collaborator => {:role => :reader}, :format => :json}
# Create relation with 'writer' rights
@collaborator = Collaborator.create(:actor => @member_user, :project => @project, :role => 'writer')
end
context 'for guest' do
context 'for guest' do
it 'should not be able to perform index action' do
get :index, :project_id => @project.id
response.should redirect_to(new_user_session_path)
end
it 'should not be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(new_user_session_path)
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
response.code.should == '401'
end
end
context 'for global admin' do
before(:each) do
@admin = FactoryGirl.create(:admin)
set_session_for(@admin)
end
before(:each) do
@admin = FactoryGirl.create(:admin)
set_session_for(@admin)
@group = FactoryGirl.create(:group)
@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'
}
@create_params = {
:project_id => @project.id.to_s,
:format => :json
}
end
it_should_behave_like 'project admin user'
end
@ -67,57 +95,74 @@ describe CollaboratorsController do
context 'for admin user' do
before(:each) do
@user = FactoryGirl.create(:user)
@user.relations
# @user.relations
set_session_for(@user)
@group = FactoryGirl.create(:group)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@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'
}
@create_params = {
:project_id => @project.id.to_s,
:format => :json
}
end
it_should_behave_like 'project admin user'
it 'should add new collaborator with reader role' do
@params = {:member_id => @another_user.id.to_s, :project_id => @project.id.to_s}
post :add, @params
@project.relations.exists?(:object_type => 'User', :object_id => @another_user.id, :role => 'reader').should be_true
end
it 'should add new group with reader role' do
@params = {:group_id => @group.id.to_s, :project_id => @project.id.to_s}
post :add, @params
@project.relations.exists?(:object_type => 'Group', :object_id => @group.id, :role => 'reader').should be_true
end
end
context 'for owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group = FactoryGirl.create(:group)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@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'
}
@create_params = {
:project_id => @project.id.to_s,
:format => :json
}
end
it_should_behave_like 'project admin user'
end
context 'for reader user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_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
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
end
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
end
it_should_behave_like 'user with no rights for this project'
end