Commit a9200d93 authored by Robert Schilling's avatar Robert Schilling

Ensure that issues and merge requests are found

parent fa300909
...@@ -680,6 +680,7 @@ Example response: ...@@ -680,6 +680,7 @@ Example response:
"subscribed": true "subscribed": true
} }
``` ```
## Unsubscribe from a merge request ## Unsubscribe from a merge request
Unsubscribes the authenticated user from a merge request to not receive Unsubscribes the authenticated user from a merge request to not receive
......
...@@ -239,8 +239,8 @@ module API ...@@ -239,8 +239,8 @@ module API
# issue_id (required) - The ID of a project issue # issue_id (required) - The ID of a project issue
# Example Request: # Example Request:
# POST /projects/:id/issues/:issue_id/subscription # POST /projects/:id/issues/:issue_id/subscription
post ":id/issues/:issue_id/subscription" do post ':id/issues/:issue_id/subscription' do
issue = user_project.issues.find_by(id: params[:issue_id]) issue = user_project.issues.find(params[:issue_id])
if issue.subscribed?(current_user) if issue.subscribed?(current_user)
not_modified! not_modified!
...@@ -257,8 +257,8 @@ module API ...@@ -257,8 +257,8 @@ module API
# issue_id (required) - The ID of a project issue # issue_id (required) - The ID of a project issue
# Example Request: # Example Request:
# DELETE /projects/:id/issues/:issue_id/subscription # DELETE /projects/:id/issues/:issue_id/subscription
delete ":id/issues/:issue_id/subscription" do delete ':id/issues/:issue_id/subscription' do
issue = user_project.issues.find_by(id: params[:issue_id]) issue = user_project.issues.find(params[:issue_id])
if issue.subscribed?(current_user) if issue.subscribed?(current_user)
issue.unsubscribe(current_user) issue.unsubscribe(current_user)
......
...@@ -594,20 +594,20 @@ describe API::API, api: true do ...@@ -594,20 +594,20 @@ describe API::API, api: true do
describe 'DELETE :id/issues/:issue_id/subscription' do describe 'DELETE :id/issues/:issue_id/subscription' do
it 'unsubscribes from an issue' 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(response.status).to eq(200)
expect(json_response['subscribed']).to eq(false) expect(json_response['subscribed']).to eq(false)
end end
it 'returns 304 if not subscribed' do 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) expect(response.status).to eq(304)
end end
it 'returns 404 if the issue is not found' do 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) expect(response.status).to eq(404)
end end
......
...@@ -529,6 +529,12 @@ describe API::API, api: true do ...@@ -529,6 +529,12 @@ describe API::API, api: true do
expect(response.status).to eq(304) expect(response.status).to eq(304)
end 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 end
describe 'DELETE :id/merge_requests/:merge_request_id/subscription' do describe 'DELETE :id/merge_requests/:merge_request_id/subscription' do
...@@ -544,6 +550,12 @@ describe API::API, api: true do ...@@ -544,6 +550,12 @@ describe API::API, api: true do
expect(response.status).to eq(304) expect(response.status).to eq(304)
end 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 end
def mr_with_later_created_and_updated_at_time def mr_with_later_created_and_updated_at_time
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment