Respond with 409 to POST '/users/sync' if sync is in progress

Fixes travis-ci/travis-ci#1659.

[Henrik Hodne: squashed commits]
This commit is contained in:
Hiro Asari 2014-01-27 08:00:32 -05:00 committed by Henrik Hodne
parent 6069f429cd
commit 5517623265
2 changed files with 21 additions and 1 deletions

View File

@ -47,7 +47,12 @@ class Travis::Api::App
end
post '/sync', scope: :private do
respond_with service(:sync_user)
if current_user.syncing?
status 409
{ 'message' => "Sync already in progress. Try again later." }
else
respond_with service(:sync_user)
end
end
end
end

View File

@ -29,4 +29,19 @@ describe Travis::Api::App::Endpoint::Users do
'correct_scopes' => true,
}
end
context 'when responding to POST for /users/sync' do
context 'when sync is in progress' do
before :each do
user.stubs(:syncing?).returns(true)
end
it 'returns 409' do
response = post('/users/sync', { access_token: access_token.to_s }, 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json, */*; q=0.01')
response.status.should == 409
JSON.parse(response.body).should be_true
end
end
end
end