Fix PATCH repos/:id/settings
This commit is contained in:
parent
c1473f0d15
commit
e11dfa35cf
|
@ -52,10 +52,16 @@ class Travis::Api::App
|
|||
end
|
||||
end
|
||||
|
||||
put '/:id/settings' do
|
||||
patch '/:id/settings' do
|
||||
payload = JSON.parse request.body.read
|
||||
|
||||
if payload['settings'].blank? || !payload['settings'].is_a?(Hash)
|
||||
halt 422, { "error" => "Settings must be passed with a request" }
|
||||
end
|
||||
|
||||
settings = service(:find_repo_settings, params).run
|
||||
if settings
|
||||
settings.merge(params[:settings])
|
||||
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.repository.save
|
||||
|
|
|
@ -24,12 +24,23 @@ describe 'Repos' do
|
|||
}.to change { repo.reload.key.private_key }
|
||||
end
|
||||
|
||||
it 'allows to update settings' do
|
||||
json = { 'settings' => { 'a-new-setting' => 'value' } }.to_json
|
||||
response = patch "repos/#{repo.id}/settings", json, headers
|
||||
|
||||
repo.reload.settings['a-new-setting'].should == 'value'
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body['settings']['a-new-setting'].should == 'value'
|
||||
end
|
||||
|
||||
it 'allows to get settings' do
|
||||
repo.settings.replace('foo' => { 'type' => 'password', 'value' => 'abc123' })
|
||||
repo.save
|
||||
|
||||
response = get "repos/#{repo.id}/settings", {}, headers
|
||||
JSON.parse(response.body).should == { 'settings' => { 'foo' => { 'type' => 'password', 'value' => '∗∗∗∗∗∗' } } }
|
||||
settings = Repository::Settings.defaults.deep_merge({ 'foo' => { 'type' => 'password', 'value' => '∗∗∗∗∗∗' } })
|
||||
JSON.parse(response.body).should == { 'settings' => settings }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user