[refs #40] Global test names and shared examples refactor

This commit is contained in:
konstantin.grabar 2011-12-15 13:38:40 +04:00
parent 964e312d08
commit aca207cda4
12 changed files with 158 additions and 221 deletions

View File

@ -13,7 +13,7 @@ shared_examples_for 'project admin user' do
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) post :update, {:project_id => @project.id}.merge(@update_params)
@another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'reader' @another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read'
end end
end end

View File

@ -26,10 +26,18 @@ describe GroupsController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'be_able_to_perform_index#groups'
it_should_behave_like 'be_able_to_perform_update#groups'
it_should_behave_like 'update_member_relation' it_should_behave_like 'update_member_relation'
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
it 'should be able to perform update action' do
put :update, {:id => @group.id}.merge(@update_params)
response.should redirect_to(group_path(@group))
end
it 'should be able to perform create action' do it 'should be able to perform create action' do
post :create, @create_params post :create, @create_params
response.should redirect_to(group_path( Group.last.id )) response.should redirect_to(group_path( Group.last.id ))

View File

@ -1,5 +1,47 @@
require 'spec_helper' require 'spec_helper'
#require 'shared_examples/personal_repositories_controller'
shared_examples_for 'personal repository viewer' do
it 'should be able to show personal repository' do
get :show, :id => @repository.id
response.should render_template(:show)
end
end
shared_examples_for 'personal repository owner' do
it_should_behave_like 'personal repository viewer'
it 'should be able to perform add_project action' do
get :add_project, :id => @repository.id
response.should render_template(:projects_list)
end
it 'should be able to add project personal repository with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end
it 'should be able to perform change_visibility action' do
get :change_visibility, :id => @repository.id
response.should redirect_to(settings_personal_repository_path(@repository))
end
it 'should be able to change visibility of repository' do
get :change_visibility, :id => @repository.id
@repository.platform.reload.visibility.should == 'open'
end
it 'should be able to perform settings action' do
get :settings, :id => @repository.id
response.should render_template(:settings)
end
end
describe PersonalRepositoriesController do describe PersonalRepositoriesController do
before(:each) do before(:each) do
@ -27,14 +69,9 @@ describe PersonalRepositoriesController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'show personal repository' it_should_behave_like 'personal repository owner'
it_should_behave_like 'add project to personal repository' it_should_behave_like 'repository user with add project rights'
it_should_behave_like 'add project personal repository with project_id param' it_should_behave_like 'repository user with remove project rights'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'remove project from repository'
it_should_behave_like 'remove project from personal repository'
it_should_behave_like 'change visibility'
it_should_behave_like 'settings personal repository'
end end
context 'for anyone except admin' do context 'for anyone except admin' do
@ -57,14 +94,9 @@ describe PersonalRepositoriesController do
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'show personal repository' it_should_behave_like 'personal repository owner'
it_should_behave_like 'change visibility' it_should_behave_like 'repository user with add project rights'
it_should_behave_like 'add project to personal repository' it_should_behave_like 'repository user with remove project rights'
it_should_behave_like 'add project personal repository with project_id param'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'remove project from personal repository'
it_should_behave_like 'remove project from repository'
it_should_behave_like 'settings personal repository'
end end
context 'for reader user' do context 'for reader user' do
@ -74,7 +106,7 @@ describe PersonalRepositoriesController do
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end end
it_should_behave_like 'show personal repository' it_should_behave_like 'personal repository viewer'
it 'should not be able to perform add_project action' do it 'should not be able to perform add_project action' do
get :add_project, :id => @repository.id get :add_project, :id => @repository.id

View File

