#778: some refactoring, fix specs

This commit is contained in:
Vokhmin Alexey V 2012-12-13 23:14:18 +04:00
parent 07d0ed89b4
commit 7528b05715
8 changed files with 26 additions and 23 deletions

View File

@ -30,9 +30,8 @@ class Platform < ActiveRecord::Base
end end
} }
before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready after_create :create_directory
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :destroy_directory
before_destroy :xml_rpc_destroy
after_update :freeze_platform_and_update_repos after_update :freeze_platform_and_update_repos
after_update :update_owner_relation after_update :update_owner_relation
@ -157,10 +156,6 @@ class Platform < ActiveRecord::Base
end end
end end
def create_directory
system("sudo mkdir -p -m 0777 #{path}")
end
def symlink_directory def symlink_directory
# umount_directory_for_rsync # TODO ignore errors # umount_directory_for_rsync # TODO ignore errors
system("ln -s #{path} #{symlink_path}") system("ln -s #{path} #{symlink_path}")
@ -196,13 +191,13 @@ class Platform < ActiveRecord::Base
File.join(APP_CONFIG['root_path'], 'platforms', dir) File.join(APP_CONFIG['root_path'], 'platforms', dir)
end end
def xml_rpc_create def create_directory
Resque.enqueue(AbfWorker::FileSystemWorker, Resque.enqueue(AbfWorker::FileSystemWorker,
{:id => id, :action => 'create', :type => 'platform'}) {:id => id, :action => 'create', :type => 'platform'})
return true return true
end end
def xml_rpc_destroy def destroy_directory
Resque.enqueue(AbfWorker::FileSystemWorker, Resque.enqueue(AbfWorker::FileSystemWorker,
{:id => id, :action => 'destroy', :type => 'platform'}) {:id => id, :action => 'destroy', :type => 'platform'})
return true return true

View File

@ -17,7 +17,7 @@ class Repository < ActiveRecord::Base
scope :recent, order("name ASC") scope :recent, order("name ASC")
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} 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_accessible :name, :description, :publish_without_qa
attr_readonly :name, :platform_id attr_readonly :name, :platform_id
@ -71,7 +71,7 @@ class Repository < ActiveRecord::Base
end end
end end
def xml_rpc_destroy def destroy_directory
Resque.enqueue(AbfWorker::FileSystemWorker, Resque.enqueue(AbfWorker::FileSystemWorker,
{:id => id, :action => 'destroy', :type => 'repository'}) {:id => id, :action => 'destroy', :type => 'repository'})
return true return true

View File

@ -11,7 +11,7 @@ module AbfWorker
send @action send @action
end end
def self.mk_dir(path) def mk_dir(path)
Dir.mkdir(path) unless File.exists?(path) Dir.mkdir(path) unless File.exists?(path)
end end

View File

@ -5,7 +5,7 @@ module AbfWorker
# @param [String] id The id of platform # @param [String] id The id of platform
def initialize(id, action) def initialize(id, action)
super action super action
@platform = Platform.find id @platform = ::Platform.find id
end end
protected protected

View File

@ -5,7 +5,7 @@ module AbfWorker
# @param [String] id The id of repository # @param [String] id The id of repository
def initialize(id, action) def initialize(id, action)
super action super action
@repository = Repository.find id @repository = ::Repository.find id
end end
protected protected
@ -15,7 +15,7 @@ module AbfWorker
repository_path = platform.path repository_path = platform.path
repository_path << '/repository' repository_path << '/repository'
if platform.personal? 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}" destroy_repositories "#{repository_path}/#{main_platform_name}"
end end
else else
@ -24,7 +24,7 @@ module AbfWorker
end end
def destroy_repositories(repository_path) 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}") system("rm -rf #{repository_path}/#{arch}/#{@repository.name}")
end end
system("rm -rf #{repository_path}/SRPMS/#{@repository.name}") system("rm -rf #{repository_path}/SRPMS/#{@repository.name}")

View File

@ -6,7 +6,7 @@ describe Platform do
stub_symlink_methods stub_symlink_methods
Platform.delete_all Platform.delete_all
User.delete_all User.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) init_test_root
# Need for validate_uniqueness_of check # Need for validate_uniqueness_of check
FactoryGirl.create(:platform) FactoryGirl.create(:platform)
end end
@ -44,6 +44,6 @@ describe Platform do
after(:all) do after(:all) do
Platform.delete_all Platform.delete_all
User.delete_all User.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) clear_test_root
end end
end end

View File

@ -21,7 +21,7 @@ describe Repository do
Platform.delete_all Platform.delete_all
User.delete_all User.delete_all
Repository.delete_all Repository.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) init_test_root
# Need for validate_uniqueness_of check # Need for validate_uniqueness_of check
FactoryGirl.create(:repository) FactoryGirl.create(:repository)
end end
@ -48,7 +48,7 @@ describe Repository do
Platform.delete_all Platform.delete_all
User.delete_all User.delete_all
Repository.delete_all Repository.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) clear_test_root
end end
end end

View File

@ -59,7 +59,15 @@ end
Resque.inline = true Resque.inline = true
# Add testing root_path def init_test_root
%x(rm -Rf #{Rails.root}/tmp/test_root) clear_test_root
%x(mkdir -p #{Rails.root}/tmp/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" APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"