Commit 46082f4b authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 3acf4fbe
......@@ -306,17 +306,12 @@ class ApplicationSetting < ActiveRecord::Base
end
def check_default_artifacts_expire_in
return true unless default_artifacts_expire_in
if ChronicDuration.parse(default_artifacts_expire_in).nil?
errors.add(:default_artifacts_expire_in,
if default_artifacts_expire_in &&
ChronicDuration.parse(default_artifacts_expire_in).nil?
errors.add(:default_artifacts_expiration,
"can't be 0. Leave it blank for no expiration")
false
else
true
end
rescue ChronicDuration::DurationParseError => e
errors.add(:default_artifacts_expire_in, ": #{e.message}")
false
errors.add(:default_artifacts_expiration, "is invalid")
end
end
......@@ -34,12 +34,16 @@ describe ApplicationSetting, models: true do
setting.update(default_artifacts_expire_in: 'a')
expect(setting).to be_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end
it 'does not allow 0' do
setting.update(default_artifacts_expire_in: '0')
expect(setting).to be_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end
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