summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2019-09-05 17:02:58 +0200
committerFrancisco Javier López <fjlopez@gitlab.com>2019-09-05 17:02:58 +0200
commit9f9c503121052ce21c2c33a09d344b7cfcbfdd4f (patch)
treefe2b234ccacc953955eb0bdfe98c3ed637478d5a
parent1c6aa98c37f3cb4221819044294020923c14f57d (diff)
downloadgitlab-ce-fj-stub-application-setting-current.tar.gz
Stubbing ApplicationSetting.current in stub_application_settingfj-stub-application-setting-current
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb2
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb4
-rw-r--r--spec/lib/gitlab/auth_spec.rb2
-rw-r--r--spec/lib/gitlab/legacy_github_import/project_creator_spec.rb8
-rw-r--r--spec/models/user_spec.rb18
-rw-r--r--spec/requests/git_http_spec.rb2
-rw-r--r--spec/requests/jwt_controller_spec.rb3
-rw-r--r--spec/services/groups/create_service_spec.rb2
-rw-r--r--spec/support/helpers/stub_configuration.rb3
9 files changed, 21 insertions, 23 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 608131dcbc8..282efe6909d 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -1040,7 +1040,7 @@ describe Projects::IssuesController do
context 'properly submits to Akismet' do
before do
allow_any_instance_of(AkismetService).to receive_messages(submit_spam: true)
- allow_any_instance_of(ApplicationSetting).to receive_messages(akismet_enabled: true)
+ stub_application_setting(akismet_enabled: true)
end
def post_spam
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb
index 7c65525b8dc..8d08431599f 100644
--- a/spec/lib/gitlab/asciidoc_spec.rb
+++ b/spec/lib/gitlab/asciidoc_spec.rb
@@ -7,10 +7,6 @@ module Gitlab
describe Asciidoc do
include FakeBlobHelpers
- before do
- allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
- end
-
context "without project" do
let(:input) { '<b>ascii</b>' }
let(:context) { {} }
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb
index 0365d63ea9c..4021ad53ce2 100644
--- a/spec/lib/gitlab/auth_spec.rb
+++ b/spec/lib/gitlab/auth_spec.rb
@@ -290,7 +290,7 @@ describe Gitlab::Auth do
end
it 'throws an error suggesting user create a PAT when internal auth is disabled' do
- allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false }
+ stub_application_setting(password_authentication_enabled_for_git: false)
expect { gl_auth.find_for_git_client('foo', 'bar', project: nil, ip: 'ip') }.to raise_error(Gitlab::Auth::MissingPersonalAccessTokenError)
end
diff --git a/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb b/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
index 8675d8691c8..25ea4bf1a33 100644
--- a/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
@@ -69,8 +69,8 @@ describe Gitlab::LegacyGithubImport::ProjectCreator do
context 'when visibility level is restricted' do
context 'when GitHub project is private' do
before do
- stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PRIVATE])
- allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
+ stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PRIVATE],
+ default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
end
it 'sets project visibility to the default project visibility' do
@@ -84,8 +84,8 @@ describe Gitlab::LegacyGithubImport::ProjectCreator do
context 'when GitHub project is public' do
before do
- stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
- allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
+ stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC],
+ default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
end
it 'sets project visibility to the default project visibility' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b8c323904b8..d2a314f3fa4 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -243,7 +243,7 @@ describe User do
describe 'email' do
context 'when no signup domains whitelisted' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return([])
+ stub_application_setting(domain_whitelist: [])
end
it 'accepts any email' do
@@ -254,7 +254,7 @@ describe User do
context 'when a signup domain is whitelisted and subdomains are allowed' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['example.com', '*.example.com'])
+ stub_application_setting(domain_whitelist: ['example.com', '*.example.com'])
end
it 'accepts info@example.com' do
@@ -275,7 +275,7 @@ describe User do
context 'when a signup domain is whitelisted and subdomains are not allowed' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['example.com'])
+ stub_application_setting(domain_whitelist: ['example.com'])
end
it 'accepts info@example.com' do
@@ -301,8 +301,8 @@ describe User do
context 'domain blacklist' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist_enabled?).and_return(true)
- allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['example.com'])
+ stub_application_setting(domain_blacklist_enabled: true)
+ stub_application_setting(domain_blacklist: ['example.com'])
end
context 'when a signup domain is blacklisted' do
@@ -324,8 +324,8 @@ describe User do
context 'when a signup domain is blacklisted but a wildcard subdomain is allowed' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['test.example.com'])
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['*.example.com'])
+ stub_application_setting(domain_blacklist: ['test.example.com'])
+ stub_application_setting(domain_whitelist: ['*.example.com'])
end
it 'gives priority to whitelist and allow info@test.example.com' do
@@ -336,7 +336,7 @@ describe User do
context 'with both lists containing a domain' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['test.com'])
+ stub_application_setting(domain_whitelist: ['test.com'])
end
it 'accepts info@test.com' do
@@ -845,7 +845,7 @@ describe User do
describe '#confirm' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(true)
+ stub_application_setting(send_user_confirmation_email: true)
end
let(:user) { create(:user, confirmed_at: nil, unconfirmed_email: 'test@gitlab.com') }
diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb
index 5c9a5b73ee5..2ab6b954d88 100644
--- a/spec/requests/git_http_spec.rb
+++ b/spec/requests/git_http_spec.rb
@@ -612,7 +612,7 @@ describe 'Git HTTP requests' do
context 'when internal auth is disabled' do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false }
+ stub_application_setting(password_authentication_enabled_for_git: false)
end
it 'rejects pulls with personal access token error message' do
diff --git a/spec/requests/jwt_controller_spec.rb b/spec/requests/jwt_controller_spec.rb
index 8b2c698fee1..853c7dfc6b2 100644
--- a/spec/requests/jwt_controller_spec.rb
+++ b/spec/requests/jwt_controller_spec.rb
@@ -132,7 +132,8 @@ describe JwtController do
context 'when internal auth is disabled' do
it 'rejects the authorization attempt with personal access token message' do
- allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false }
+ stub_application_setting(password_authentication_enabled_for_git: false)
+
get '/jwt/auth', params: parameters, headers: headers
expect(response).to have_gitlab_http_status(401)
diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb
index 0f9f20de586..e10e66e370f 100644
--- a/spec/services/groups/create_service_spec.rb
+++ b/spec/services/groups/create_service_spec.rb
@@ -17,7 +17,7 @@ describe Groups::CreateService, '#execute' do
context "cannot create group with restricted visibility level" do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:restricted_visibility_levels).and_return([Gitlab::VisibilityLevel::PUBLIC])
+ stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end
it { is_expected.not_to be_persisted }
diff --git a/spec/support/helpers/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb
index f364e4fd158..0a62a5fbc71 100644
--- a/spec/support/helpers/stub_configuration.rb
+++ b/spec/support/helpers/stub_configuration.rb
@@ -11,9 +11,10 @@ module StubConfiguration
def stub_application_setting(messages)
add_predicates(messages)
- # Stubbing both of these because we're not yet consistent with how we access
+ # Stubbing all of these because we're not yet consistent with how we access
# current application settings
allow_any_instance_of(ApplicationSetting).to receive_messages(to_settings(messages))
+ allow(ApplicationSetting).to receive(:current).and_return(ApplicationSetting.new)
allow(Gitlab::CurrentSettings.current_application_settings)
.to receive_messages(to_settings(messages))