@ -1,5 +1,36 @@
require 'spec_helper' require 'spec_helper'
#require "shared_examples/platforms_controller"
shared_examples_for 'platform owner' do
it_should_behave_like 'platform index viewer'
it 'should not be able to destroy personal platform' do
delete :destroy, :id => @personal_platform.id
response.should redirect_to(forbidden_path)
end
it 'should change objects count on destroy success' do
lambda { delete :destroy, :id => @platform.id }.should change{ Platform.count }.by(-1)
end
it 'should be able to perform destroy action' do
delete :destroy, :id => @platform.id
response.should redirect_to(root_path)
end
end
shared_examples_for 'platform index viewer' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
end
shared_examples_for 'user without create rights' do
it 'should not be able to create platform' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
end
describe PlatformsController do describe PlatformsController do
before(:each) do before(:each) do
@ -44,8 +75,6 @@ describe PlatformsController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'able_to_perform_index#platforms'
it 'should be able to perform new action' do it 'should be able to perform new action' do
get :new get :new
response.should render_template(:new) response.should render_template(:new)
@ -60,14 +89,12 @@ describe PlatformsController do
lambda { post :create, @create_params }.should change{ Platform.count }.by(1) lambda { post :create, @create_params }.should change{ Platform.count }.by(1)
end end
it_should_behave_like 'be_able_to_perform_destroy#platforms' it_should_behave_like 'platform owner'
it_should_behave_like 'change_objects_count_on_destroy_success'
it_should_behave_like 'not_be_able_to_destroy_personal_platform'
context 'when owner uname present' do context 'when owner uname present' do
it 'should create platform with mentioned owner' do it 'should create platform with mentioned owner' do
post :create, @create_params.merge({:admin_uname => @user.uname}) post :create, @create_params.merge({:admin_uname => @user.uname, :admin_id => @user.id})
Platform.last.owner.id.should eql(@user.id) Platform.last.owner.id.should eql(@user.id)
end end
@ -83,11 +110,8 @@ describe PlatformsController do
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'able_to_perform_index#platforms' it_should_behave_like 'user without create rights'
it_should_behave_like 'not_be_able_to_perform_create#platforms' it_should_behave_like 'platform owner'
it_should_behave_like 'be_able_to_perform_destroy#platforms'
it_should_behave_like 'change_objects_count_on_destroy_success'
it_should_behave_like 'not_be_able_to_destroy_personal_platform'
it 'should be able to perform new action' do it 'should be able to perform new action' do
get :new get :new
@ -108,8 +132,8 @@ describe PlatformsController do
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end end
it_should_behave_like 'able_to_perform_index#platforms' it_should_behave_like 'platform index viewer'
it_should_behave_like 'not_be_able_to_perform_create#platforms' it_should_behave_like 'user without create rights'
it 'should not be able to perform destroy action' do it 'should not be able to perform destroy action' do
delete :destroy, :id => @platform.id delete :destroy, :id => @platform.id

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
#require 'shared_examples/projects_controller'
describe ProjectsController do describe ProjectsController do
before(:each) do before(:each) do
@ -40,9 +39,8 @@ describe ProjectsController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'be_able_to_perform_index#projects' it_should_behave_like 'projects user with writer rights'
it_should_behave_like 'be_able_to_perform_update#projects' it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'update collaborator relation'
it 'should be able to perform create action' do it 'should be able to perform create action' do
post :create, @create_params post :create, @create_params
@ -52,8 +50,6 @@ describe ProjectsController do
it 'should change objects count on create' do it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Project.count }.by(1) lambda { post :create, @create_params }.should change{ Project.count }.by(1)
end end
it_should_behave_like 'be_able_to_fork_project'
end end
context 'for owner user' do context 'for owner user' do
@ -64,10 +60,8 @@ describe ProjectsController 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 'be_able_to_perform_update#projects' it_should_behave_like 'projects user with writer rights'
it_should_behave_like 'update collaborator relation' it_should_behave_like 'user with rights to view projects'
it_should_behave_like 'be_able_to_perform_build#projects'
it_should_behave_like 'be_able_to_perform_process_build#projects'
it 'should be able to perform destroy action' do it 'should be able to perform destroy action' do
delete :destroy, {:id => @project.id} delete :destroy, {:id => @project.id}
@ -91,14 +85,13 @@ describe ProjectsController 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 'be_able_to_perform_index#projects' it_should_behave_like 'projects user with reader rights'
it 'should be able to perform show action' do it 'should be able to perform show action' do
get :show, :id => @project.id get :show, :id => @project.id
response.should render_template(:show) response.should render_template(:show)
end end
it_should_behave_like 'be_able_to_fork_project'
end end
context 'for writer user' do context 'for writer user' do
@ -108,10 +101,7 @@ describe ProjectsController 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 'be_able_to_perform_update#projects' it_should_behave_like 'projects user with writer rights'
it_should_behave_like 'update collaborator relation' it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'be_able_to_perform_build#projects'
it_should_behave_like 'be_able_to_perform_process_build#projects'
it_should_behave_like 'be_able_to_fork_project'
end end
end end

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
#require 'shared_examples/repositories_controller'
describe RepositoriesController do describe RepositoriesController do
before(:each) do before(:each) do
@ -35,9 +34,6 @@ describe RepositoriesController do
set_session_for(@admin) set_session_for(@admin)
end end
it_should_behave_like 'be_able_to_perform_index#repositories'
it_should_behave_like 'be_able_to_perform_show#repositories'
it 'should be able to perform new action' do it 'should be able to perform new action' do
get :new, :platform_id => @platform.id get :new, :platform_id => @platform.id
response.should render_template(:new) response.should render_template(:new)
@ -52,14 +48,7 @@ describe RepositoriesController do
lambda { post :create, @create_params }.should change{ Repository.count }.by(1) lambda { post :create, @create_params }.should change{ Repository.count }.by(1)
end end
it_should_behave_like 'be_able_to_perform_destroy#repositories' it_should_behave_like 'repository user with admin rights'
it_should_behave_like 'change_repositories_count_after_destroy'
it_should_behave_like 'be_able_to_perform_add_project#repositories'
it_should_behave_like 'be_able_to_perform_add_project#repositories_with_project_id_param'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'be_able_to_perform_remove_project#repositories'
it_should_behave_like 'remove project from repository'
it_should_behave_like 'destroy personal repository'
end end
context 'for anyone except admin' do context 'for anyone except admin' do
@ -93,15 +82,7 @@ describe RepositoriesController do
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'be_able_to_perform_index#repositories' it_should_behave_like 'repository user with owner rights'
it_should_behave_like 'be_able_to_perform_show#repositories'
it_should_behave_like 'be_able_to_perform_add_project#repositories'
it_should_behave_like 'be_able_to_perform_add_project#repositories_with_project_id_param'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'be_able_to_perform_remove_project#repositories'
it_should_behave_like 'remove project from repository'
it_should_behave_like 'be_able_to_perform_destroy#repositories'
it_should_behave_like 'change_repositories_count_after_destroy'
end end
context 'for reader user' do context 'for reader user' do
@ -111,8 +92,7 @@ describe RepositoriesController do
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end end
it_should_behave_like 'be_able_to_perform_index#repositories' it_should_behave_like 'repository user with reader rights'
it_should_behave_like 'be_able_to_perform_show#repositories'
it 'should not be able to perform add_project action' do it 'should not be able to perform add_project action' do
get :add_project, :id => @repository.id get :add_project, :id => @repository.id

