[refs #2249] Add corrections to rspec controllers tests
This commit is contained in:
parent
bc504dfcf7
commit
ff9bfa3f9d
11
db/schema.rb
11
db/schema.rb
|
@ -220,6 +220,7 @@ ActiveRecord::Schema.define(:version => 20111128140341) do
|
|||
t.string "object_type"
|
||||
t.integer "target_id"
|
||||
t.string "target_type"
|
||||
t.integer "role_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "role"
|
||||
|
@ -248,16 +249,16 @@ ActiveRecord::Schema.define(:version => 20111128140341) do
|
|||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.text "ssh_key"
|
||||
t.integer "role_id"
|
||||
t.string "role"
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Modules
|
|||
pl = platforms.build
|
||||
pl.owner = self
|
||||
pl.name = "#{self.uname}_personal"
|
||||
pl.name = "#{self.uname}_personal"
|
||||
pl.description = "#{self.uname}_personal"
|
||||
pl.platform_type = 'personal'
|
||||
pl.distrib_type = APP_CONFIG['distr_types'].first
|
||||
pl.visibility = 'hidden'
|
||||
|
@ -21,7 +21,7 @@ module Modules
|
|||
rep = pl.repositories.build
|
||||
rep.owner = pl.owner
|
||||
rep.name = 'main'
|
||||
rep.name = 'main'
|
||||
rep.description = 'main'
|
||||
rep.save!
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'shared_examples/collaborators_controller'
|
||||
|
||||
describe CollaboratorsController do
|
||||
before(:each) do
|
||||
|
@ -25,20 +26,9 @@ describe CollaboratorsController do
|
|||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
it_should_behave_like 'be_able_to_perform_index_action'
|
||||
it_should_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
end
|
||||
|
||||
context 'for admin user' do
|
||||
|
@ -50,20 +40,9 @@ describe CollaboratorsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
it_should_behave_like 'be_able_to_perform_index_action'
|
||||
it_should_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
end
|
||||
|
||||
context 'for owner user' do
|
||||
|
@ -75,20 +54,9 @@ describe CollaboratorsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
it_should_behave_like 'be_able_to_perform_index_action'
|
||||
it_should_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
end
|
||||
|
||||
context 'for reader user' do
|
||||
|
@ -100,15 +68,9 @@ describe CollaboratorsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should not be able to perform index action' 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_behave_like 'not_be_able_to_perform_index_action'
|
||||
it_should_behave_like 'not_be_able_to_perform_update_action'
|
||||
it_should_behave_like 'not_update_collaborator_relation'
|
||||
end
|
||||
|
||||
context 'for writer user' do
|
||||
|
@ -120,14 +82,8 @@ describe CollaboratorsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should not be able to perform index action' 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_behave_like 'not_be_able_to_perform_index_action'
|
||||
it_should_behave_like 'not_be_able_to_perform_update_action'
|
||||
it_should_behave_like 'not_update_collaborator_relation'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require "shared_examples/platforms_controller"
|
||||
|
||||
describe PlatformsController do
|
||||
before(:each) do
|
||||
|
@ -7,7 +8,7 @@ describe PlatformsController do
|
|||
@user = Factory(:user)
|
||||
@create_params = {:platform => {
|
||||
:name => 'pl1',
|
||||
:unixname => 'pl1',
|
||||
:description => 'pl1',
|
||||
:platform_type => 'main',
|
||||
:distrib_type => APP_CONFIG['distr_types'].first
|
||||
}}
|
||||
|
@ -40,10 +41,7 @@ describe PlatformsController do
|
|||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
it 'should be able to perform index action' do
|
||||
get :index
|
||||
response.should render_template(:index)
|
||||
end
|
||||
it_should_behave_like 'able_to_perform_index_action'
|
||||
|
||||
it 'should be able to perform new action' do
|
||||
get :new
|
||||
|
@ -55,20 +53,13 @@ describe PlatformsController do
|
|||
response.should redirect_to(platform_path(Platform.last))
|
||||
end
|
||||
|
||||
it 'should set flash notice on create success' do
|
||||
post :create, @create_params
|
||||
flash[:notice].should_not be_blank
|
||||
it 'should change objects count on create success' do
|
||||
lambda { post :create, @create_params }.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
|
||||
|
||||
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_behave_like 'be_able_to_perform_destroy_action'
|
||||
it_should_behave_like 'change_objects_count_on_destroy_success'
|
||||
it_should_behave_like 'not_be_able_to_destroy_personal_platform'
|
||||
end
|
||||
|
||||
context 'for owner user' do
|
||||
|
@ -80,10 +71,11 @@ describe PlatformsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should be able to perform index action' do
|
||||
get :index
|
||||
response.should render_template(:index)
|
||||
end
|
||||
it_should_behave_like 'able_to_perform_index_action'
|
||||
it_should_behave_like 'not_be_able_to_perform_create_action'
|
||||
it_should_behave_like 'be_able_to_perform_destroy_action'
|
||||
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
|
||||
get :new
|
||||
|
@ -95,20 +87,6 @@ describe PlatformsController do
|
|||
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 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
|
||||
|
||||
context 'for reader user' do
|
||||
|
@ -119,20 +97,8 @@ describe PlatformsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should be able to perform index action' do
|
||||
get :index
|
||||
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_behave_like 'able_to_perform_index_action'
|
||||
it_should_behave_like 'not_be_able_to_perform_create_action'
|
||||
|
||||
it 'should not be able to perform destroy action' do
|
||||
delete :destroy, :id => @platform.id
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'shared_examples/projects_controller'
|
||||
|
||||
describe ProjectsController do
|
||||
before(:each) do
|
||||
|
@ -36,35 +37,20 @@ describe ProjectsController do
|
|||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
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 => @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_behave_like 'be_able_to_perform_index_action'
|
||||
it_should_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
|
||||
it 'should be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(project_path( Project.last.id ))
|
||||
end
|
||||
|
||||
it 'should set flash notice on create success' do
|
||||
post :create, @create_params
|
||||
flash[:notice].should_not be_blank
|
||||
it 'should change objects count on create' do
|
||||
lambda { post :create, @create_params }.should change{ Project.count }.by(1)
|
||||
end
|
||||
|
||||
it 'should be able to fork project' do
|
||||
post :fork, :id => @project.id
|
||||
response.should redirect_to(project_path(Project.last))
|
||||
end
|
||||
it_should_behave_like 'be_able_to_fork_project'
|
||||
end
|
||||
|
||||
context 'for owner user' do
|
||||
|
@ -76,31 +62,20 @@ describe ProjectsController do
|
|||
r.save!
|
||||
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 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_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
it_should_behave_like 'be_able_to_perform_build_action'
|
||||
it_should_behave_like 'be_able_to_perform_process_build_action'
|
||||
|
||||
it 'should be able to perform destroy action' do
|
||||
delete :destroy, {:id => @project.id}
|
||||
response.should redirect_to(@project.owner)
|
||||
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
|
||||
post :fork, :id => @project.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
|
@ -115,20 +90,14 @@ describe ProjectsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should not be able to perform index action' do
|
||||
get :index
|
||||
response.should render_template(:index)
|
||||
end
|
||||
it_should_behave_like 'be_able_to_perform_index_action'
|
||||
|
||||
it 'should not be able to perform show action' do
|
||||
it 'should be able to perform show action' do
|
||||
get :show, :id => @project.id
|
||||
response.should render_template(:show)
|
||||
end
|
||||
|
||||
it 'should be able to fork project' do
|
||||
post :fork, :id => @project.id
|
||||
response.should redirect_to(project_path(Project.last))
|
||||
end
|
||||
it_should_behave_like 'be_able_to_fork_project'
|
||||
end
|
||||
|
||||
context 'for writer user' do
|
||||
|
@ -139,29 +108,10 @@ describe ProjectsController do
|
|||
r.save!
|
||||
end
|
||||
|
||||
it 'should not 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 '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
|
||||
it_should_behave_like 'be_able_to_perform_update_action'
|
||||
it_should_behave_like 'update_collaborator_relation'
|
||||
it_should_behave_like 'be_able_to_perform_build_action'
|
||||
it_should_behave_like 'be_able_to_perform_process_build_action'
|
||||
it_should_behave_like 'be_able_to_fork_project'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Factory.define(:platform) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
p.unixname { Factory.next(:unixname) }
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.platform_type 'main'
|
||||
p.distrib_type APP_CONFIG['distr_types'].first
|
||||
p.association :owner, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Factory.define(:project) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
p.unixname { Factory.next(:unixname) }
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.association :owner, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
Factory.define(:repository) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
p.unixname { Factory.next(:unixname) }
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.association :platform, :factory => :platform
|
||||
p.association :owner, :factory => :user
|
||||
end
|
||||
|
||||
Factory.define(:personal_repository, :class => Repository) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
p.unixname { Factory.next(:unixname) }
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.association :platform, :factory => :platform
|
||||
p.association :owner, :factory => :user
|
||||
|
||||
p.after_create { |rep|
|
||||
rep.platform.platform_type = 'personal'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue