diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-10-17 13:53:42 +0000 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2017-10-18 09:20:16 +0000 |
commit | 53bfe0891e96841f713dc9bfe19a1232d3f29205 (patch) | |
tree | 4afc958fc38d841821dbb6669879700287aad783 | |
parent | b2894dbceb7cce3e9ae00527724be515a290e809 (diff) | |
download | gitlab-ce-53bfe0891e96841f713dc9bfe19a1232d3f29205.tar.gz |
Merge branch 'prevent-creating-multiple-application-settings' into 'master'
Prevent creating multiple ApplicationSetting by forcing it to always have id=1
Closes #34728
See merge request gitlab-org/gitlab-ce!14718
(cherry picked from commit 65a1cbc600cf36ff5db9644072e4bf1e2b8e5cde)
c909b6aa Prevent creating multiple ApplicationSetting by forcing it to always have id=1
-rw-r--r-- | app/models/application_setting.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/prevent-creating-multiple-application-settings.yml | 5 | ||||
-rw-r--r-- | spec/models/application_setting_spec.rb | 10 |
3 files changed, 17 insertions, 0 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index c0cc60d5ebf..5b5bb3cbe2c 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -33,6 +33,8 @@ class ApplicationSetting < ActiveRecord::Base attr_accessor :domain_whitelist_raw, :domain_blacklist_raw + default_value_for :id, 1 + validates :uuid, presence: true validates :session_expire_delay, diff --git a/changelogs/unreleased/prevent-creating-multiple-application-settings.yml b/changelogs/unreleased/prevent-creating-multiple-application-settings.yml new file mode 100644 index 00000000000..fd49028b9e9 --- /dev/null +++ b/changelogs/unreleased/prevent-creating-multiple-application-settings.yml @@ -0,0 +1,5 @@ +--- +title: Prevent creating multiple ApplicationSetting instances +merge_request: +author: +type: fixed diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 78cacf9ff5d..eff84c308b5 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -209,6 +209,16 @@ describe ApplicationSetting do end end + context 'restrict creating duplicates' do + before do + described_class.create_from_defaults + end + + it 'raises an record creation violation if already created' do + expect { described_class.create_from_defaults }.to raise_error(ActiveRecord::RecordNotUnique) + end + end + context 'restricted signup domains' do it 'sets single domain' do setting.domain_whitelist_raw = 'example.com' |