Commit 52a42336 authored by Toon Claes's avatar Toon Claes

Add validation to ensure Primary is not disabled

parent 466707d5
...@@ -21,6 +21,7 @@ class GeoNode < ActiveRecord::Base ...@@ -21,6 +21,7 @@ class GeoNode < ActiveRecord::Base
validate :check_url_is_valid validate :check_url_is_valid
validates :primary, uniqueness: { message: 'node already exists' }, if: :primary validates :primary, uniqueness: { message: 'node already exists' }, if: :primary
validates :enabled, if: :primary, acceptance: { message: 'Geo primary node cannot be disabled' }
validates :access_key, presence: true validates :access_key, presence: true
validates :encrypted_secret_access_key, presence: true validates :encrypted_secret_access_key, presence: true
......
...@@ -13,8 +13,7 @@ describe Gitlab::Geo::JwtRequestDecoder do ...@@ -13,8 +13,7 @@ describe Gitlab::Geo::JwtRequestDecoder do
end end
it 'fails to decode when node is disabled' do it 'fails to decode when node is disabled' do
primary_node.enabled = false primary_node.update_attribute(:enabled, false)
primary_node.save
expect(subject.decode).to be_nil expect(subject.decode).to be_nil
end end
......
...@@ -27,6 +27,15 @@ describe GeoNode, type: :model do ...@@ -27,6 +27,15 @@ describe GeoNode, type: :model do
it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:minimum_reverification_interval).is_greater_than_or_equal_to(1) } it { is_expected.to validate_numericality_of(:minimum_reverification_interval).is_greater_than_or_equal_to(1) }
context 'primary node' do
it 'cannot be disabled' do
primary_node.enabled = false
expect(primary_node).not_to be_valid
expect(primary_node.errors).to include(:enabled)
end
end
end end
context 'default values' do context 'default values' do
......
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