Properly validate settings
This commit is contained in:
parent
fa56e4cfa0
commit
2e8fc35e13
|
@ -64,8 +64,12 @@ class Travis::Api::App
|
|||
settings.merge(payload['settings'])
|
||||
# TODO: I would like to have better API here, but leaving this
|
||||
# for testing to not waste too much time before I can play with it
|
||||
settings.save
|
||||
respond_with({ settings: settings.obfuscated }, version: :v2)
|
||||
if settings.save
|
||||
respond_with({ settings: settings.obfuscated }, version: :v2)
|
||||
else
|
||||
status 422
|
||||
respond_with(settings, type: :validation_error, version: :v2)
|
||||
end
|
||||
else
|
||||
status 404
|
||||
end
|
||||
|
|
|
@ -34,10 +34,23 @@ describe 'Repos' do
|
|||
body['settings']['build_pushes'].should == false
|
||||
end
|
||||
|
||||
it 'returns errors when settings are not valid' do
|
||||
json = { 'settings' => { 'maximum_number_of_builds' => 'this is not a number' } }.to_json
|
||||
response = patch "repos/#{repo.id}/settings", json, headers
|
||||
|
||||
repo.reload.settings['maximum_number_of_builds'].should == 0
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body['message'].should == 'Validation failed'
|
||||
body['errors'].should == [{
|
||||
'field' => 'maximum_number_of_builds',
|
||||
'code' => 'not_a_number'
|
||||
}]
|
||||
end
|
||||
|
||||
it 'allows to get settings' do
|
||||
response = get "repos/#{repo.id}/settings", {}, headers
|
||||
settings = Repository::Settings.defaults
|
||||
JSON.parse(response.body).should == { 'settings' => settings }
|
||||
JSON.parse(response.body)['settings'].should have_key('build_pushes')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user