diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-10-17 13:53:42 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-10-17 13:53:42 +0000 |
commit | 65a1cbc600cf36ff5db9644072e4bf1e2b8e5cde (patch) | |
tree | 0354292dccf0debc90d55a00937d4033453603e0 | |
parent | 526c47618e446bfec776b6e17462298f17fb24ee (diff) | |
parent | c909b6aa6d62a4c556a866166d0a98c952d2ef62 (diff) | |
download | gitlab-ce-65a1cbc600cf36ff5db9644072e4bf1e2b8e5cde.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
-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 a93b777a9bc..d3b8debb0fd 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 cf192691507..6945c90cb9b 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -222,6 +222,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' |