diff options
Diffstat (limited to 'spec/models/namespace_setting_spec.rb')
-rw-r--r-- | spec/models/namespace_setting_spec.rb | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/spec/models/namespace_setting_spec.rb b/spec/models/namespace_setting_spec.rb index e9822d97447..c7449e047b0 100644 --- a/spec/models/namespace_setting_spec.rb +++ b/spec/models/namespace_setting_spec.rb @@ -216,32 +216,54 @@ RSpec.describe NamespaceSetting, feature_category: :groups_and_projects, type: : end end - describe '#emails_enabled?' do - context 'when a group has no parent' - let(:settings) { create(:namespace_settings, emails_enabled: true) } - let(:grandparent) { create(:group) } + context 'when a group has parent groups' do + let(:grandparent) { create(:group, namespace_settings: settings) } let(:parent) { create(:group, parent: grandparent) } - let(:group) { create(:group, parent: parent, namespace_settings: settings) } + let!(:group) { create(:group, parent: parent) } - context 'when the groups setting is changed' do - it 'returns false when the attribute is false' do - group.update_attribute(:emails_disabled, true) + context "when a parent group has disabled diff previews" do + let(:settings) { create(:namespace_settings, show_diff_preview_in_email: false) } - expect(group.emails_enabled?).to be_falsey + it 'returns false' do + expect(group.show_diff_preview_in_email?).to be_falsey end end - context 'when a group has a parent' do - it 'returns true when no parent has disabled emails' do - expect(group.emails_enabled?).to be_truthy + context 'when all parent groups have enabled diff previews' do + let(:settings) { create(:namespace_settings, show_diff_preview_in_email: true) } + + it 'returns true' do + expect(group.show_diff_preview_in_email?).to be_truthy end + end + end + end - context 'when ancestor emails are disabled' do - it 'returns false' do - grandparent.update_attribute(:emails_disabled, true) + describe '#emails_enabled?' do + context 'when a group has no parent' + let(:settings) { create(:namespace_settings, emails_enabled: true) } + let(:grandparent) { create(:group) } + let(:parent) { create(:group, parent: grandparent) } + let(:group) { create(:group, parent: parent, namespace_settings: settings) } - expect(group.emails_enabled?).to be_falsey - end + context 'when the groups setting is changed' do + it 'returns false when the attribute is false' do + group.update_attribute(:emails_enabled, false) + + expect(group.emails_enabled?).to be_falsey + end + end + + context 'when a group has a parent' do + it 'returns true when no parent has disabled emails' do + expect(group.emails_enabled?).to be_truthy + end + + context 'when ancestor emails are disabled' do + it 'returns false' do + grandparent.update_attribute(:emails_enabled, false) + + expect(group.emails_enabled?).to be_falsey end end end @@ -251,19 +273,19 @@ RSpec.describe NamespaceSetting, feature_category: :groups_and_projects, type: : let(:parent) { create(:group, parent: grandparent) } let!(:group) { create(:group, parent: parent) } - context "when a parent group has disabled diff previews" do - let(:settings) { create(:namespace_settings, show_diff_preview_in_email: false) } + context "when a parent group has emails disabled" do + let(:settings) { create(:namespace_settings, emails_enabled: false) } it 'returns false' do - expect(group.show_diff_preview_in_email?).to be_falsey + expect(group.emails_enabled?).to be_falsey end end - context 'when all parent groups have enabled diff previews' do - let(:settings) { create(:namespace_settings, show_diff_preview_in_email: true) } + context 'when all parent groups have emails enabled' do + let(:settings) { create(:namespace_settings, emails_enabled: true) } it 'returns true' do - expect(group.show_diff_preview_in_email?).to be_truthy + expect(group.emails_enabled?).to be_truthy end end end |