Commit 903b2c24 authored by Kamil Trzciński's avatar Kamil Trzciński

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

Fix environment folder route when special chars present

Closes #29922

See merge request !10250
parents 6460489b 80212617
---
title: Fix environment folder route when special chars present in environment name
merge_request: 10250
author:
......@@ -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
......
......@@ -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
......
......@@ -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) }
......
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
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