diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2016-04-13 16:30:20 +0200 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2016-04-13 17:15:42 +0200 |
commit | a9200d93d3e3d586302887fcaa0cf8f5fbd9a613 (patch) | |
tree | 52c4b9e8783c5787c61fe57aa9e53bd3260925df | |
parent | fa3009095fbb995550a20e5d0cbc994f4290fbea (diff) | |
download | gitlab-ce-a9200d93d3e3d586302887fcaa0cf8f5fbd9a613.tar.gz |
Ensure that issues and merge requests are found
-rw-r--r-- | doc/api/merge_requests.md | 1 | ||||
-rw-r--r-- | lib/api/issues.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 12 |
4 files changed, 20 insertions, 7 deletions
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index 3c18ebfa31e..2057f9d77aa 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -680,6 +680,7 @@ Example response: "subscribed": true } ``` + ## Unsubscribe from a merge request Unsubscribes the authenticated user from a merge request to not receive diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 37d25073074..4cdecadfe0f 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -239,8 +239,8 @@ module API # issue_id (required) - The ID of a project issue # Example Request: # POST /projects/:id/issues/:issue_id/subscription - post ":id/issues/:issue_id/subscription" do - issue = user_project.issues.find_by(id: params[:issue_id]) + post ':id/issues/:issue_id/subscription' do + issue = user_project.issues.find(params[:issue_id]) if issue.subscribed?(current_user) not_modified! @@ -257,8 +257,8 @@ module API # issue_id (required) - The ID of a project issue # Example Request: # DELETE /projects/:id/issues/:issue_id/subscription - delete ":id/issues/:issue_id/subscription" do - issue = user_project.issues.find_by(id: params[:issue_id]) + delete ':id/issues/:issue_id/subscription' do + issue = user_project.issues.find(params[:issue_id]) if issue.subscribed?(current_user) issue.unsubscribe(current_user) diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 8361a1649e0..86ea223f206 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -594,20 +594,20 @@ describe API::API, api: true do describe 'DELETE :id/issues/:issue_id/subscription' do it 'unsubscribes from an issue' do - post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) + delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) expect(response.status).to eq(200) expect(json_response['subscribed']).to eq(false) end it 'returns 304 if not subscribed' do - post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) + delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) expect(response.status).to eq(304) end it 'returns 404 if the issue is not found' do - post api("/projects/#{project.id}/issues/123/subscription", user) + delete api("/projects/#{project.id}/issues/123/subscription", user) expect(response.status).to eq(404) end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index c247fcf9c96..1fa7e76894f 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -529,6 +529,12 @@ describe API::API, api: true do expect(response.status).to eq(304) end + + it 'returns 404 if the merge request is not found' do + post api("/projects/#{project.id}/merge_requests/123/subscription", user) + + expect(response.status).to eq(404) + end end describe 'DELETE :id/merge_requests/:merge_request_id/subscription' do @@ -544,6 +550,12 @@ describe API::API, api: true do expect(response.status).to eq(304) end + + it 'returns 404 if the merge request is not found' do + post api("/projects/#{project.id}/merge_requests/123/subscription", user) + + expect(response.status).to eq(404) + end end def mr_with_later_created_and_updated_at_time |