abf/abf-ideas#83: added specs for Repository model

This commit is contained in:
Vokhmin Alexey V 2013-07-29 14:46:49 +04:00
parent 16fdad15a5
commit 6d2ca8eee4
2 changed files with 49 additions and 2 deletions

View File

@ -45,22 +45,31 @@ class Repository < ActiveRecord::Base
end end
end end
# Checks locking of sync
def sync_locked? def sync_locked?
sync_actions :check sync_actions :check
end end
# Uses for locking sync
# Calls from UI
def lock_sync def lock_sync
sync_actions :lock sync_actions :lock
end end
# Uses for unlocking sync
# Calls from UI
def unlock_sync def unlock_sync
sync_actions :unlock sync_actions :unlock
end end
# Uses for locking publishing
# Calls from API
def start_sync def start_sync
sync_actions :lock, '.repo.lock' sync_actions :lock, '.repo.lock'
end end
# Uses for unlocking publishing
# Calls from API
def stop_sync def stop_sync
sync_actions :unlock, '.repo.lock' sync_actions :unlock, '.repo.lock'
end end
@ -98,9 +107,9 @@ class Repository < ActiveRecord::Base
path = "#{platform.path}/repository/#{arch}/#{name}/#{lock_file}" path = "#{platform.path}/repository/#{arch}/#{name}/#{lock_file}"
case action case action
when :lock when :lock
result ||= system 'touch', path result ||= FileUtils.touch(path) rescue nil
when :unlock when :unlock
result ||= system 'rm', '-rf', path result ||= FileUtils.rm_f(path)
when :check when :check
return true if File.exist?(path) return true if File.exist?(path)
end end

View File

@ -30,6 +30,44 @@ describe Repository do
end 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 context 'when create with same owner that platform' do
before do before do
@platform = FactoryGirl.create(:platform) @platform = FactoryGirl.create(:platform)