#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
}
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}")

View File

@ -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

View File

@ -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

View File

@ -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"