abf/abf-ideas#83: added specs for Repository model
This commit is contained in:
parent
16fdad15a5
commit
6d2ca8eee4
|
@ -45,22 +45,31 @@ class Repository < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Checks locking of sync
|
||||
def sync_locked?
|
||||
sync_actions :check
|
||||
end
|
||||
|
||||
# Uses for locking sync
|
||||
# Calls from UI
|
||||
def lock_sync
|
||||
sync_actions :lock
|
||||
end
|
||||
|
||||
# Uses for unlocking sync
|
||||
# Calls from UI
|
||||
def unlock_sync
|
||||
sync_actions :unlock
|
||||
end
|
||||
|
||||
# Uses for locking publishing
|
||||
# Calls from API
|
||||
def start_sync
|
||||
sync_actions :lock, '.repo.lock'
|
||||
end
|
||||
|
||||
# Uses for unlocking publishing
|
||||
# Calls from API
|
||||
def stop_sync
|
||||
sync_actions :unlock, '.repo.lock'
|
||||
end
|
||||
|
@ -98,9 +107,9 @@ class Repository < ActiveRecord::Base
|
|||
path = "#{platform.path}/repository/#{arch}/#{name}/#{lock_file}"
|
||||
case action
|
||||
when :lock
|
||||
result ||= system 'touch', path
|
||||
result ||= FileUtils.touch(path) rescue nil
|
||||
when :unlock
|
||||
result ||= system 'rm', '-rf', path
|
||||
result ||= FileUtils.rm_f(path)
|
||||
when :check
|
||||
return true if File.exist?(path)
|
||||
end
|
||||
|
|
|
@ -30,6 +30,44 @@ describe Repository do
|
|||
|
||||
end
|
||||
|
||||
context '#sync_locked?, #lock_sync, #unlock_sync, #start_sync, #stop_sync' do
|
||||
let(:repository) { FactoryGirl.create(:repository) }
|
||||
let(:path) { "#{repository.platform.path}/repository/SRPMS/#{repository.name}" }
|
||||
before { FileUtils.mkdir_p path }
|
||||
|
||||
it 'ensures that #sync_locked? returns false if .sync.lock file does not exist' do
|
||||
repository.sync_locked?.should be_false
|
||||
end
|
||||
|
||||
it 'ensures that #sync_locked? returns true if .sync.lock file does exist' do
|
||||
FileUtils.touch "#{path}/.sync.lock"
|
||||
repository.sync_locked?.should be_true
|
||||
end
|
||||
|
||||
it 'ensures that #lock_sync creates .sync.lock file' do
|
||||
repository.lock_sync
|
||||
File.exist?("#{path}/.sync.lock").should be_true
|
||||
end
|
||||
|
||||
it 'ensures that #unlock_sync removes .sync.lock file' do
|
||||
FileUtils.touch "#{path}/.sync.lock"
|
||||
repository.unlock_sync
|
||||
File.exist?("#{path}/.sync.lock").should be_false
|
||||
end
|
||||
|
||||
it 'ensures that #start_sync creates .repo.lock file' do
|
||||
repository.start_sync
|
||||
File.exist?("#{path}/.repo.lock").should be_true
|
||||
end
|
||||
|
||||
it 'ensures that #stop_sync removes .repo.lock file' do
|
||||
FileUtils.touch "#{path}/.repo.lock"
|
||||
repository.stop_sync
|
||||
File.exist?("#{path}/.repo.lock").should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'when create with same owner that platform' do
|
||||
before do
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
|
|
Loading…
Reference in New Issue