[refs #2249] Add corrections to rspec controllers tests

This commit is contained in:
konstantin.grabar 2011-11-29 18:36:51 +04:00
parent bc504dfcf7
commit ff9bfa3f9d
11 changed files with 186 additions and 200 deletions

View File

@ -220,6 +220,7 @@ ActiveRecord::Schema.define(:version => 20111128140341) do
t.string "object_type" t.string "object_type"
t.integer "target_id" t.integer "target_id"
t.string "target_type" t.string "target_type"
t.integer "role_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "role" t.string "role"
@ -248,16 +249,16 @@ ActiveRecord::Schema.define(:version => 20111128140341) do
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "name" t.string "name"
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.string "remember_token" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.text "ssh_key"
t.string "uname" t.string "uname"
t.text "ssh_key"
t.integer "role_id"
t.string "role" t.string "role"
end end

View File

@ -12,7 +12,7 @@ module Modules
pl = platforms.build pl = platforms.build
pl.owner = self pl.owner = self
pl.name = "#{self.uname}_personal" pl.name = "#{self.uname}_personal"
pl.name = "#{self.uname}_personal" pl.description = "#{self.uname}_personal"
pl.platform_type = 'personal' pl.platform_type = 'personal'
pl.distrib_type = APP_CONFIG['distr_types'].first pl.distrib_type = APP_CONFIG['distr_types'].first
pl.visibility = 'hidden' pl.visibility = 'hidden'
@ -21,7 +21,7 @@ module Modules
rep = pl.repositories.build rep = pl.repositories.build
rep.owner = pl.owner rep.owner = pl.owner
rep.name = 'main' rep.name = 'main'
rep.name = 'main' rep.description = 'main'
rep.save! rep.save!
end end

View File

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'shared_examples/collaborators_controller'
describe CollaboratorsController do describe CollaboratorsController do
before(:each) do before(:each) do
@ -25,20 +26,9 @@ describe CollaboratorsController do
set_session_for(@admin) set_session_for(@admin)
end end
it 'should be able to perform index action' do it_should_behave_like 'be_able_to_perform_index_action'
get :index, :project_id => @project.id it_should_behave_like 'be_able_to_perform_update_action'
response.should redirect_to(edit_project_collaborators_path(@project)) it_should_behave_like 'update_collaborator_relation'
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 set flash notice on update success' do
post :update, {:project_id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
end
end end
context 'for admin user' do context 'for admin user' do
@ -50,20 +40,9 @@ describe CollaboratorsController do
r.save! r.save!
end end
it 'should be able to perform index action' do it_should_behave_like 'be_able_to_perform_index_action'
get :index, :project_id => @project.id it_should_behave_like 'be_able_to_perform_update_action'
response.should redirect_to(edit_project_collaborators_path(@project)) it_should_behave_like 'update_collaborator_relation'
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 set flash notice on update success' do
post :update, {:project_id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
end
end end
context 'for owner user' do context 'for owner user' do
@ -75,20 +54,9 @@ describe CollaboratorsController do
r.save! r.save!
end end
it 'should be able to perform index action' do it_should_behave_like 'be_able_to_perform_index_action'
get :index, :project_id => @project.id it_should_behave_like 'be_able_to_perform_update_action'
response.should redirect_to(edit_project_collaborators_path(@project)) it_should_behave_like 'update_collaborator_relation'
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 set flash notice on update success' do
post :update, {:project_id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
end
end end
context 'for reader user' do context 'for reader user' do
@ -100,15 +68,9 @@ describe CollaboratorsController do
r.save! r.save!
end end
it 'should not be able to perform index action' do it_should_behave_like 'not_be_able_to_perform_index_action'
get :index, :project_id => @project.id it_should_behave_like 'not_be_able_to_perform_update_action'
response.should redirect_to(edit_project_collaborators_path(@project)) it_should_behave_like 'not_update_collaborator_relation'
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
end end
context 'for writer user' do context 'for writer user' do
@ -120,14 +82,8 @@ describe CollaboratorsController do
r.save! r.save!
end end
it 'should not be able to perform index action' do it_should_behave_like 'not_be_able_to_perform_index_action'
get :index, :project_id => @project.id it_should_behave_like 'not_be_able_to_perform_update_action'
response.should redirect_to(edit_project_collaborators_path(@project)) it_should_behave_like 'not_update_collaborator_relation'
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
end end
end end

View File

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require "shared_examples/platforms_controller"
describe PlatformsController do describe PlatformsController do
before(:each) do before(:each) do
@ -7,7 +8,7 @@ describe PlatformsController do
@user = Factory(:user) @user = Factory(:user)
@create_params = {:platform => { @create_params = {:platform => {
:name => 'pl1', :name => 'pl1',
:unixname => 'pl1', :description => 'pl1',
:platform_type => 'main', :platform_type => 'main',
:distrib_type => APP_CONFIG['distr_types'].first :distrib_type => APP_CONFIG['distr_types'].first
}} }}
@ -40,10 +41,7 @@ describe PlatformsController do
set_session_for(@admin) set_session_for(@admin)
end end
it 'should be able to perform index action' do it_should_behave_like 'able_to_perform_index_action'
get :index
response.should render_template(:index)
end
it 'should be able to perform new action' do it 'should be able to perform new action' do
get :new get :new
@ -55,20 +53,13 @@ describe PlatformsController do
response.should redirect_to(platform_path(Platform.last)) response.should redirect_to(platform_path(Platform.last))
end end
it 'should set flash notice on create success' do it 'should change objects count on create success' do
post :create, @create_params lambda { post :create, @create_params }.should change{ Platform.count }.by(1)
flash[:notice].should_not be_blank
end end
it 'should be able to perform destroy action' do it_should_behave_like 'be_able_to_perform_destroy_action'
delete :destroy, :id => @platform.id it_should_behave_like 'change_objects_count_on_destroy_success'
response.should redirect_to(root_path) it_should_behave_like 'not_be_able_to_destroy_personal_platform'
end
it 'should not be able to destroy personal platform' do
delete :destroy, :id => @personal_platform.id
response.should redirect_to(forbidden_path)
end
end end
context 'for owner user' do context 'for owner user' do
@ -80,10 +71,11 @@ describe PlatformsController do
r.save! r.save!
end end
it 'should be able to perform index action' do it_should_behave_like 'able_to_perform_index_action'
get :index it_should_behave_like 'not_be_able_to_perform_create_action'
response.should render_template(:index) it_should_behave_like 'be_able_to_perform_destroy_action'
end 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
@ -95,20 +87,6 @@ describe PlatformsController do
response.should redirect_to(forbidden_path) response.should redirect_to(forbidden_path)
end end
it 'should set flash notice on create success' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
it 'should be able to perform destroy action' do
delete :destroy, :id => @platform.id
response.should redirect_to(root_path)
end
it 'should not be able to destroy personal platform' do
delete :destroy, :id => @personal_platform.id
response.should redirect_to(forbidden_path)
end
end end
context 'for reader user' do context 'for reader user' do
@ -119,20 +97,8 @@ describe PlatformsController do
r.save! r.save!
end end
it 'should be able to perform index action' do it_should_behave_like 'able_to_perform_index_action'
get :index it_should_behave_like 'not_be_able_to_perform_create_action'
response.should render_template(:index)
end
it 'should not be able to perform create action' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
it 'should set flash notice on create success' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
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,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'shared_examples/projects_controller'
describe ProjectsController do describe ProjectsController do
before(:each) do before(:each) do
@ -36,35 +37,20 @@ describe ProjectsController do
set_session_for(@admin) set_session_for(@admin)
end end
it 'should be able to perform index action' do it_should_behave_like 'be_able_to_perform_index_action'
get :index it_should_behave_like 'be_able_to_perform_update_action'
response.should render_template(:index) it_should_behave_like 'update_collaborator_relation'
end
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 set flash notice on update success' do
put :update, {:id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
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(project_path( Project.last.id )) response.should redirect_to(project_path( Project.last.id ))
end end
it 'should set flash notice on create success' do it 'should change objects count on create' do
post :create, @create_params lambda { post :create, @create_params }.should change{ Project.count }.by(1)
flash[:notice].should_not be_blank
end end
it 'should be able to fork project' do it_should_behave_like 'be_able_to_fork_project'
post :fork, :id => @project.id
response.should redirect_to(project_path(Project.last))
end
end end
context 'for owner user' do context 'for owner user' do
@ -76,31 +62,20 @@ describe ProjectsController do
r.save! r.save!
end end
it 'should be able to perform update action' do it_should_behave_like 'be_able_to_perform_update_action'
put :update, {:id => @project.id}.merge(@update_params) it_should_behave_like 'update_collaborator_relation'
response.should redirect_to(project_path(@project)) it_should_behave_like 'be_able_to_perform_build_action'
end it_should_behave_like 'be_able_to_perform_process_build_action'
it 'should set flash notice on update success' do
put :update, {:id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
end
it 'should be able to perform build action' do
get :build, :id => @project.id
response.should render_template(:build)
end
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
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}
response.should redirect_to(@project.owner) response.should redirect_to(@project.owner)
end end
it 'should change objects count on destroy' do
lambda { post :create, @create_params }.should change{ Project.count }.by(-1)
end
it 'should not be able to fork project' do it 'should not be able to fork project' do
post :fork, :id => @project.id post :fork, :id => @project.id
response.should redirect_to(forbidden_path) response.should redirect_to(forbidden_path)
@ -115,20 +90,14 @@ describe ProjectsController do
r.save! r.save!
end end
it 'should not be able to perform index action' do it_should_behave_like 'be_able_to_perform_index_action'
get :index
response.should render_template(:index)
end
it 'should not 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 be able to fork project' do it_should_behave_like 'be_able_to_fork_project'
post :fork, :id => @project.id
response.should redirect_to(project_path(Project.last))
end
end end
context 'for writer user' do context 'for writer user' do
@ -139,29 +108,10 @@ describe ProjectsController do
r.save! r.save!
end end
it 'should not be able to perform update action' do it_should_behave_like 'be_able_to_perform_update_action'
put :update, {:id => @project.id}.merge(@update_params) it_should_behave_like 'update_collaborator_relation'
response.should redirect_to(project_path(@project)) it_should_behave_like 'be_able_to_perform_build_action'
end it_should_behave_like 'be_able_to_perform_process_build_action'
it_should_behave_like 'be_able_to_fork_project'
it 'should set flash notice on update success' do
put :update, {:id => @project.id}.merge(@update_params)
flash[:notice].should_not be_blank
end
it 'shoud be able to perform build action' do
get :build, :id => @project.id
response.should render_template(:build)
end
it 'shoud 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
it 'should be able to fork project' do
post :fork, :id => @project.id
response.should redirect_to(project_path(Project.last))
end
end end
end end

View File

@ -1,6 +1,6 @@
Factory.define(:platform) do |p| Factory.define(:platform) do |p|
p.name { Factory.next(:string) } p.description { Factory.next(:string) }
p.unixname { Factory.next(:unixname) } p.name { Factory.next(:unixname) }
p.platform_type 'main' p.platform_type 'main'
p.distrib_type APP_CONFIG['distr_types'].first p.distrib_type APP_CONFIG['distr_types'].first
p.association :owner, :factory => :user p.association :owner, :factory => :user

View File

@ -1,5 +1,5 @@
Factory.define(:project) do |p| Factory.define(:project) do |p|
p.name { Factory.next(:string) } p.description { Factory.next(:string) }
p.unixname { Factory.next(:unixname) } p.name { Factory.next(:unixname) }
p.association :owner, :factory => :user p.association :owner, :factory => :user
end end

View File

@ -1,13 +1,13 @@
Factory.define(:repository) do |p| Factory.define(:repository) do |p|
p.name { Factory.next(:string) } p.description { Factory.next(:string) }
p.unixname { Factory.next(:unixname) } p.name { Factory.next(:unixname) }
p.association :platform, :factory => :platform p.association :platform, :factory => :platform
p.association :owner, :factory => :user p.association :owner, :factory => :user
end end
Factory.define(:personal_repository, :class => Repository) do |p| Factory.define(:personal_repository, :class => Repository) do |p|
p.name { Factory.next(:string) } p.description { Factory.next(:string) }
p.unixname { Factory.next(:unixname) } p.name { Factory.next(:unixname) }
p.association :platform, :factory => :platform p.association :platform, :factory => :platform
p.association :owner, :factory => :user p.association :owner, :factory => :user

View File

@ -0,0 +1,39 @@
shared_examples_for 'be_able_to_perform_index_action' 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 '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)
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_be_able_to_perform_index_action' 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_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)
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

View File

@ -0,0 +1,34 @@
shared_examples_for 'able_to_perform_index_action' 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_action' 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_action' 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

@ -0,0 +1,40 @@
shared_examples_for 'be_able_to_perform_index_action' 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_action' do
it 'should be able to perform update action' do
put :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 '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_action' do
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_action' 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