Commit deffd918 authored by Timothy Andrew's avatar Timothy Andrew

Migrate the Todos API to use `issuable_iid`

- Instead of `issuable_id`
parent 3f57d9bb
...@@ -5,8 +5,8 @@ module API ...@@ -5,8 +5,8 @@ module API
before { authenticate! } before { authenticate! }
ISSUABLE_TYPES = { ISSUABLE_TYPES = {
'merge_requests' => ->(id) { find_merge_request_with_access(id) }, 'merge_requests' => ->(iid) { find_merge_request_with_access(iid) },
'issues' => ->(id) { find_project_issue(id) } 'issues' => ->(iid) { find_project_issue(iid) }
}.freeze }.freeze
params do params do
...@@ -14,13 +14,13 @@ module API ...@@ -14,13 +14,13 @@ module API
end end
resource :projects do resource :projects do
ISSUABLE_TYPES.each do |type, finder| ISSUABLE_TYPES.each do |type, finder|
type_id_str = "#{type.singularize}_id".to_sym type_id_str = "#{type.singularize}_iid".to_sym
desc 'Create a todo on an issuable' do desc 'Create a todo on an issuable' do
success Entities::Todo success Entities::Todo
end end
params do params do
requires type_id_str, type: Integer, desc: 'The ID of an issuable' requires type_id_str, type: Integer, desc: 'The IID of an issuable'
end end
post ":id/#{type}/:#{type_id_str}/todo" do post ":id/#{type}/:#{type_id_str}/todo" do
issuable = instance_exec(params[type_id_str], &finder) issuable = instance_exec(params[type_id_str], &finder)
......
...@@ -163,7 +163,7 @@ describe API::Todos, api: true do ...@@ -163,7 +163,7 @@ describe API::Todos, api: true do
shared_examples 'an issuable' do |issuable_type| shared_examples 'an issuable' do |issuable_type|
it 'creates a todo on an issuable' do it 'creates a todo on an issuable' do
post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.id}/todo", john_doe) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", john_doe)
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response['project']).to be_a Hash expect(json_response['project']).to be_a Hash
...@@ -180,7 +180,7 @@ describe API::Todos, api: true do ...@@ -180,7 +180,7 @@ describe API::Todos, api: true do
it 'returns 304 there already exist a todo on that issuable' do it 'returns 304 there already exist a todo on that issuable' do
create(:todo, project: project_1, author: author_1, user: john_doe, target: issuable) create(:todo, project: project_1, author: author_1, user: john_doe, target: issuable)
post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.id}/todo", john_doe) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", john_doe)
expect(response.status).to eq(304) expect(response.status).to eq(304)
end end
...@@ -195,7 +195,7 @@ describe API::Todos, api: true do ...@@ -195,7 +195,7 @@ describe API::Todos, api: true do
guest = create(:user) guest = create(:user)
project_1.team << [guest, :guest] project_1.team << [guest, :guest]
post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.id}/todo", guest) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", guest)
if issuable_type == 'merge_requests' if issuable_type == 'merge_requests'
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
......
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