[refs #40] Refactor collaborators specs names

This commit is contained in:
konstantin.grabar 2011-12-13 19:03:06 +04:00
parent bd8788fe49
commit 2c2fcb4a76
3 changed files with 39 additions and 56 deletions

View File

@ -30,7 +30,6 @@ class CollaboratorsController < ApplicationController
def update def update
all_user_ids = [] all_user_ids = []
all_groups_ids = [] all_groups_ids = []
puts params.inspect
Relation::ROLES.each { |r| Relation::ROLES.each { |r|
all_user_ids = all_user_ids | params['user'][r.to_sym].keys if params['user'] && params['user'][r.to_sym] all_user_ids = all_user_ids | params['user'][r.to_sym].keys if params['user'] && params['user'][r.to_sym]
all_groups_ids = all_groups_ids | params['group'][r.to_sym].keys if params['group'] && params['group'][r.to_sym] all_groups_ids = all_groups_ids | params['group'][r.to_sym].keys if params['group'] && params['group'][r.to_sym]

View File

@ -1,5 +1,38 @@
require 'spec_helper' require 'spec_helper'
#require 'shared_examples/collaborators_controller'
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))
end
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
it 'should be able to set reader role for any user' do
post :update, {:project_id => @project.id}.merge(@update_params)
@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'reader'
end
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))
end
it 'should not be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
it 'should not be able to set reader role for any user' do
post :update, {:project_id => @project.id}.merge(@update_params)
!@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end
end
describe CollaboratorsController do describe CollaboratorsController do
before(:each) do before(:each) do
@ -26,9 +59,7 @@ describe CollaboratorsController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'show collaborators list' it_should_behave_like 'project admin user'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end end
context 'for admin user' do context 'for admin user' do
@ -39,9 +70,7 @@ describe CollaboratorsController do
@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 'show collaborators list' it_should_behave_like 'project admin user'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end end
context 'for owner user' do context 'for owner user' do
@ -52,9 +81,7 @@ describe CollaboratorsController do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'show collaborators list' it_should_behave_like 'project admin user'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end end
context 'for reader user' do context 'for reader user' do
@ -65,9 +92,7 @@ describe CollaboratorsController do
@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 'not show collaborators list' it_should_behave_like 'user with no rights for this project'
it_should_behave_like 'not update collaborators'
it_should_behave_like 'not update collaborator relation'
end end
context 'for writer user' do context 'for writer user' do
@ -78,8 +103,6 @@ describe CollaboratorsController do
@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 'not show collaborators list' it_should_behave_like 'user with no rights for this project'
it_should_behave_like 'not update collaborators'
it_should_behave_like 'not update collaborator relation'
end end
end end

View File

@ -1,39 +0,0 @@
shared_examples_for 'show collaborators list' do
it 'should be able to perform index action' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
end
end
shared_examples_for 'update collaborators' do
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'update collaborator relation' do
it 'should update collaborator relation' do
@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end
end
shared_examples_for 'not show collaborators list' do
it 'should be able to perform index action' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
end
end
shared_examples_for 'not update collaborators' do
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'not update collaborator relation' do
it 'should set flash notice on update success' do
!@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end
end