Commit cad600ad authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Michael Kozono

Geo - Create repository updated events only if the repository exists

parent 2ff3c889
......@@ -9,11 +9,12 @@ module Geo
RepositoryUpdateError = Class.new(StandardError)
def initialize(repository, params = {})
@project = repository.project
@params = params
@refs = params.fetch(:refs, [])
@changes = params.fetch(:changes, [])
@source = Geo::RepositoryUpdatedEvent.source_for(repository)
@project = repository.project
@repository = repository
@params = params
@refs = params.fetch(:refs, [])
@changes = params.fetch(:changes, [])
@source = Geo::RepositoryUpdatedEvent.source_for(repository)
end
def execute
......@@ -27,11 +28,13 @@ module Geo
private
attr_reader :project, :refs, :changes, :source
attr_reader :project, :repository, :refs, :changes, :source
delegate :repository_state, to: :project
def create_repository_updated_event!
return unless repository.exists?
Geo::RepositoryUpdatedEventStore.new(
project, refs: refs, changes: changes, source: source
).create!
......
---
title: Geo - Create repository updated events only if the repository exists
merge_request: 42519
author:
type: fixed
......@@ -37,10 +37,18 @@ RSpec.describe Geo::RepositoryUpdatedService do
end
context 'when running on a primary node' do
it 'creates a repository updated event' do
it 'creates a repository updated event when repository exists' do
allow(repository).to receive(:exists?).and_return(true)
expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end
it 'does not create a repository updated event when repository does not exist' do
allow(repository).to receive(:exists?).and_return(false)
expect { subject.execute }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
it 'resets the repository verification checksum' do
expect { subject.execute }.to change { repository_state.reload.public_send("#{method_prefix}_verification_checksum") }.to(nil)
end
......@@ -91,9 +99,17 @@ RSpec.describe Geo::RepositoryUpdatedService do
context 'when design repository is being updated' do
let(:repository) { project.design_repository }
it 'creates a design repository updated event' do
it 'creates a design repository updated event when repository exists' do
allow(repository).to receive(:exists?).and_return(true)
expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end
it 'does not create a repository updated event when repository does not exist' do
allow(repository).to receive(:exists?).and_return(false)
expect { subject.execute }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
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