[issue #347] Fixed CollaboratorsController spec.
This commit is contained in:
parent
326b35b4f8
commit
f4e23bca14
|
@ -4,16 +4,26 @@ require 'spec_helper'
|
||||||
shared_examples_for 'project admin user' do
|
shared_examples_for 'project admin user' do
|
||||||
it 'should be able to view collaborators list' do
|
it 'should be able to view collaborators list' do
|
||||||
get :index, :project_id => @project.id
|
get :index, :project_id => @project.id
|
||||||
response.should redirect_to(edit_project_collaborators_path(@project))
|
response.should be_succes
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform update action' do
|
it 'should be able to perform update action' do
|
||||||
post :update, {:project_id => @project.id}.merge(@update_params)
|
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
|
||||||
response.should redirect_to(edit_project_collaborators_path(@project))
|
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
|
end
|
||||||
|
|
||||||
it 'should be able to set reader role for any user' do
|
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'
|
@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,45 +31,63 @@ end
|
||||||
shared_examples_for 'user with no rights for this project' do
|
shared_examples_for 'user with no rights for this project' do
|
||||||
it 'should not be able to view collaborators list' do
|
it 'should not be able to view collaborators list' do
|
||||||
get :index, :project_id => @project.id
|
get :index, :project_id => @project.id
|
||||||
response.should redirect_to(edit_project_collaborators_path(@project))
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform update action' do
|
it 'should not be able to perform update action' do
|
||||||
post :update, {:project_id => @project.id}.merge(@update_params)
|
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
|
||||||
response.should redirect_to(edit_project_collaborators_path(@project))
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to set reader role for any user' do
|
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'
|
!@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe CollaboratorsController do
|
describe CollaboratorsController do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
stub_rsync_methods
|
stub_rsync_methods
|
||||||
@project = FactoryGirl.create(:project)
|
@project = FactoryGirl.create(:project)
|
||||||
@another_user = FactoryGirl.create(:user)
|
@another_user = FactoryGirl.create(:user)
|
||||||
@update_params = {:user => {@another_user.id => :reader}}
|
@member_user = FactoryGirl.create(:user)
|
||||||
end
|
@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
|
it 'should not be able to perform index action' do
|
||||||
get :index, :project_id => @project.id
|
get :index, :project_id => @project.id
|
||||||
response.should redirect_to(new_user_session_path)
|
response.should redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform update action' do
|
it 'should not be able to perform update action' do
|
||||||
post :update, {:project_id => @project.id}.merge(@update_params)
|
put :update, {:project_id => @project.id, :id => @collaborator.id}.merge(@update_params)
|
||||||
response.should redirect_to(new_user_session_path)
|
response.code.should == '401'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for global admin' do
|
context 'for global admin' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@admin = FactoryGirl.create(:admin)
|
@admin = FactoryGirl.create(:admin)
|
||||||
set_session_for(@admin)
|
set_session_for(@admin)
|
||||||
end
|
@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'
|
it_should_behave_like 'project admin user'
|
||||||
end
|
end
|
||||||
|
@ -67,57 +95,74 @@ describe CollaboratorsController do
|
||||||
context 'for admin user' do
|
context 'for admin user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
@user.relations
|
# @user.relations
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
@group = FactoryGirl.create(:group)
|
@group = FactoryGirl.create(:group)
|
||||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
@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
|
end
|
||||||
|
|
||||||
it_should_behave_like 'project admin user'
|
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
|
end
|
||||||
|
|
||||||
context 'for owner user' do
|
context 'for owner user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
@project.update_attribute(:owner, @user)
|
@group = FactoryGirl.create(:group)
|
||||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
|
||||||
end
|
@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'
|
it_should_behave_like 'project admin user'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for reader user' do
|
context 'for reader user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
@project.update_attribute(:owner, @user)
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it_should_behave_like 'user with no rights for this project'
|
it_should_behave_like 'user with no rights for this project'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for writer user' do
|
context 'for writer user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
@project.update_attribute(:owner, @user)
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
||||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it_should_behave_like 'user with no rights for this project'
|
it_should_behave_like 'user with no rights for this project'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue