Delegates the update of the Geo node to Geo::NodeUpdateService

parent 4007551e
......@@ -108,6 +108,10 @@ class GeoNode < ActiveRecord::Base
end
end
def namespaces_changed?
namespaces.any? { |n| n.new_record? || n.marked_for_destruction? }
end
def project_ids
return unless namespaces.presence
......
module Geo
class NodeUpdateService
attr_reader :geo_node, :old_namespace_ids, :params
def initialize(geo_node, params)
@geo_node = geo_node
@old_namespace_ids = geo_node.namespace_ids
@params = params.except(:geo_node_key_attributes)
end
def execute
return false unless geo_node.update(params)
if namespaces_changed?(geo_node)
Geo::RepositoriesChangedEventStore.new(geo_node).create
end
geo_node
end
private
def namespaces_changed?(geo_node)
geo_node.namespace_ids.any? && geo_node.namespace_ids != old_namespace_ids
end
end
end
......@@ -25,7 +25,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
end
def update
if @node.update_attributes(geo_node_params.except(:geo_node_key_attributes))
if Geo::NodeUpdateService.new(@node, geo_node_params).execute
redirect_to admin_geo_nodes_path, notice: 'Geo Node was successfully updated.'
else
render 'edit'
......
......@@ -132,15 +132,21 @@ describe Admin::GeoNodesController, :postgresql do
context 'with add-on license' do
before do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(true)
go
end
it 'updates the node without changing the key' do
geo_node.reload
go
geo_node.reload
expect(geo_node.url.chomp('/')).to eq(geo_node_attributes[:url])
expect(geo_node.geo_node_key.fingerprint).to eq(original_fingerprint)
end
it 'delegates the update of the Geo node to Geo::NodeUpdateService' do
expect_any_instance_of(Geo::NodeUpdateService).to receive(:execute).once
go
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