Merge pull request #22 from warpc/shared_examples_refactor

Fix sudo refactoring code. Refactoring tests(stub rsync calls, change shared examples)
This commit is contained in:
Vladimir Sharshov 2011-12-12 09:16:58 -08:00
commit 0d2351a3f7
15 changed files with 84 additions and 61 deletions

View File

@ -108,8 +108,8 @@ class Platform < ActiveRecord::Base
def mount_directory_for_rsync
#FileUtils.rm_rf "#{ Rails.root.join('tmp', 'umount', self.name) }" if File.exist? "#{ Rails.root.join('tmp', 'umount', name) }"
#FileUtils.mkdir_p "#{ Rails.root.join('tmp', 'mount', name) }"
system("sudo mkdir -p \"#{ Rails.root.join("public", "downloads") }/#{ name }\"")
system("sudo mount --bind \"/home/share/platforms/#{ name }\" \"#{ Rails.root.join("public", "downloads") }/#{ name }\"")
system("sudo mkdir -p #{ Rails.root.join("public", "downloads") }/#{ name }")
system("sudo mount --bind /home/share/platforms/#{ name } #{ Rails.root.join("public", "downloads") }/#{ name }")
#system("sudo cp -f /srv/rosa_build/current/tmp/mount/#{ name }/* /home/share/platforms/#{ name }/repository/")
#system("sudo rm -Rf \"/srv/rosa_build/current/tmp/mount/#{ name }\"")
Arch.all.each do |arch|
@ -121,8 +121,8 @@ class Platform < ActiveRecord::Base
end
def umount_directory_for_rsync
system("umount \"#{ Rails.root.join("public", "downloads") }/#{ name }\"")
system("rm -Rf \"#{ Rails.root.join("public", "downloads") }/#{ name }\"")
system("sudo umount #{ Rails.root.join("public", "downloads") }/#{ name }")
system("sudo rm -Rf #{ Rails.root.join("public", "downloads") }/#{ name }")
#system("rm -Rf \"/srv/rosa_build/current/tmp/umount/#{ name }\"")
#FileUtils.rm_rf "#{ Rails.root.join('tmp', 'mount', name) }" if File.exist? "#{ Rails.root.join('tmp', 'mount', name) }"
#FileUtils.mkdir_p "#{ Rails.root.join('tmp', 'umount', name) }"

View File

@ -26,9 +26,9 @@ describe CollaboratorsController do
set_session_for(@admin)
end
it_should_behave_like 'be_able_to_perform_index#collaborators'
it_should_behave_like 'be_able_to_perform_update#collaborators'
it_should_behave_like 'update_collaborator_relation'
it_should_behave_like 'show collaborators list'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end
context 'for admin user' do
@ -39,9 +39,9 @@ describe CollaboratorsController do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_index#collaborators'
it_should_behave_like 'be_able_to_perform_update#collaborators'
it_should_behave_like 'update_collaborator_relation'
it_should_behave_like 'show collaborators list'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end
context 'for owner user' do
@ -52,9 +52,9 @@ describe CollaboratorsController do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_index#collaborators'
it_should_behave_like 'be_able_to_perform_update#collaborators'
it_should_behave_like 'update_collaborator_relation'
it_should_behave_like 'show collaborators list'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end
context 'for reader user' do
@ -65,9 +65,9 @@ describe CollaboratorsController do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'not_be_able_to_perform_index#collaborators'
it_should_behave_like 'not_be_able_to_perform_update#collaborators'
it_should_behave_like 'not_update_collaborator_relation'
it_should_behave_like 'not show collaborators list'
it_should_behave_like 'not update collaborators'
it_should_behave_like 'not update collaborator relation'
end
context 'for writer user' do
@ -78,8 +78,8 @@ describe CollaboratorsController do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
end
it_should_behave_like 'not_be_able_to_perform_index#collaborators'
it_should_behave_like 'not_be_able_to_perform_update#collaborators'
it_should_behave_like 'not_update_collaborator_relation'
it_should_behave_like 'not show collaborators list'
it_should_behave_like 'not update collaborators'
it_should_behave_like 'not update collaborator relation'
end
end

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe PersonalRepositoriesController do
before(:each) do
stub_rsync_methods
@repository = Factory(:personal_repository)
@platform = Factory(:platform)
@project = Factory(:project)
@ -25,15 +27,14 @@ describe PersonalRepositoriesController do
set_session_for(@admin)
end
it_should_behave_like 'be_able_to_perform_show#personal_repositories'
it_should_behave_like 'be_able_to_perform_add_project#personal_repositories'
it_should_behave_like 'be_able_to_perform_add_project#personal_repositories_with_project_id_param'
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 'be_able_to_perform_remove_project#personal_repositories'
it_should_behave_like 'remove_project_from_repository'
it_should_behave_like 'be_able_to_perform_settings#personal_repositories'
it_should_behave_like 'be_able_to_perform_change_visibility'
it_should_behave_like 'be_able_to_change_visibility'
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
context 'for anyone except admin' do
@ -56,15 +57,14 @@ describe PersonalRepositoriesController do
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_settings#personal_repositories'
it_should_behave_like 'be_able_to_perform_change_visibility'
it_should_behave_like 'be_able_to_change_visibility'
it_should_behave_like 'be_able_to_perform_show#personal_repositories'
it_should_behave_like 'be_able_to_perform_add_project#personal_repositories'
it_should_behave_like 'be_able_to_perform_add_project#personal_repositories_with_project_id_param'
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 'be_able_to_perform_remove_project#personal_repositories'
it_should_behave_like 'remove_project_from_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
context 'for reader user' do
@ -74,7 +74,7 @@ describe PersonalRepositoriesController do
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_show#personal_repositories'
it_should_behave_like 'show personal repository'
it 'should not be able to perform add_project action' do
get :add_project, :id => @repository.id

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe PlatformsController do
before(:each) do
stub_rsync_methods
@platform = Factory(:platform)
@personal_platform = Factory(:platform, :platform_type => 'personal')
@user = Factory(:user)

