diff --git a/lib/travis/api/app/endpoint/users.rb b/lib/travis/api/app/endpoint/users.rb index c6067b90..ff109c2c 100644 --- a/lib/travis/api/app/endpoint/users.rb +++ b/lib/travis/api/app/endpoint/users.rb @@ -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 diff --git a/spec/unit/endpoint/users_spec.rb b/spec/unit/endpoint/users_spec.rb index 7675b170..46e0ff7e 100644 --- a/spec/unit/endpoint/users_spec.rb +++ b/spec/unit/endpoint/users_spec.rb @@ -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