Commit 602f3b84 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add a few more tests and make sure empty value sets to nil

parent 4eff5eb8
......@@ -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
......
......@@ -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
......
......@@ -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
......
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