Commit 322d6ead authored by Gabriel Mazetto's avatar Gabriel Mazetto

Avoid locking yourself out when adding a GeoNode

parent 579370be
......@@ -72,4 +72,13 @@ class GeoNode < ActiveRecord::Base
def change_geo_node_key_title
self.geo_node_key.title = "Geo node: #{self.url}" if self.geo_node_key
end
def validate(record)
# Prevent locking yourself out
if record.host == Gitlab.config.gitlab.host &&
record.port == Gitlab.config.gitlab.port &&
record.relative_url_root == Gitlab.config.gitlab.relative_url_root && !record.primary
record.errors[:base] << 'Current node must be the primary node or you will be locking yourself out'
end
end
end
......@@ -32,6 +32,16 @@ describe GeoNode, type: :model do
end
end
context 'prevent locking yourself out' do
subject { GeoNode.new(host: Gitlab.config.gitlab.host,
port: Gitlab.config.gitlab.port,
relative_url_root: Gitlab.config.gitlab.relative_url_root) }
it 'does not accept adding a non primary node with same details as current_node' do
expect(subject).not_to be_valid
end
end
describe '#uri' do
context 'when all fields are filled' do
subject { GeoNode.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab') }
......
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