summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-02-19 10:55:13 +1300
committermfluharty <mfluharty@gitlab.com>2019-02-20 11:20:34 -0700
commitabffd8832d7b7c633b93cb7cc350296d5634327a (patch)
tree005217b0825a5079249af0d79af4a2a8dbf24edb
parent302eff3fcc56e654fa86ebaeca8185680e5bb343 (diff)
downloadgitlab-ce-abffd8832d7b7c633b93cb7cc350296d5634327a.tar.gz
Use Gitlab::CurrentSettings in UrlValidator
Gitlab::CurrentSettings will create ApplicationSetting.current if not present which means we don't have to use `&.`. We can also more easily use stub_application_setting in specs
-rw-r--r--app/validators/url_validator.rb2
-rw-r--r--spec/lib/gitlab/current_settings_spec.rb7
-rw-r--r--spec/models/lfs_download_object_spec.rb4
3 files changed, 5 insertions, 8 deletions
diff --git a/app/validators/url_validator.rb b/app/validators/url_validator.rb
index d3e32818dc7..c85f5ba5cdb 100644
--- a/app/validators/url_validator.rb
+++ b/app/validators/url_validator.rb
@@ -93,6 +93,6 @@ class UrlValidator < ActiveModel::EachValidator
end
def allow_setting_local_requests?
- ApplicationSetting.current&.allow_local_requests_from_hooks_and_services?
+ Gitlab::CurrentSettings.allow_local_requests_from_hooks_and_services?
end
end
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb
index caf9fc5442c..97910e58676 100644
--- a/spec/lib/gitlab/current_settings_spec.rb
+++ b/spec/lib/gitlab/current_settings_spec.rb
@@ -14,9 +14,8 @@ describe Gitlab::CurrentSettings do
describe '#current_application_settings', :use_clean_rails_memory_store_caching do
it 'allows keys to be called directly' do
- db_settings = create(:application_setting,
- home_page_url: 'http://mydomain.com',
- signup_enabled: false)
+ db_settings = ApplicationSetting.first || create(:application_setting)
+ db_settings.update!(home_page_url: 'http://mydomain.com', signup_enabled: false)
expect(described_class.home_page_url).to eq(db_settings.home_page_url)
expect(described_class.signup_enabled?).to be_falsey
@@ -109,7 +108,7 @@ describe Gitlab::CurrentSettings do
context 'with pending migrations' do
before do
- expect(ActiveRecord::Migrator).to receive(:needs_migration?).and_return(true)
+ allow(ActiveRecord::Migrator).to receive(:needs_migration?).and_return(true)
end
shared_examples 'a non-persisted ApplicationSetting object' do
diff --git a/spec/models/lfs_download_object_spec.rb b/spec/models/lfs_download_object_spec.rb
index 88838b127d2..9e78d25ad33 100644
--- a/spec/models/lfs_download_object_spec.rb
+++ b/spec/models/lfs_download_object_spec.rb
@@ -46,9 +46,7 @@ describe LfsDownloadObject do
subject { described_class.new(oid: oid, size: size, link: 'http://192.168.1.1') }
before do
- allow(ApplicationSetting)
- .to receive(:current)
- .and_return(ApplicationSetting.build_from_defaults(allow_local_requests_from_hooks_and_services: setting))
+ stub_application_setting(allow_local_requests_from_hooks_and_services: setting)
end
context 'are allowed' do