Commit 35ab669a authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'zj-sort-env-folders' into 'master'

Sort environments folders when opening them

Closes #30814

See merge request !11436
parents d7157746 5c83d3af
...@@ -31,6 +31,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -31,6 +31,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def folder def folder
folder_environments = project.environments.where(environment_type: params[:id]) folder_environments = project.environments.where(environment_type: params[:id])
@environments = folder_environments.with_state(params[:scope] || :available) @environments = folder_environments.with_state(params[:scope] || :available)
.order(:name)
respond_to do |format| respond_to do |format|
format.html format.html
......
---
title: Sort folder for environments
merge_request:
author:
require 'spec_helper' require 'spec_helper'
describe Projects::EnvironmentsController do describe Projects::EnvironmentsController do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:project) { create(:empty_project) } set(:project) { create(:empty_project) }
let(:environment) do set(:environment) do
create(:environment, name: 'production', project: project) create(:environment, name: 'production', project: project)
end end
before do before do
project.team << [user, :master] project.add_master(user)
sign_in(user) sign_in(user)
end end
describe 'GET index' do describe 'GET index' do
context 'when standardrequest has been made' do context 'when a request for the HTML is made' do
it 'responds with status code 200' do it 'responds with status code 200' do
get :index, environment_params get :index, environment_params
expect(response).to be_ok expect(response).to have_http_status(:ok)
end end
end end
...@@ -84,6 +84,9 @@ describe Projects::EnvironmentsController do ...@@ -84,6 +84,9 @@ describe Projects::EnvironmentsController do
create(:environment, project: project, create(:environment, project: project,
name: 'staging-1.0/review', name: 'staging-1.0/review',
state: :available) state: :available)
create(:environment, project: project,
name: 'staging-1.0/zzz',
state: :available)
end end
context 'when using default format' do context 'when using default format' do
...@@ -98,7 +101,7 @@ describe Projects::EnvironmentsController do ...@@ -98,7 +101,7 @@ describe Projects::EnvironmentsController do
end end
context 'when using JSON format' do context 'when using JSON format' do
it 'responds with JSON' do it 'sorts the subfolders lexicographically' do
get :folder, namespace_id: project.namespace, get :folder, namespace_id: project.namespace,
project_id: project, project_id: project,
id: 'staging-1.0', id: 'staging-1.0',
...@@ -108,6 +111,8 @@ describe Projects::EnvironmentsController do ...@@ -108,6 +111,8 @@ describe Projects::EnvironmentsController do
expect(response).not_to render_template 'folder' expect(response).not_to render_template 'folder'
expect(json_response['environments'][0]) expect(json_response['environments'][0])
.to include('name' => 'staging-1.0/review') .to include('name' => 'staging-1.0/review')
expect(json_response['environments'][1])
.to include('name' => 'staging-1.0/zzz')
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