View File

@ -213,7 +213,7 @@ describe CanCan do
end end
[:manage, :add_project, :remove_project, :change_visibility, :settings].each do |action| [:manage, :add_project, :remove_project, :change_visibility, :settings].each do |action|
it 'should be able to #{ action } repository' do it "should be able to #{ action } repository" do
@ability.should be_able_to(action, @repository) @ability.should be_able_to(action, @repository)
end end
end end

View File

@ -1,15 +0,0 @@
shared_examples_for 'be_able_to_perform_index#groups' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
end
shared_examples_for 'be_able_to_perform_update#groups' do
it 'should be able to perform update action' do
put :update, {:id => @group.id}.merge(@update_params)
response.should redirect_to(group_path(@group))
end
end

View File

@ -1,28 +1,7 @@
shared_examples_for 'show personal repository' do shared_examples_for 'not destroy personal repository' do
it 'should be able to perform show action' do it 'should not be able to destroy personal repository' do
get :show, :id => @repository.id delete :destroy, :id => @personal_repository.id
response.should render_template(:show) response.should redirect_to(forbidden_path)
end
end
shared_examples_for 'add project to personal repository' do
it 'should be able to perform add_project action' do
get :add_project, :id => @repository.id
response.should render_template(:projects_list)
end
end
shared_examples_for 'add project personal repository with project_id param' do
it 'should be able to perform add_project action with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end
end
shared_examples_for 'remove project from personal repository' do
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end end
end end
@ -32,29 +11,3 @@ shared_examples_for 'destroy personal repository' do
response.should redirect_to(platform_path(@repository.platform.id)) response.should redirect_to(platform_path(@repository.platform.id))
end end
end end
shared_examples_for 'not destroy personal repository' do
it 'should not be able to destroy personal repository' do
delete :destroy, :id => @personal_repository.id
response.should redirect_to(forbidden_path)
end
end
shared_examples_for 'settings personal repository' do
it 'should be able to perform settings action' do
get :settings, :id => @repository.id
response.should render_template(:settings)
end
end
shared_examples_for 'change visibility' do
it 'should be able to perform change_visibility action' do
get :change_visibility, :id => @repository.id
response.should redirect_to(settings_personal_repository_path(@repository))
end
it 'should change visibility of repository' do
get :change_visibility, :id => @repository.id
@repository.platform.reload.visibility.should == 'open'
end
end

View File

@ -1,34 +0,0 @@
shared_examples_for 'able_to_perform_index#platforms' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
end
shared_examples_for 'not_be_able_to_perform_create#platforms' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
end
shared_examples_for 'not_be_able_to_destroy_personal_platform' do
it 'should be able to perform create action' do
delete :destroy, :id => @personal_platform.id
response.should redirect_to(forbidden_path)
end
end
shared_examples_for 'change_objects_count_on_destroy_success' do
it 'should change objects count on destroy success' do
lambda { delete :destroy, :id => @platform.id }.should change{ Platform.count }.by(-1)
end
end
shared_examples_for 'be_able_to_perform_destroy#platforms' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @platform.id
response.should redirect_to(root_path)
end
end

