Merge branch 'fix/gb/environments-folders-route' into 'master'

Fix environment folder route when special chars present

Closes #29922

See merge request !10250
This commit is contained in:
Kamil Trzciński 2017-03-28 15:31:03 +00:00
commit 903b2c2448
5 changed files with 106 additions and 1 deletions

View file

@ -0,0 +1,4 @@
---
title: Fix environment folder route when special chars present in environment name
merge_request: 10250
author:

View file

@ -166,7 +166,7 @@ constraints(ProjectUrlConstrainer.new) do
end
collection do
get :folder, path: 'folders/:id'
get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ }
end
end

View file

@ -81,6 +81,39 @@ describe Projects::EnvironmentsController do
end
end
describe 'GET folder' do
before do
create(:environment, project: project,
name: 'staging-1.0/review',
state: :available)
end
context 'when using default format' do
it 'responds with HTML' do
get :folder, namespace_id: project.namespace,
project_id: project,
id: 'staging-1.0'
expect(response).to be_ok
expect(response).to render_template 'folder'
end
end
context 'when using JSON format' do
it 'responds with JSON' do
get :folder, namespace_id: project.namespace,
project_id: project,
id: 'staging-1.0',
format: :json
expect(response).to be_ok
expect(response).not_to render_template 'folder'
expect(json_response['environments'][0])
.to include('name' => 'staging-1.0/review')
end
end
end
describe 'GET show' do
context 'with valid id' do
it 'responds with a status code 200' do

View file

@ -166,6 +166,25 @@ feature 'Environment', :feature do
end
end
feature 'environment folders', :js do
context 'when folder name contains special charaters' do
before do
create(:environment, project: project,
name: 'staging-1.0/review',
state: :available)
visit folder_namespace_project_environments_path(project.namespace,
project,
id: 'staging-1.0')
end
it 'renders a correct environment folder' do
expect(page).to have_http_status(:ok)
expect(page).to have_content('Environments / staging-1.0')
end
end
end
feature 'auto-close environment when branch is deleted' do
given(:project) { create(:project) }

View file

@ -0,0 +1,49 @@
require 'spec_helper'
describe Projects::EnvironmentsController, :routing do
let(:project) { create(:empty_project) }
let(:environment) do
create(:environment, project: project,
name: 'staging-1.0/review')
end
let(:environments_route) do
"#{project.namespace.name}/#{project.name}/environments/"
end
describe 'routing environment folders' do
context 'when using JSON format' do
it 'correctly matches environment name and JSON format' do
expect(get_folder('staging-1.0.json'))
.to route_to(*folder_action(id: 'staging-1.0', format: 'json'))
end
end
context 'when using HTML format' do
it 'correctly matches environment name and HTML format' do
expect(get_folder('staging-1.0.html'))
.to route_to(*folder_action(id: 'staging-1.0', format: 'html'))
end
end
context 'when using implicit format' do
it 'correctly matches environment name' do
expect(get_folder('staging-1.0'))
.to route_to(*folder_action(id: 'staging-1.0'))
end
end
end
def get_folder(folder)
get("#{project.namespace.name}/#{project.name}/" \
"environments/folders/#{folder}")
end
def folder_action(**opts)
options = { namespace_id: project.namespace.name,
project_id: project.name }
['projects/environments#folder', options.merge(opts)]
end
end