summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-02-15 00:19:36 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-02-15 15:31:51 +0800
commit602f3b84c08c06cd132a8c53c7bcbb3a139cebfd (patch)
tree2072a43655467065a28204ea9fbd2324703245b2
parent4eff5eb89fc6eec5692f4119b2fc3c9622d1b3e3 (diff)
downloadgitlab-ce-602f3b84c08c06cd132a8c53c7bcbb3a139cebfd.tar.gz
Add a few more tests and make sure empty value sets to nil
-rw-r--r--app/models/application_setting.rb8
-rw-r--r--spec/models/application_setting_spec.rb22
-rw-r--r--spec/requests/api/settings_spec.rb11
3 files changed, 39 insertions, 2 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 818223dcc86..17193036fb6 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -269,6 +269,14 @@ class ApplicationSetting < ActiveRecord::Base
self.repository_storages = [value]
end
+ def default_artifacts_expire_in=(value)
+ if value.present?
+ super(value.strip)
+ else
+ super(nil)
+ end
+ end
+
# Choose one of the available repository storage options. Currently all have
# equal weighting.
def pick_repository_storage
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index b950fcdd81a..15632bac094 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -29,6 +29,28 @@ describe ApplicationSetting, models: true do
it { is_expected.not_to allow_value(['test']).for(:disabled_oauth_sign_in_sources) }
end
+ describe 'default_artifacts_expire_in' do
+ it 'sets an error if it is invalid' do
+ setting.update(default_artifacts_expire_in: 'a')
+
+ expect(setting).to be_invalid
+ end
+
+ it 'sets the value if it is valid' do
+ setting.update(default_artifacts_expire_in: '30 days')
+
+ expect(setting).to be_valid
+ expect(setting.default_artifacts_expire_in).to eq('30 days')
+ end
+
+ it 'does not set it if it is blank' do
+ setting.update(default_artifacts_expire_in: ' ')
+
+ expect(setting).to be_valid
+ expect(setting.default_artifacts_expire_in).to be_nil
+ end
+ end
+
it { is_expected.to validate_presence_of(:max_attachment_size) }
it do
diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb
index 91e3c333a02..411905edb49 100644
--- a/spec/requests/api/settings_spec.rb
+++ b/spec/requests/api/settings_spec.rb
@@ -30,8 +30,14 @@ describe API::Settings, 'Settings', api: true do
it "updates application settings" do
put api("/application/settings", admin),
- default_projects_limit: 3, signin_enabled: false, repository_storage: 'custom', koding_enabled: true, koding_url: 'http://koding.example.com',
- plantuml_enabled: true, plantuml_url: 'http://plantuml.example.com'
+ default_projects_limit: 3,
+ signin_enabled: false,
+ repository_storage: 'custom',
+ koding_enabled: true,
+ koding_url: 'http://koding.example.com',
+ plantuml_enabled: true,
+ plantuml_url: 'http://plantuml.example.com',
+ default_artifacts_expire_in: '2 days'
expect(response).to have_http_status(200)
expect(json_response['default_projects_limit']).to eq(3)
expect(json_response['signin_enabled']).to be_falsey
@@ -41,6 +47,7 @@ describe API::Settings, 'Settings', api: true do
expect(json_response['koding_url']).to eq('http://koding.example.com')
expect(json_response['plantuml_enabled']).to be_truthy
expect(json_response['plantuml_url']).to eq('http://plantuml.example.com')
+ expect(json_response['default_artifacts_expire_in']).to eq('2 days')
end
end