Does not return dirty projects on Geo::ProjectRegistry.synced

parent 8593cf86
......@@ -5,5 +5,9 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) }
scope :failed, -> { where.not(last_repository_synced_at: nil).where(last_repository_successful_sync_at: nil) }
scope :synced, -> { where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil) }
def self.synced
where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil)
.where(resync_repository: false, resync_wiki: false)
end
end
......@@ -8,4 +8,51 @@ describe Geo::ProjectRegistry, models: true do
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
end
describe '.synced' do
let(:project) { create(:empty_project) }
let(:synced_at) { Time.now }
it 'does not return dirty projects' do
Geo::ProjectRegistry.create(
project: project,
last_repository_synced_at: synced_at,
last_repository_successful_sync_at: synced_at,
last_wiki_synced_at: synced_at,
last_wiki_successful_sync_at: synced_at,
resync_repository: true,
resync_wiki: true
)
expect(described_class.synced).to be_empty
end
it 'does not return projects where last attempt to sync failed' do
Geo::ProjectRegistry.create(
project: project,
last_repository_synced_at: synced_at,
last_repository_successful_sync_at: nil,
last_wiki_synced_at: synced_at,
last_wiki_successful_sync_at: nil,
resync_repository: true,
resync_wiki: true
)
expect(described_class.synced).to be_empty
end
it 'returns synced projects' do
registry = Geo::ProjectRegistry.create(
project: project,
last_repository_synced_at: synced_at,
last_repository_successful_sync_at: synced_at,
last_wiki_synced_at: synced_at,
last_wiki_successful_sync_at: synced_at,
resync_repository: false,
resync_wiki: false
)
expect(described_class.synced).to match_array([registry])
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