Commit efa05023 authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Filipa Lacerda

Enable grouping and pagination in environmnets API

parent 0fddece7
...@@ -16,7 +16,9 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -16,7 +16,9 @@ class Projects::EnvironmentsController < Projects::ApplicationController
format.html format.html
format.json do format.json do
render json: EnvironmentSerializer render json: EnvironmentSerializer
.new(project: @project, user: current_user) .new(project: @project, user: @current_user)
.with_pagination(request, response)
.within_folders
.represent(@environments) .represent(@environments)
end end
end end
......
...@@ -3,9 +3,13 @@ require 'spec_helper' ...@@ -3,9 +3,13 @@ require 'spec_helper'
describe Projects::EnvironmentsController do describe Projects::EnvironmentsController do
include ApiHelpers include ApiHelpers
let(:environment) { create(:environment) }
let(:project) { environment.project }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:empty_project) }
let(:environment) do
create(:environment, name: 'production',
project: project)
end
before do before do
project.team << [user, :master] project.team << [user, :master]
...@@ -22,14 +26,20 @@ describe Projects::EnvironmentsController do ...@@ -22,14 +26,20 @@ describe Projects::EnvironmentsController do
end end
end end
context 'when requesting JSON response' do context 'when requesting JSON response for folders' do
before do
create(:environment, project: project, name: 'staging/review-1')
create(:environment, project: project, name: 'staging/review-2')
end
it 'responds with correct JSON' do it 'responds with correct JSON' do
get :index, environment_params(format: :json) get :index, environment_params(format: :json)
first_environment = json_response.first expect(json_response.count).to eq 2
expect(json_response.first['name']).to eq 'production'
expect(first_environment).not_to be_empty expect(json_response.second['name']).to eq 'staging'
expect(first_environment['name']). to eq environment.name expect(json_response.second['size']).to eq 2
expect(json_response.second['latest']['name']).to eq 'staging/review-2'
end end
end end
end end
......
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