Commit 5f4165c6 authored by Jan Provaznik's avatar Jan Provaznik

Update epics index JSON response

For JSON requests epics index page returns a JSON array of epics. This
will be used on epic roadmap page (#3559). Pagination is disabled in
this case - it's not supported for the first iteration on roadmap page.

Until now JSON response for epics index action returned an HTML list of
epics but it was not used anywhere in our code.

Related #3559
parent 6ac773c1
......@@ -17,9 +17,7 @@ class Groups::EpicsController < Groups::ApplicationController
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("groups/epics/_epics")
}
render json: serializer.represent(@epics)
end
end
end
......@@ -38,6 +36,10 @@ class Groups::EpicsController < Groups::ApplicationController
private
def pagination_disabled?
request.format.json?
end
def epic
@issuable = @epic ||= @group.epics.find_by(iid: params[:epic_id] || params[:id])
......
......@@ -76,6 +76,39 @@ describe Groups::EpicsController do
expect(response).to have_gitlab_http_status(200)
end
end
context 'when format is JSON' do
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
end
def list_epics
get :index, group_id: group, format: :json
end
it 'returns a list of epics' do
list_epics
expect(json_response).to be_an Array
end
it 'does not use pagination' do
list_epics
expect(json_response.size).to eq(2)
end
it 'returns correct epic attributes' do
list_epics
item = json_response.first
epic = Epic.find(item['id'])
expect(item['group_id']).to eq(group.id)
expect(item['start_date']).to eq(epic.start_date)
expect(item['end_date']).to eq(epic.end_date)
expect(item['web_url']).to eq(group_epic_path(group, epic))
end
end
end
describe 'GET #show' 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