View File

@ -1,34 +1,32 @@
shared_examples_for 'be_able_to_perform_index#projects' do shared_examples_for 'projects user with reader rights' do
it 'should be able to perform index action' do it_should_behave_like 'user with rights to view projects'
get :index
response.should render_template(:index)
end
end
shared_examples_for 'be_able_to_perform_update#projects' do
it 'should be able to perform update action' do
put :update, {:id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'be_able_to_fork_project' do
it 'should be able to fork project' do it 'should be able to fork project' do
post :fork, :id => @project.id post :fork, :id => @project.id
response.should redirect_to(project_path(Project.last)) response.should redirect_to(project_path(Project.last))
end end
end end
shared_examples_for 'be_able_to_perform_build#projects' do shared_examples_for 'projects user with writer rights' do
it 'should be able to perform update action' do
put :update, {:id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
it 'should be able to perform build action' do it 'should be able to perform build action' do
get :build, :id => @project.id get :build, :id => @project.id
response.should render_template(:build) response.should render_template(:build)
end end
end
shared_examples_for 'be_able_to_perform_process_build#projects' do
it 'should be able to perform process_build action' do it 'should be able to perform process_build action' do
post :process_build, {:id => @project.id}.merge(@process_build_params) post :process_build, {:id => @project.id}.merge(@process_build_params)
response.should redirect_to(project_path(@project)) response.should redirect_to(project_path(@project))
end end
end end
shared_examples_for 'user with rights to view projects' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
end

View File

@ -1,61 +1,62 @@
shared_examples_for 'be_able_to_perform_index#repositories' do shared_examples_for 'repository user with reader rights' do
it 'should be able to perform index action' do it 'should be able to perform index action' do
get :index get :index
response.should render_template(:index) response.should render_template(:index)
end end
end
shared_examples_for 'be_able_to_perform_show#repositories' do
it 'should be able to perform show action' do it 'should be able to perform show action' do
get :show, :id => @repository.id get :show, :id => @repository.id
response.should render_template(:show) response.should render_template(:show)
end end
end end
shared_examples_for 'be_able_to_perform_add_project#repositories' do shared_examples_for 'repository user with owner rights' do
it 'should be able to perform add_project action' do it 'should be able to perform add_project action' do
get :add_project, :id => @repository.id get :add_project, :id => @repository.id
response.should render_template(:projects_list) response.should render_template(:projects_list)
end end
end
shared_examples_for 'be_able_to_perform_add_project#repositories_with_project_id_param' do
it 'should be able to perform add_project action with project_id param' do it 'should be able to perform add_project action with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(repository_path(@repository)) response.should redirect_to(repository_path(@repository))
end end
it_should_behave_like 'repository user with add project rights'
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(repository_path(@repository))
end end
shared_examples_for 'add_project_to_repository' do it_should_behave_like 'repository user with remove project rights'
it 'should be able to perform destroy action' do
delete :destroy, :id => @repository.id
response.should redirect_to(platform_path(@repository.platform.id))
end
it 'should change objects count after destroy action' do
lambda { delete :destroy, :id => @repository.id }.should change{ Repository.count }.by(-1)
end
it_should_behave_like 'repository user with reader rights'
end
shared_examples_for 'repository user with admin rights' do
it_should_behave_like 'repository user with owner rights'
it_should_behave_like 'destroy personal repository'
end
shared_examples_for 'repository user with add project rights' do
it 'should be able to add project to repository' do it 'should be able to add project to repository' do
get :add_project, :id => @repository.id, :project_id => @project.id get :add_project, :id => @repository.id, :project_id => @project.id
@repository.projects.exists? :id => @project.id @repository.projects.exists? :id => @project.id
end end
end end
shared_examples_for 'be_able_to_perform_remove_project#repositories' do shared_examples_for 'repository user with remove project rights' do
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(repository_path(@repository))
end
end
shared_examples_for 'remove project from repository' do
it 'should be able to remove project from repository' do it 'should be able to remove project from repository' do
get :remove_project, :id => @repository.id, :project_id => @project.id get :remove_project, :id => @repository.id, :project_id => @project.id
!@repository.projects.exists? :id => @project.id !@repository.projects.exists? :id => @project.id
end end
end end
shared_examples_for 'be_able_to_perform_destroy#repositories' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @repository.id
response.should redirect_to(platform_path(@repository.platform.id))
end
end
shared_examples_for 'change_repositories_count_after_destroy' do
it 'should change objects count after destroy action' do
lambda { delete :destroy, :id => @repository.id }.should change{ Repository.count }.by(-1)
end
end