Specify environment actions to distinguish between metrics and every other environment related actions

This commit is contained in:
Tiago Botelho 2018-06-26 10:36:16 +01:00 committed by Jose
parent c4df74d1e1
commit 91463e5246
7 changed files with 46 additions and 8 deletions

View file

@ -31,10 +31,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
end end
def empty
render :empty
end
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)
@ -124,6 +120,10 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
end end
def empty
render :empty
end
def metrics def metrics
# Currently, this acts as a hint to load the metrics details into the cache # Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already # if they aren't there already

View file

@ -15,6 +15,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
# Git clients will not know what authenticity token to send along # Git clients will not know what authenticity token to send along
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
skip_before_action :repository skip_before_action :repository
skip_before_action :available_environment
before_action :authenticate_user before_action :authenticate_user
private private

View file

@ -2,7 +2,7 @@ class Projects::UploadsController < Projects::ApplicationController
include UploadsActions include UploadsActions
# These will kick you out if you don't have access. # These will kick you out if you don't have access.
skip_before_action :project, :repository, skip_before_action :project, :repository, :available_environment,
if: -> { action_name == 'show' && image_or_video? } if: -> { action_name == 'show' && image_or_video? }
before_action :authorize_upload_file!, only: [:create] before_action :authorize_upload_file!, only: [:create]

View file

@ -204,18 +204,18 @@
%ul.sidebar-sub-level-items %ul.sidebar-sub-level-items
= nav_link(controller: [:environments, :clusters, :user, :gcp], html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: [:environments, :clusters, :user, :gcp], html_options: { class: "fly-out-top-item" } ) do
= link_to project_environments_path(@project) do = link_to operations_metrics_path(@project, @available_environment) do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
= _('Operations') = _('Operations')
%li.divider.fly-out-top-item %li.divider.fly-out-top-item
- if project_nav_tab? :environments - if project_nav_tab? :environments
= nav_link(controller: [:environments, :metrics]) do = nav_link(controller: :environments, action: [:metrics, :empty]) do
= link_to operations_metrics_path(@project, @available_environment), title: 'Metrics', class: 'shortcuts-environments' do = link_to operations_metrics_path(@project, @available_environment), title: 'Metrics', class: 'shortcuts-environments' do
%span %span
= _('Metrics') = _('Metrics')
= nav_link(controller: :environments) do = nav_link(controller: :environments, action: [:index, :folder, :show, :new, :edit, :create, :update, :stop, :terminal]) do
= link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do = link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do
%span %span
= _('Environments') = _('Environments')

View file

@ -277,6 +277,16 @@ describe Projects::EnvironmentsController do
end end
end end
describe 'GET #empty' do
it 'responds with HTML' do
get :empty, namespace_id: project.namespace,
project_id: project
expect(response).to be_ok
expect(response).to render_template 'empty'
end
end
describe 'GET #metrics' do describe 'GET #metrics' do
before do before do
allow(controller).to receive(:environment).and_return(environment) allow(controller).to receive(:environment).and_return(environment)

View file

@ -110,6 +110,14 @@ describe 'User uses shortcuts', :js do
end end
context 'when navigating to the Operations pages' do context 'when navigating to the Operations pages' do
it 'redirects to the Metrics page' do
find('body').native.send_key('g')
find('body').native.send_key('m')
expect(page).to have_active_navigation('Operations')
expect(page).to have_active_sub_navigation('Metrics')
end
it 'redirects to the Environments page' do it 'redirects to the Environments page' do
find('body').native.send_key('g') find('body').native.send_key('g')
find('body').native.send_key('e') find('body').native.send_key('e')

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe EnvironmentsHelper do
include ApplicationHelper
describe 'operations_metrics_path' do
let(:project) { create(:project) }
it 'returns empty metrics path when environment is nil' do
expect(helper.operations_metrics_path(project, nil)).to eq(empty_project_environments_path(project))
end
it 'returns environment metrics path when environment is passed' do
environment = create(:environment, project: project)
expect(helper.operations_metrics_path(project, environment)).to eq(environment_metrics_path(environment))
end
end
end