diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index f3debdc90..ac17849e8 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -13,7 +13,7 @@ shared_examples_for 'project admin user' do 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' + @another_user.relations.exists? :target_id => @project.id, :target_type => 'Project', :role => 'read' end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index d9b3a897f..1d9793b04 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -26,10 +26,18 @@ describe GroupsController do set_session_for(@admin) 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 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 post :create, @create_params response.should redirect_to(group_path( Group.last.id )) diff --git a/spec/controllers/personal_repositories_controller_spec.rb b/spec/controllers/personal_repositories_controller_spec.rb index 09395e483..6fb764ae8 100644 --- a/spec/controllers/personal_repositories_controller_spec.rb +++ b/spec/controllers/personal_repositories_controller_spec.rb @@ -1,5 +1,47 @@ 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 before(:each) do @@ -27,14 +69,9 @@ describe PersonalRepositoriesController do set_session_for(@admin) end - it_should_behave_like 'show personal repository' - it_should_behave_like 'add project to personal repository' - 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 repository' - it_should_behave_like 'remove project from personal repository' - it_should_behave_like 'change visibility' - it_should_behave_like 'settings personal repository' + it_should_behave_like 'personal repository owner' + it_should_behave_like 'repository user with add project rights' + it_should_behave_like 'repository user with remove project rights' end 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') end - it_should_behave_like 'show personal repository' - it_should_behave_like 'change visibility' - it_should_behave_like 'add project to personal repository' - 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' + it_should_behave_like 'personal repository owner' + it_should_behave_like 'repository user with add project rights' + it_should_behave_like 'repository user with remove project rights' end context 'for reader user' do @@ -74,7 +106,7 @@ describe PersonalRepositoriesController do @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') 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 get :add_project, :id => @repository.id diff --git a/spec/controllers/platforms_controller_spec.rb b/spec/controllers/platforms_controller_spec.rb index d00f5a65d..03dc09848 100644 --- a/spec/controllers/platforms_controller_spec.rb +++ b/spec/controllers/platforms_controller_spec.rb @@ -1,5 +1,36 @@ 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 before(:each) do @@ -44,8 +75,6 @@ describe PlatformsController do set_session_for(@admin) end - it_should_behave_like 'able_to_perform_index#platforms' - it 'should be able to perform new action' do get :new response.should render_template(:new) @@ -60,14 +89,12 @@ describe PlatformsController do lambda { post :create, @create_params }.should change{ Platform.count }.by(1) end - 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_behave_like 'platform owner' context 'when owner uname present' 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) end @@ -83,11 +110,8 @@ describe PlatformsController do @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end - it_should_behave_like 'able_to_perform_index#platforms' - it_should_behave_like 'not_be_able_to_perform_create#platforms' - 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_behave_like 'user without create rights' + it_should_behave_like 'platform owner' it 'should be able to perform new action' do get :new @@ -108,8 +132,8 @@ describe PlatformsController do @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end - it_should_behave_like 'able_to_perform_index#platforms' - it_should_behave_like 'not_be_able_to_perform_create#platforms' + it_should_behave_like 'platform index viewer' + it_should_behave_like 'user without create rights' it 'should not be able to perform destroy action' do delete :destroy, :id => @platform.id diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index eded2b56c..a02b5e63e 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -#require 'shared_examples/projects_controller' describe ProjectsController do before(:each) do @@ -40,9 +39,8 @@ describe ProjectsController do set_session_for(@admin) end - it_should_behave_like 'be_able_to_perform_index#projects' - it_should_behave_like 'be_able_to_perform_update#projects' - it_should_behave_like 'update collaborator relation' + it_should_behave_like 'projects user with writer rights' + it_should_behave_like 'projects user with reader rights' it 'should be able to perform create action' do post :create, @create_params @@ -52,8 +50,6 @@ describe ProjectsController do it 'should change objects count on create' do lambda { post :create, @create_params }.should change{ Project.count }.by(1) end - - it_should_behave_like 'be_able_to_fork_project' end context 'for owner user' do @@ -64,10 +60,8 @@ describe ProjectsController do @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end - it_should_behave_like 'be_able_to_perform_update#projects' - it_should_behave_like 'update collaborator relation' - 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 'projects user with writer rights' + it_should_behave_like 'user with rights to view projects' it 'should be able to perform destroy action' do delete :destroy, {:id => @project.id} @@ -91,14 +85,13 @@ describe ProjectsController do @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') 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 get :show, :id => @project.id response.should render_template(:show) end - it_should_behave_like 'be_able_to_fork_project' end context 'for writer user' do @@ -108,10 +101,7 @@ describe ProjectsController do @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') end - it_should_behave_like 'be_able_to_perform_update#projects' - it_should_behave_like 'update collaborator relation' - 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' + it_should_behave_like 'projects user with writer rights' + it_should_behave_like 'projects user with reader rights' end end diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 6cb672d00..722a0c96c 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -#require 'shared_examples/repositories_controller' describe RepositoriesController do before(:each) do @@ -35,9 +34,6 @@ describe RepositoriesController do set_session_for(@admin) 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 get :new, :platform_id => @platform.id response.should render_template(:new) @@ -52,14 +48,7 @@ describe RepositoriesController do lambda { post :create, @create_params }.should change{ Repository.count }.by(1) end - it_should_behave_like 'be_able_to_perform_destroy#repositories' - 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' + it_should_behave_like 'repository user with admin rights' end 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') end - it_should_behave_like 'be_able_to_perform_index#repositories' - 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' + it_should_behave_like 'repository user with owner rights' end context 'for reader user' do @@ -111,8 +92,7 @@ describe RepositoriesController do @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end - it_should_behave_like 'be_able_to_perform_index#repositories' - it_should_behave_like 'be_able_to_perform_show#repositories' + it_should_behave_like 'repository user with reader rights' it 'should not be able to perform add_project action' do get :add_project, :id => @repository.id diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index fa34d7845..97362bb66 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -213,7 +213,7 @@ describe CanCan do end [: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) end end diff --git a/spec/support/shared_examples/groups_controller.rb b/spec/support/shared_examples/groups_controller.rb deleted file mode 100644 index e9b560ce1..000000000 --- a/spec/support/shared_examples/groups_controller.rb +++ /dev/null @@ -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 - - diff --git a/spec/support/shared_examples/personal_repositories_controller.rb b/spec/support/shared_examples/personal_repositories_controller.rb index 43b5e2d36..461370695 100644 --- a/spec/support/shared_examples/personal_repositories_controller.rb +++ b/spec/support/shared_examples/personal_repositories_controller.rb @@ -1,28 +1,7 @@ -shared_examples_for 'show personal repository' do - it 'should be able to perform show action' do - get :show, :id => @repository.id - response.should render_template(:show) - 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)) +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 @@ -32,29 +11,3 @@ shared_examples_for 'destroy personal repository' do response.should redirect_to(platform_path(@repository.platform.id)) 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 diff --git a/spec/support/shared_examples/platforms_controller.rb b/spec/support/shared_examples/platforms_controller.rb deleted file mode 100644 index ff5f793b8..000000000 --- a/spec/support/shared_examples/platforms_controller.rb +++ /dev/null @@ -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 diff --git a/spec/support/shared_examples/projects_controller.rb b/spec/support/shared_examples/projects_controller.rb index e2986c754..7aa4baa01 100644 --- a/spec/support/shared_examples/projects_controller.rb +++ b/spec/support/shared_examples/projects_controller.rb @@ -1,34 +1,32 @@ -shared_examples_for 'be_able_to_perform_index#projects' do - it 'should be able to perform index action' do - get :index - response.should render_template(:index) - end -end +shared_examples_for 'projects user with reader rights' do + it_should_behave_like 'user with rights to view projects' -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 post :fork, :id => @project.id response.should redirect_to(project_path(Project.last)) 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 get :build, :id => @project.id response.should render_template(:build) end -end -shared_examples_for 'be_able_to_perform_process_build#projects' do it 'should be able to perform process_build action' do post :process_build, {:id => @project.id}.merge(@process_build_params) response.should redirect_to(project_path(@project)) 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 diff --git a/spec/support/shared_examples/repositories_controller.rb b/spec/support/shared_examples/repositories_controller.rb index 2f6865ea3..a10590bf0 100644 --- a/spec/support/shared_examples/repositories_controller.rb +++ b/spec/support/shared_examples/repositories_controller.rb @@ -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 get :index response.should render_template(:index) end -end -shared_examples_for 'be_able_to_perform_show#repositories' do it 'should be able to perform show action' do get :show, :id => @repository.id response.should render_template(:show) 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 get :add_project, :id => @repository.id response.should render_template(:projects_list) 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 get :add_project, :id => @repository.id, :project_id => @project.id response.should redirect_to(repository_path(@repository)) 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 + + 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 'add_project_to_repository' do +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 get :add_project, :id => @repository.id, :project_id => @project.id @repository.projects.exists? :id => @project.id end end -shared_examples_for 'be_able_to_perform_remove_project#repositories' 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 +shared_examples_for 'repository user with remove project rights' do it 'should be able to remove project from repository' do get :remove_project, :id => @repository.id, :project_id => @project.id !@repository.projects.exists? :id => @project.id 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