Does not count synced files that were replaced on attachments status

parent 233f4fb9
......@@ -69,7 +69,12 @@ class GeoNodeStatus
end
def attachments_synced_count
@attachments_synced_count ||= Geo::FileRegistry.where(file_type: [:attachment, :avatar, :file]).count
@attachments_synced_count ||= begin
upload_ids = Upload.pluck(:id)
synced_ids = Geo::FileRegistry.where(file_type: [:attachment, :avatar, :file]).pluck(:file_id)
(synced_ids & upload_ids).length
end
end
def attachments_synced_count=(value)
......
......@@ -31,6 +31,20 @@ describe GeoNodeStatus, model: true do
end
end
describe '#attachments_synced_count' do
it 'does not count synced files that were replaced' do
user = create(:user, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png'))
upload = Upload.find_by(model: user, uploader: 'AvatarUploader')
Geo::FileRegistry.create(file_type: :avatar, file_id: upload.id)
user.update(avatar: fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg'))
upload = Upload.find_by(model: user, uploader: 'AvatarUploader')
Geo::FileRegistry.create(file_type: :avatar, file_id: upload.id)
expect(subject.attachments_synced_count).to eq(1)
end
end
describe '#attachments_synced_in_percentage' do
it 'returns 0 when no objects are available' do
subject.attachments_count = 0
......
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