Не подтверждена Коммит 9f9c5031 создал по автору Francisco Javier López's avatar Francisco Javier López
Просмотр файлов

Stubbing ApplicationSetting.current in stub_application_setting

владелец 1c6aa98c
......@@ -1040,7 +1040,7 @@ def post_verified_issue
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
......
......@@ -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) { {} }
......
......@@ -290,7 +290,7 @@ def operation
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
......
......@@ -69,8 +69,8 @@
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 @@
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
......
......@@ -243,7 +243,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 '#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') }
......
......@@ -612,7 +612,7 @@
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
......
......@@ -132,7 +132,8 @@
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)
......
......@@ -17,7 +17,7 @@
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 }
......
......@@ -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))
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать