Fix tests and disallow 0 to make it consistent with .gitlab-ci.yml

This commit is contained in:
Lin Jen-Shin 2017-02-15 15:31:25 +08:00
parent 602f3b84c0
commit cfd839d6f5
4 changed files with 17 additions and 4 deletions

View file

@ -306,9 +306,15 @@ class ApplicationSetting < ActiveRecord::Base
end
def check_default_artifacts_expire_in
ChronicDuration.parse(default_artifacts_expire_in) if
default_artifacts_expire_in
true
return true unless default_artifacts_expire_in
if ChronicDuration.parse(default_artifacts_expire_in).nil?
errors.add(:default_artifacts_expire_in,
"can't be 0. Leave it blank for unlimited")
false
else
true
end
rescue ChronicDuration::DurationParseError => e
errors.add(:default_artifacts_expire_in, ": #{e.message}")
false

View file

@ -559,6 +559,7 @@ module API
expose :default_project_visibility
expose :default_snippet_visibility
expose :default_group_visibility
expose :default_artifacts_expire_in
expose :domain_whitelist
expose :domain_blacklist_enabled
expose :domain_blacklist

View file

@ -57,7 +57,7 @@ module API
requires :shared_runners_text, type: String, desc: 'Shared runners text '
end
optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts"
optional :default_artifacts_expire_in, type: Integer, desc: "Set the default expiration time for each job's artifacts"
optional :default_artifacts_expire_in, type: String, desc: "Set the default expiration time for each job's artifacts"
optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'

View file

@ -36,6 +36,12 @@ describe ApplicationSetting, models: true do
expect(setting).to be_invalid
end
it 'does not allow 0' do
setting.update(default_artifacts_expire_in: '0')
expect(setting).to be_invalid
end
it 'sets the value if it is valid' do
setting.update(default_artifacts_expire_in: '30 days')