Commit b3dfc1da authored by Toon Claes's avatar Toon Claes Committed by Stan Hu

Changes cause success has a non-NULL constraint

`success` column cannot be NULL, so we need to adapt the code to
define what "never" synced means.
parent 9536d26e
......@@ -5,7 +5,8 @@ class Geo::FileRegistry < Geo::BaseRegistry
scope :lfs_objects, -> { where(file_type: :lfs) }
scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) }
scope :never, -> { where(retry_count: nil) }
scope :failed, -> { where(success: false).where.not(retry_count: nil) }
scope :never, -> { where(success: false, retry_count: nil) }
scope :fresh, -> { order(created_at: :desc) }
self.inheritance_column = 'file_type'
......@@ -20,14 +21,10 @@ class Geo::FileRegistry < Geo::BaseRegistry
def self.with_status(status)
case status
when 'synced'
synced
when 'never'
never
when 'failed'
failed
when 'synced', 'never', 'failed'
self.public_send(status) # rubocop: disable GitlabSecurity/PublicSend
else
self
all
end
end
......@@ -36,10 +33,10 @@ class Geo::FileRegistry < Geo::BaseRegistry
# It takes into account things like if a successful replication has been done
# if there are pending actions or existing errors
#
# @return [Symbol] :never, :failed:, :pending or :synced
# @return [Symbol] :synced, :never, or :failed
def synchronization_state
return :synced if success?
return :never if success.nil? && retry_count.nil?
return :never if retry_count.nil?
:failed
end
......
require 'spec_helper'
describe Geo::FileRegistry do
set(:failed) { create(:geo_file_registry, success: false) }
set(:synced) { create(:geo_file_registry, success: true) }
set(:failed) { create(:geo_file_registry, :failed) }
set(:synced) { create(:geo_file_registry) }
describe '.failed' do
it 'returns registries in the failed state' do
......@@ -27,10 +27,9 @@ describe Geo::FileRegistry do
describe '.never' do
it 'returns registries that are never synced' do
create(:geo_file_registry, retry_count: 1, success: true)
create(:geo_file_registry, retry_count: 2, success: false)
never = create(:geo_file_registry, retry_count: nil, success: false)
expect(described_class.never).to match_ids([failed, synced])
expect(described_class.never).to match_ids([never])
end
end
......@@ -59,7 +58,7 @@ describe Geo::FileRegistry do
end
it 'returns :never for a successful registry never synced' do
never = build(:geo_file_registry, success: nil)
never = build(:geo_file_registry, success: false, retry_count: nil)
expect(never.synchronization_state).to eq(:never)
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