Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/namespace_spec.rb')
-rw-r--r--spec/models/namespace_spec.rb55
1 files changed, 50 insertions, 5 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 9974aac3c6c..85569a68252 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -569,6 +569,48 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do
end
end
end
+
+ describe "#default_branch_protection_settings" do
+ let(:default_branch_protection_defaults) { {} }
+ let(:namespace_setting) { create(:namespace_settings, default_branch_protection_defaults: default_branch_protection_defaults) }
+ let(:namespace) { create(:namespace, namespace_settings: namespace_setting) }
+ let(:group) { create(:group, namespace_settings: namespace_setting) }
+
+ before do
+ stub_application_setting(default_branch_protection_defaults: Gitlab::Access::BranchProtection.protected_against_developer_pushes)
+ end
+
+ context 'for a namespace' do
+ it 'returns the instance level setting' do
+ expected_settings = Gitlab::Access::BranchProtection.protected_against_developer_pushes.deep_stringify_keys
+ settings = namespace.default_branch_protection_settings.to_hash
+
+ expect(settings).to eq(expected_settings)
+ end
+ end
+
+ context 'for a group' do
+ context 'that has not altered the default value' do
+ it 'returns the instance level setting' do
+ expected_settings = Gitlab::Access::BranchProtection.protected_against_developer_pushes.deep_stringify_keys
+ settings = group.default_branch_protection_settings.to_hash
+
+ expect(settings).to eq(expected_settings)
+ end
+ end
+
+ context 'that has altered the default value' do
+ let(:default_branch_protection_defaults) { Gitlab::Access::BranchProtection.protected_fully.deep_stringify_keys }
+
+ it 'returns the group level setting' do
+ expected_settings = default_branch_protection_defaults
+ settings = group.default_branch_protection_settings.to_hash
+
+ expect(settings).to eq(expected_settings)
+ end
+ end
+ end
+ end
end
describe "Respond to" do
@@ -1863,20 +1905,22 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do
describe '#emails_disabled?' do
context 'when not a subgroup' do
+ let(:group) { create(:group) }
+
it 'returns false' do
- group = create(:group, emails_disabled: false)
+ group.update_attribute(:emails_enabled, true)
expect(group.emails_disabled?).to be_falsey
end
it 'returns true' do
- group = create(:group, emails_disabled: true)
+ group.update_attribute(:emails_enabled, false)
expect(group.emails_disabled?).to be_truthy
end
it 'does not query the db when there is no parent group' do
- group = create(:group, emails_disabled: true)
+ group.update_attribute(:emails_enabled, false)
expect { group.emails_disabled? }.not_to exceed_query_limit(0)
end
@@ -1903,7 +1947,8 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do
describe '#emails_enabled?' do
context 'without a persisted namespace_setting object' do
- let(:group) { build(:group, emails_disabled: false) }
+ let(:group_settings) { create(:namespace_settings) }
+ let(:group) { build(:group, emails_disabled: false, namespace_settings: group_settings) }
it "is the opposite of emails_disabled" do
expect(group.emails_enabled?).to be_truthy
@@ -1928,7 +1973,7 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do
parent_2 = create(:group) # No projects
create(:project, group: child_1_1).tap do |project|
- project.pages_metadatum.update!(deployed: true)
+ create(:pages_deployment, project: project)
end
create(:project, group: child_1_1)