Commit 4abecc72 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added specs for new methods in project_registry

parent 82d6d3ab
......@@ -168,14 +168,29 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
project.wiki_enabled? && (never_synced_wiki? || wiki_sync_needed?(scheduled_time))
end
# Returns whether repository is pending verification check
#
# This will check for missing verification checksum sha
#
# @return [Boolean] whether repository is pending verification
def repository_verification_pending?
self.repository_verification_checksum_sha.nil?
end
# Returns whether wiki is pending verification check
#
# This will check for missing verification checksum sha
#
# @return [Boolean] whether wiki is pending verification
def wiki_verification_pending?
self.wiki_verification_checksum_sha.nil?
end
# Returns wheter verification is pending for either wiki or repository
#
# This will check for missing verification checksum sha for both wiki and repository
#
# @return [Boolean] whether verification is pending for either wiki or repository
def verification_pending?
repository_verification_pending? || wiki_verification_pending?
end
......@@ -214,16 +229,22 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
end
# Flag the repository to be re-checked
#
# This operation happens only in the database and the recheck will be triggered after by the cron job
def flag_repository_for_recheck!
self.update(repository_verification_checksum_sha: nil, last_repository_verification_failure: nil, repository_checksum_mismatch: false)
end
# Flag the repository to be re-synced
#
# This operation happens only in the database and the resync will be triggered after by the cron job
def flag_repository_for_resync!
repository_updated!(:repository, Time.now)
end
# Flag the repository to perform a full re-download
#
# This operation happens only in the database and the forced re-download will be triggered after by the cron job
def flag_repository_for_redownload!
self.update(resync_repository: true, force_to_redownload_repository: true)
end
......@@ -235,7 +256,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
#
# @return [Boolean] whether the registry is candidate for a re-download
def candidate_for_redownload?
self.repository_retry_count && self.repository_retry_count >= 1
self.repository_retry_count && self.repository_retry_count > 1
end
private
......
......@@ -762,4 +762,117 @@ describe Geo::ProjectRegistry do
end
end
end
describe '#repository_verification_pending?' do
it 'returns true when outdated' do
registry = create(:geo_project_registry, :repository_verification_outdated)
expect(registry.repository_verification_pending?).to be_truthy
end
it 'returns true when we are missing checksum sha' do
registry = create(:geo_project_registry, :repository_verification_failed)
expect(registry.repository_verification_pending?).to be_truthy
end
it 'returns false when checksum is present' do
registry = create(:geo_project_registry, :repository_verified)
expect(registry.repository_verification_pending?).to be_falsey
end
end
describe '#wiki_verification_pending?' do
it 'returns true when outdated' do
registry = create(:geo_project_registry, :wiki_verification_outdated)
expect(registry.wiki_verification_pending?).to be_truthy
end
it 'returns true when we are missing checksum sha' do
registry = create(:geo_project_registry, :wiki_verification_failed)
expect(registry.wiki_verification_pending?).to be_truthy
end
it 'returns false when checksum is present' do
registry = create(:geo_project_registry, :wiki_verified)
expect(registry.wiki_verification_pending?).to be_falsey
end
end
describe 'verification_pending?' do
it 'returns true when either wiki or repository verification is pending' do
repo_registry = create(:geo_project_registry, :repository_verification_outdated)
wiki_registry = create(:geo_project_registry, :wiki_verification_failed)
expect(repo_registry.verification_pending?).to be_truthy
expect(wiki_registry.verification_pending?).to be_truthy
end
it 'returns false when both wiki and repository verification is present' do
registry = create(:geo_project_registry, :repository_verified, :wiki_verified)
expect(registry.verification_pending?).to be_falsey
end
end
describe '#flag_repository_for_recheck!' do
it 'modified record to a recheck state' do
registry = create(:geo_project_registry, :repository_verified)
registry.flag_repository_for_recheck!
expect(registry).to have_attributes(
repository_verification_checksum_sha: nil,
last_repository_verification_failure: nil,
repository_checksum_mismatch: false
)
end
end
describe '#flag_repository_for_resync!' do
it 'modified record to a resync state' do
registry = create(:geo_project_registry, :synced)
registry.flag_repository_for_resync!
expect(registry).to have_attributes(
resync_repository: true,
repository_verification_checksum_sha: nil,
last_repository_verification_failure: nil,
repository_checksum_mismatch: false,
repository_verification_retry_count: nil,
repository_retry_count: nil,
repository_retry_at: nil
)
end
end
describe '#flag_repository_for_redownload!' do
it 'modified record to a recheck state' do
registry = create(:geo_project_registry, :repository_verified)
registry.flag_repository_for_redownload!
expect(registry).to have_attributes(
resync_repository: true,
force_to_redownload_repository: true
)
end
end
describe '#candidate_for_redownload?' do
it 'returns false when repository_retry_count is 1 or less' do
registry = create(:geo_project_registry, :sync_failed)
expect(registry.candidate_for_redownload?).to be_falsey
end
it 'returns true when repository_retry_count is > 1' do
registry = create(:geo_project_registry, :sync_failed, repository_retry_count: 2)
expect(registry.candidate_for_redownload?).to be_truthy
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment