diff options
Diffstat (limited to 'spec/models/concerns/cascading_namespace_setting_attribute_spec.rb')
-rw-r--r-- | spec/models/concerns/cascading_namespace_setting_attribute_spec.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb index ddff9ce32b4..02cd8557231 100644 --- a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb +++ b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb @@ -142,7 +142,7 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do end it 'does not allow the local value to be saved' do - subgroup_settings.delayed_project_removal = nil + subgroup_settings.delayed_project_removal = false expect { subgroup_settings.save! } .to raise_error(ActiveRecord::RecordInvalid, /Delayed project removal cannot be changed because it is locked by an ancestor/) @@ -164,6 +164,19 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do end end + describe '#delayed_project_removal=' do + before do + subgroup_settings.update!(delayed_project_removal: nil) + group_settings.update!(delayed_project_removal: true) + end + + it 'does not save the value locally when it matches the cascaded value' do + subgroup_settings.update!(delayed_project_removal: true) + + expect(subgroup_settings.read_attribute(:delayed_project_removal)).to eq(nil) + end + end + describe '#delayed_project_removal_locked?' do shared_examples 'not locked' do it 'is not locked by an ancestor' do @@ -189,6 +202,20 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do it_behaves_like 'not locked' end + context 'when attribute is locked by self' do + before do + subgroup_settings.update!(lock_delayed_project_removal: true) + end + + it 'is not locked by default' do + expect(subgroup_settings.delayed_project_removal_locked?).to eq(false) + end + + it 'is locked when including self' do + expect(subgroup_settings.delayed_project_removal_locked?(include_self: true)).to eq(true) + end + end + context 'when parent does not lock the attribute' do it_behaves_like 'not locked' end @@ -277,6 +304,13 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do expect { subgroup_settings.save! } .to raise_error(ActiveRecord::RecordInvalid, /Delayed project removal cannot be nil when locking the attribute/) end + + it 'copies the cascaded value when locking the attribute if the local value is nil', :aggregate_failures do + subgroup_settings.delayed_project_removal = nil + subgroup_settings.lock_delayed_project_removal = true + + expect(subgroup_settings.read_attribute(:delayed_project_removal)).to eq(false) + end end context 'when application settings locks the attribute' do |