Commit 734df1bb authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'api-fix-milestone-iid-filter' into 'master'

API: Add iid filter to milestones

This was documented in the API docs but it was never working because the iid filter was never applied to the milestones. The tests were working by accident because the were checking the first element, which was by accident the request element. 

* Closes https://github.com/gitlabhq/gitlabhq/issues/10122

See merge request !3588
parents 25998f57 9d03e8fd
...@@ -23,6 +23,7 @@ v 8.7.0 (unreleased) ...@@ -23,6 +23,7 @@ v 8.7.0 (unreleased)
- Add default scope to projects to exclude projects pending deletion - Add default scope to projects to exclude projects pending deletion
- Ensure empty recipients are rejected in BuildsEmailService - Ensure empty recipients are rejected in BuildsEmailService
- API: Ability to filter milestones by state `active` and `closed` (Robert Schilling) - API: Ability to filter milestones by state `active` and `closed` (Robert Schilling)
- API: Fix milestone filtering by `iid` (Robert Schilling)
- Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.)
- Better errors handling when creating milestones inside groups - Better errors handling when creating milestones inside groups
- Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.)
......
...@@ -21,6 +21,7 @@ module API ...@@ -21,6 +21,7 @@ module API
# state (optional) - Return "active" or "closed" milestones # state (optional) - Return "active" or "closed" milestones
# Example Request: # Example Request:
# GET /projects/:id/milestones # GET /projects/:id/milestones
# GET /projects/:id/milestones?iid=42
# GET /projects/:id/milestones?state=active # GET /projects/:id/milestones?state=active
# GET /projects/:id/milestones?state=closed # GET /projects/:id/milestones?state=closed
get ":id/milestones" do get ":id/milestones" do
...@@ -28,6 +29,7 @@ module API ...@@ -28,6 +29,7 @@ module API
milestones = user_project.milestones milestones = user_project.milestones
milestones = filter_milestones_state(milestones, params[:state]) milestones = filter_milestones_state(milestones, params[:state])
milestones = filter_by_iid(milestones, params[:iid]) if params[:iid].present?
present paginate(milestones), with: Entities::Milestone present paginate(milestones), with: Entities::Milestone
end end
......
...@@ -50,10 +50,12 @@ describe API::API, api: true do ...@@ -50,10 +50,12 @@ describe API::API, api: true do
end end
it 'should return a project milestone by iid' do it 'should return a project milestone by iid' do
get api("/projects/#{project.id}/milestones?iid=#{milestone.iid}", user) get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(json_response.first['title']).to eq milestone.title expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq milestone.id expect(json_response.first['title']).to eq closed_milestone.title
expect(json_response.first['id']).to eq closed_milestone.id
end end
it 'should return 401 error if user not authenticated' do it 'should return 401 error if user not authenticated' do
......
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