From 7528b057159310ff162f2fcd34242bd4febf6301 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 13 Dec 2012 23:14:18 +0400 Subject: [PATCH] #778: some refactoring, fix specs --- app/models/platform.rb | 13 ++++--------- app/models/repository.rb | 4 ++-- lib/abf_worker/runners/base.rb | 2 +- lib/abf_worker/runners/platform.rb | 2 +- lib/abf_worker/runners/repository.rb | 6 +++--- spec/models/platform_spec.rb | 4 ++-- spec/models/repository_spec.rb | 4 ++-- spec/spec_helper.rb | 14 +++++++++++--- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index 9edefd617..e8b055138 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -30,9 +30,8 @@ class Platform < ActiveRecord::Base end } - before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready - before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} - before_destroy :xml_rpc_destroy + after_create :create_directory + before_destroy :destroy_directory after_update :freeze_platform_and_update_repos after_update :update_owner_relation @@ -157,10 +156,6 @@ class Platform < ActiveRecord::Base end end - def create_directory - system("sudo mkdir -p -m 0777 #{path}") - end - def symlink_directory # umount_directory_for_rsync # TODO ignore errors system("ln -s #{path} #{symlink_path}") @@ -196,13 +191,13 @@ class Platform < ActiveRecord::Base File.join(APP_CONFIG['root_path'], 'platforms', dir) end - def xml_rpc_create + def create_directory Resque.enqueue(AbfWorker::FileSystemWorker, {:id => id, :action => 'create', :type => 'platform'}) return true end - def xml_rpc_destroy + def destroy_directory Resque.enqueue(AbfWorker::FileSystemWorker, {:id => id, :action => 'destroy', :type => 'platform'}) return true diff --git a/app/models/repository.rb b/app/models/repository.rb index 16409a900..ceafea800 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -17,7 +17,7 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} - before_destroy :xml_rpc_destroy, :unless => lambda {Thread.current[:skip]} + before_destroy :destroy_directory attr_accessible :name, :description, :publish_without_qa attr_readonly :name, :platform_id @@ -71,7 +71,7 @@ class Repository < ActiveRecord::Base end end - def xml_rpc_destroy + def destroy_directory Resque.enqueue(AbfWorker::FileSystemWorker, {:id => id, :action => 'destroy', :type => 'repository'}) return true diff --git a/lib/abf_worker/runners/base.rb b/lib/abf_worker/runners/base.rb index 2c8ecadab..08841b30c 100644 --- a/lib/abf_worker/runners/base.rb +++ b/lib/abf_worker/runners/base.rb @@ -11,7 +11,7 @@ module AbfWorker send @action end - def self.mk_dir(path) + def mk_dir(path) Dir.mkdir(path) unless File.exists?(path) end diff --git a/lib/abf_worker/runners/platform.rb b/lib/abf_worker/runners/platform.rb index 6abea46bc..2b024c8d2 100644 --- a/lib/abf_worker/runners/platform.rb +++ b/lib/abf_worker/runners/platform.rb @@ -5,7 +5,7 @@ module AbfWorker # @param [String] id The id of platform def initialize(id, action) super action - @platform = Platform.find id + @platform = ::Platform.find id end protected diff --git a/lib/abf_worker/runners/repository.rb b/lib/abf_worker/runners/repository.rb index b3a45094c..feb0abc45 100644 --- a/lib/abf_worker/runners/repository.rb +++ b/lib/abf_worker/runners/repository.rb @@ -5,7 +5,7 @@ module AbfWorker # @param [String] id The id of repository def initialize(id, action) super action - @repository = Repository.find id + @repository = ::Repository.find id end protected @@ -15,7 +15,7 @@ module AbfWorker repository_path = platform.path repository_path << '/repository' if platform.personal? - Platform.main.pluck(:name).each do |main_platform_name| + ::Platform.main.pluck(:name).each do |main_platform_name| destroy_repositories "#{repository_path}/#{main_platform_name}" end else @@ -24,7 +24,7 @@ module AbfWorker end def destroy_repositories(repository_path) - Arch.pluck(:name).each do |arch| + ::Arch.pluck(:name).each do |arch| system("rm -rf #{repository_path}/#{arch}/#{@repository.name}") end system("rm -rf #{repository_path}/SRPMS/#{@repository.name}") diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index c0f9499f5..20b1c9d2e 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -6,7 +6,7 @@ describe Platform do stub_symlink_methods Platform.delete_all User.delete_all - FileUtils.rm_rf(APP_CONFIG['root_path']) + init_test_root # Need for validate_uniqueness_of check FactoryGirl.create(:platform) end @@ -44,6 +44,6 @@ describe Platform do after(:all) do Platform.delete_all User.delete_all - FileUtils.rm_rf(APP_CONFIG['root_path']) + clear_test_root end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 13fef0847..b878dbcfb 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -21,7 +21,7 @@ describe Repository do Platform.delete_all User.delete_all Repository.delete_all - FileUtils.rm_rf(APP_CONFIG['root_path']) + init_test_root # Need for validate_uniqueness_of check FactoryGirl.create(:repository) end @@ -48,7 +48,7 @@ describe Repository do Platform.delete_all User.delete_all Repository.delete_all - FileUtils.rm_rf(APP_CONFIG['root_path']) + clear_test_root end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e168084b3..3c7c507f7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -59,7 +59,15 @@ end Resque.inline = true -# Add testing root_path -%x(rm -Rf #{Rails.root}/tmp/test_root) -%x(mkdir -p #{Rails.root}/tmp/test_root) +def init_test_root + clear_test_root + %x(mkdir -p #{Rails.root}/tmp/test_root) + %x(mkdir -p #{Rails.root}/tmp/test_root/platforms) +end + +def clear_test_root + %x(rm -Rf #{Rails.root}/tmp/test_root) +end + +init_test_root APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"