View File

@ -1,6 +1,10 @@
require 'spec_helper'
describe ProductBuildListsController do
before(:each) do
stub_rsync_methods
end
context 'crud' do
def valid_attributes
{:product_id => product.id, :platform_id => product.platform_id}

View File

@ -2,6 +2,8 @@ require 'spec_helper'
describe ProductsController do
before(:each) do
stub_rsync_methods
@another_user = Factory(:user)
@platform = Factory(:platform)
@product = Factory(:product, :platform => @platform)

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe ProjectsController do
before(:each) do
stub_rsync_methods
@project = Factory(:project)
@another_user = Factory(:user)
@create_params = {:project => {:name => 'pro'}}
@ -40,7 +42,7 @@ describe ProjectsController do
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 'update collaborator relation'
it 'should be able to perform create action' do
post :create, @create_params
@ -63,7 +65,7 @@ describe ProjectsController do
end
it_should_behave_like 'be_able_to_perform_update#projects'
it_should_behave_like 'update_collaborator_relation'
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'
@ -107,7 +109,7 @@ describe ProjectsController do
end
it_should_behave_like 'be_able_to_perform_update#projects'
it_should_behave_like 'update_collaborator_relation'
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'

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe RepositoriesController do
before(:each) do
stub_rsync_methods
@repository = Factory(:repository)
@personal_repository = Factory(:personal_repository)
@platform = Factory(:platform)
@ -56,8 +58,8 @@ describe RepositoriesController do
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 'not_be_able_to_destroy_personal_repository'
it_should_behave_like 'remove project from repository'
it_should_behave_like 'destroy personal repository'
end
context 'for anyone except admin' do
@ -80,7 +82,7 @@ describe RepositoriesController do
lambda { post :create, @create_params }.should change{ Repository.count }.by(0)
end
it_should_behave_like 'not_be_able_to_destroy_personal_repository'
it_should_behave_like 'not destroy personal repository'
end
context 'for owner user' do
@ -97,7 +99,7 @@ describe RepositoriesController do
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 'remove project from repository'
it_should_behave_like 'be_able_to_perform_destroy#repositories'
it_should_behave_like 'change_repositories_count_after_destroy'
end

View File

@ -22,6 +22,10 @@ describe CanCan do
let(:open_platform) { Factory(:platform, :visibility => 'open') }
let(:hidden_platform) { Factory(:platform, :visibility => 'hidden') }
before(:each) do
stub_rsync_methods
end
context 'Site admin' do
before(:each) do
admin_create
@ -246,4 +250,4 @@ describe CanCan do
end
end
end

View File

@ -2,6 +2,7 @@ require 'spec_helper'
describe Platform do
before(:each) do
stub_rsync_methods
Platform.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path'])
end

View File

@ -4,6 +4,7 @@ describe Repository do
context 'when create with same owner that platform' do
before (:each) do
stub_rsync_methods
@platform = Factory(:platform)
@params = {:name => 'tst_platform', :description => 'test platform'}
end

View File

@ -32,7 +32,14 @@ def set_session_for(user=nil)
sign_in current_user
end
def stub_rsync_methods
any_instance_of(Platform, :mount_directory_for_rsync => true)
any_instance_of(Platform, :umount_directory_for_rsync => true)
end
# Add testing root_path
%x(rm -Rf #{Rails.root}/tmp/test_root)
%x(mkdir -p #{Rails.root}/tmp/test_root)
APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"

View File

@ -1,38 +1,38 @@
shared_examples_for 'be_able_to_perform_index#collaborators' do
shared_examples_for 'show collaborators list' do
it 'should be able to perform index action' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
end
end
shared_examples_for 'be_able_to_perform_update#collaborators' do
shared_examples_for 'update collaborators' do
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'update_collaborator_relation' do
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#collaborators' do
shared_examples_for 'not show collaborators list' do
it 'should be able to perform index action' do
get :index, :project_id => @project.id
response.should redirect_to(edit_project_collaborators_path(@project))
end
end
shared_examples_for 'not_be_able_to_perform_update#collaborators' do
shared_examples_for 'not update collaborators' do
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'not_update_collaborator_relation' do
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

View File

@ -1,60 +1,58 @@
shared_examples_for 'be_able_to_perform_show#personal_repositories' do
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 'be_able_to_perform_add_project#personal_repositories' do
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 'be_able_to_perform_add_project#personal_repositories_with_project_id_param' do
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 'be_able_to_perform_remove_project#personal_repositories' do
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
shared_examples_for 'be_able_to_perform_destroy#personal_repositories' do
shared_examples_for 'destroy personal repository' 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 'not_be_able_to_destroy_personal_repository' do
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 'be_able_to_perform_settings#personal_repositories' do
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 'be_able_to_perform_change_visibility' do
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
end
shared_examples_for 'be_able_to_change_visibility' do
it 'should change visibility of repository' do
get :change_visibility, :id => @repository.id
@repository.platform.reload.visibility.should == 'open'

View File

@ -40,7 +40,7 @@ shared_examples_for 'be_able_to_perform_remove_project#repositories' do
end
end
shared_examples_for 'remove_project_from_repository' do
shared_examples_for '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
!@repository.projects.exists? :id => @project.id