BigW Consortium Gitlab

Commit 46082f4b by Lin Jen-Shin
parent 3acf4fbe
...@@ -306,17 +306,12 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -306,17 +306,12 @@ class ApplicationSetting < ActiveRecord::Base
end end
def check_default_artifacts_expire_in def check_default_artifacts_expire_in
return true unless default_artifacts_expire_in if default_artifacts_expire_in &&
ChronicDuration.parse(default_artifacts_expire_in).nil?
if ChronicDuration.parse(default_artifacts_expire_in).nil? errors.add(:default_artifacts_expiration,
errors.add(:default_artifacts_expire_in,
"can't be 0. Leave it blank for no expiration") "can't be 0. Leave it blank for no expiration")
false
else
true
end end
rescue ChronicDuration::DurationParseError => e rescue ChronicDuration::DurationParseError => e
errors.add(:default_artifacts_expire_in, ": #{e.message}") errors.add(:default_artifacts_expiration, "is invalid")
false
end end
end end
...@@ -34,12 +34,16 @@ describe ApplicationSetting, models: true do ...@@ -34,12 +34,16 @@ describe ApplicationSetting, models: true do
setting.update(default_artifacts_expire_in: 'a') setting.update(default_artifacts_expire_in: 'a')
expect(setting).to be_invalid expect(setting).to be_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end end
it 'does not allow 0' do it 'does not allow 0' do
setting.update(default_artifacts_expire_in: '0') setting.update(default_artifacts_expire_in: '0')
expect(setting).to be_invalid expect(setting).to be_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end end
it 'sets the value if it is valid' do it 'sets the value if it is valid' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment