Commit 6d7078e7 authored by Bala Kumar's avatar Bala Kumar Committed by Shinya Maeda

Resolve "Use Same Endpoint for HTML and JSON in OperationsController"

parent b8376928
# frozen_string_literal: true # frozen_string_literal: true
# Note: Both Operations dashboard (https://docs.gitlab.com/ee/user/operations_dashboard/) and Environments dashboard (https://docs.gitlab.com/ee/ci/environments/environments_dashboard.html) features are co-existing in the same controller.
class OperationsController < ApplicationController class OperationsController < ApplicationController
before_action :authorize_read_operations_dashboard! before_action :authorize_read_operations_dashboard!
respond_to :json, only: [:list]
feature_category :release_orchestration feature_category :release_orchestration
POLLING_INTERVAL = 120_000 POLLING_INTERVAL = 120_000
# Used by Operations dashboard.
def index def index
end respond_to do |format|
format.html
def environments format.json do
end set_polling_interval_header
projects = load_projects
def list render json: { projects: serialize_as_json(projects) }
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL) end
projects = load_projects end
render json: { projects: serialize_as_json(projects) }
end end
def environments_list # Used by Environments dashboard.
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL) def environments
projects = load_environments_projects respond_to do |format|
format.html
render json: { projects: serialize_as_json_for_environments(projects) } format.json do
set_polling_interval_header
projects = load_environments_projects
render json: { projects: serialize_as_json_for_environments(projects) }
end
end
end end
# Used by Operations and Environments dashboard.
def create def create
project_ids = params['project_ids'] respond_to do |format|
format.json do
result = add_projects(project_ids) project_ids = params['project_ids']
render json: { result = add_projects(project_ids)
added: result.added_project_ids,
duplicate: result.duplicate_project_ids, render json: {
invalid: result.invalid_project_ids added: result.added_project_ids,
} duplicate: result.duplicate_project_ids,
invalid: result.invalid_project_ids
}
end
end
end end
# Used by Operations and Environments dashboard.
def destroy def destroy
project_id = params['project_id'] project_id = params['project_id']
...@@ -57,6 +70,10 @@ class OperationsController < ApplicationController ...@@ -57,6 +70,10 @@ class OperationsController < ApplicationController
render_404 unless can?(current_user, :read_operations_dashboard) render_404 unless can?(current_user, :read_operations_dashboard)
end end
def set_polling_interval_header
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
end
def load_projects def load_projects
Dashboard::Operations::ListService.new(current_user).execute Dashboard::Operations::ListService.new(current_user).execute
end end
......
...@@ -6,8 +6,8 @@ module EE ...@@ -6,8 +6,8 @@ module EE
def operations_data def operations_data
{ {
'add-path' => add_operations_project_path, 'add-path' => add_operations_project_path(format: :json),
'list-path' => operations_list_path, 'list-path' => operations_path(format: :json),
'empty-dashboard-svg-path' => image_path('illustrations/operations-dashboard_empty.svg'), 'empty-dashboard-svg-path' => image_path('illustrations/operations-dashboard_empty.svg'),
'empty-dashboard-help-path' => help_page_path('user/operations_dashboard/index.md') 'empty-dashboard-help-path' => help_page_path('user/operations_dashboard/index.md')
} }
...@@ -15,8 +15,8 @@ module EE ...@@ -15,8 +15,8 @@ module EE
def environments_data def environments_data
{ {
'add-path' => add_operations_project_path, 'add-path' => add_operations_environments_project_path(format: :json),
'list-path' => operations_environments_list_path, 'list-path' => operations_environments_path(format: :json),
'empty-dashboard-svg-path' => image_path('illustrations/operations-dashboard_empty.svg'), 'empty-dashboard-svg-path' => image_path('illustrations/operations-dashboard_empty.svg'),
'empty-dashboard-help-path' => help_page_path('ci/environments/environments_dashboard.md'), 'empty-dashboard-help-path' => help_page_path('ci/environments/environments_dashboard.md'),
'environments-dashboard-help-path' => help_page_path('ci/environments/environments_dashboard.md') 'environments-dashboard-help-path' => help_page_path('ci/environments/environments_dashboard.md')
......
...@@ -9,7 +9,7 @@ class DashboardEnvironmentsProjectEntity < Grape::Entity ...@@ -9,7 +9,7 @@ class DashboardEnvironmentsProjectEntity < Grape::Entity
expose :web_url expose :web_url
expose :remove_path do |project| expose :remove_path do |project|
remove_operations_project_path(project_id: project.id) remove_operations_environments_project_path(project_id: project.id)
end end
expose :namespace, using: API::Entities::NamespaceBasic expose :namespace, using: API::Entities::NamespaceBasic
......
# frozen_string_literal: true # frozen_string_literal: true
# Used by Operations dashboard
get 'operations' => 'operations#index' get 'operations' => 'operations#index'
get 'operations/environments' => 'operations#environments'
get 'operations/list' => 'operations#list'
get 'operations/environments_list' => 'operations#environments_list'
post 'operations' => 'operations#create', as: :add_operations_project post 'operations' => 'operations#create', as: :add_operations_project
delete 'operations' => 'operations#destroy', as: :remove_operations_project delete 'operations' => 'operations#destroy', as: :remove_operations_project
# Used by Environments dashboard
get 'operations/environments' => 'operations#environments'
post 'operations/environments' => 'operations#create', as: :add_operations_environments_project
delete 'operations/environments' => 'operations#destroy', as: :remove_operations_environments_project
...@@ -14,634 +14,648 @@ RSpec.describe OperationsController do ...@@ -14,634 +14,648 @@ RSpec.describe OperationsController do
sign_in(user) sign_in(user)
end end
shared_examples 'unlicensed' do |http_method, action| shared_examples 'unlicensed' do |http_method, action, format = :html|
before do before do
stub_licensed_features(operations_dashboard: false) stub_licensed_features(operations_dashboard: false)
end end
it 'renders 404' do it 'renders 404' do
public_send(http_method, action) public_send(http_method, action, format: format)
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
describe 'GET #index' do describe 'GET #index' do
it_behaves_like 'unlicensed', :get, :index def get_index(format)
get :index, format: format
end
it 'renders index with 200 status code' do describe 'format html' do
get :index it_behaves_like 'unlicensed', :get, :index, :html
expect(response).to have_gitlab_http_status(:ok) it 'renders index with 200 status code' do
expect(response).to render_template(:index) get_index(:html)
end
context 'with an anonymous user' do expect(response).to have_gitlab_http_status(:ok)
before do expect(response).to render_template(:index)
sign_out(user)
end end
it 'redirects to sign-in page' do context 'with an anonymous user' do
get :index before do
sign_out(user)
end
expect(response).to redirect_to(new_user_session_path) it 'redirects to sign-in page' do
get_index(:html)
expect(response).to redirect_to(new_user_session_path)
end
end end
end end
end
describe 'GET #environments' do describe 'format json' do
it_behaves_like 'unlicensed', :get, :environments let(:now) { Time.current.change(usec: 0) }
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
let!(:environment) { create(:environment, name: 'production', project: project) }
let!(:deployment) { create(:deployment, :success, environment: environment, sha: commit.id, created_at: now, project: project) }
it 'renders the view' do it_behaves_like 'unlicensed', :get, :index, :json
get :environments
expect(response).to have_gitlab_http_status(:ok) shared_examples 'empty project list' do
expect(response).to render_template(:environments) it 'returns an empty list' do
end get_index(:json)
context 'with an anonymous user' do expect(response).to have_gitlab_http_status(:ok)
before do expect(json_response).to match_schema('dashboard/operations/list', dir: 'ee')
sign_out(user) expect(json_response['projects']).to eq([])
end
end end
it 'redirects to sign-in page' do context 'with added projects' do
get :environments let(:alert1) { create(:prometheus_alert, project: project, environment: environment) }
let(:alert2) { create(:prometheus_alert, project: project, environment: environment) }
expect(response).to redirect_to(new_user_session_path) let!(:alert_events) do
end [
end create(:alert_management_alert, prometheus_alert: alert1, project: project, environment: environment),
end create(:alert_management_alert, prometheus_alert: alert2, project: project, environment: environment),
create(:alert_management_alert, prometheus_alert: alert1, project: project, environment: environment),
create(:alert_management_alert, :resolved, prometheus_alert: alert2, project: project, environment: environment)
]
end
describe 'GET #list' do let(:open_alerts) { alert_events.select(&:triggered?) + alert_events.select(&:acknowledged?) }
let(:now) { Time.current.change(usec: 0) } let(:last_firing_alert) { open_alerts.last.prometheus_alert }
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
let!(:environment) { create(:environment, name: 'production', project: project) }
let!(:deployment) { create(:deployment, :success, environment: environment, sha: commit.id, created_at: now, project: project) }
it_behaves_like 'unlicensed', :get, :list let(:alert_path) do
metrics_project_environment_path(project, environment)
end
shared_examples 'empty project list' do let(:alert_json_path) do
it 'returns an empty list' do project_prometheus_alert_path(project, last_firing_alert.prometheus_metric_id,
get :list environment_id: environment, format: :json)
end
expect(response).to have_gitlab_http_status(:ok) let(:expected_project) { json_response['projects'].first }
expect(json_response).to match_schema('dashboard/operations/list', dir: 'ee')
expect(json_response['projects']).to eq([])
end
end
context 'with added projects' do before do
let(:alert1) { create(:prometheus_alert, project: project, environment: environment) } user.update!(ops_dashboard_projects: [project])
let(:alert2) { create(:prometheus_alert, project: project, environment: environment) } project.add_developer(user)
end
let!(:alert_events) do
[
create(:alert_management_alert, prometheus_alert: alert1, project: project, environment: environment),
create(:alert_management_alert, prometheus_alert: alert2, project: project, environment: environment),
create(:alert_management_alert, prometheus_alert: alert1, project: project, environment: environment),
create(:alert_management_alert, :resolved, prometheus_alert: alert2, project: project, environment: environment)
]
end
let(:open_alerts) { alert_events.select(&:triggered?) + alert_events.select(&:acknowledged?) } it 'returns a list of added projects' do
let(:last_firing_alert) { open_alerts.last.prometheus_alert } get_index(:json)
let(:alert_path) do expect(response).to have_gitlab_http_status(:ok)
metrics_project_environment_path(project, environment) expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee')
end
let(:alert_json_path) do expect(json_response['projects'].size).to eq(1)
project_prometheus_alert_path(project, last_firing_alert.prometheus_metric_id,
environment_id: environment, format: :json)
end
let(:expected_project) { json_response['projects'].first } expect(expected_project['id']).to eq(project.id)
expect(expected_project['remove_path'])
.to eq(remove_operations_project_path(project_id: project.id))
expect(expected_project['last_deployment']['id']).to eq(deployment.id)
expect(expected_project['alert_count']).to eq(open_alerts.size)
expect(expected_project['alert_path']).to eq(alert_path)
expect(expected_project['last_alert']['id']).to eq(last_firing_alert.id)
end
before do it "returns as many projects as are in the user's dashboard" do
user.update!(ops_dashboard_projects: [project]) projects = Array.new(8).map do
project.add_developer(user) project = create(:project)
end project.add_developer(user)
project
end
user.update!(ops_dashboard_projects: projects)
it 'returns a list of added projects' do get_index(:json)
get :list
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee') expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee')
expect(json_response['projects'].size).to eq(1) expect(json_response['projects'].size).to eq(8)
end
expect(expected_project['id']).to eq(project.id) it 'returns a list of added projects' do
expect(expected_project['remove_path']) get_index(:json)
.to eq(remove_operations_project_path(project_id: project.id))
expect(expected_project['last_deployment']['id']).to eq(deployment.id)
expect(expected_project['alert_count']).to eq(open_alerts.size)
expect(expected_project['alert_path']).to eq(alert_path)
expect(expected_project['last_alert']['id']).to eq(last_firing_alert.id)
end
it "returns as many projects as are in the user's dashboard" do expect(response).to have_gitlab_http_status(:ok)
projects = Array.new(8).map do expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee')
project = create(:project) expect(json_response['projects'].size).to eq(1)
project.add_developer(user) expect(expected_project['id']).to eq(project.id)
project
end end
user.update!(ops_dashboard_projects: projects)
get :list
expect(response).to have_gitlab_http_status(:ok) context 'without sufficient access level' do
expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee') before do
project.add_reporter(user)
end
expect(json_response['projects'].size).to eq(8) it_behaves_like 'empty project list'
end
end end
it 'returns a list of added projects' do context 'without projects' do
get :list it_behaves_like 'empty project list'
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee')
expect(json_response['projects'].size).to eq(1)
expect(expected_project['id']).to eq(project.id)
end end
context 'without sufficient access level' do context 'with an anonymous user' do
before do before do
project.add_reporter(user) sign_out(user)
end end
it_behaves_like 'empty project list' it 'returns unauthorized response' do
end get_index(:json)
end
context 'without projects' do
it_behaves_like 'empty project list'
end
context 'with an anonymous user' do
before do
sign_out(user)
end
it 'redirects to sign-in page' do expect(response).to have_gitlab_http_status(:unauthorized)
get :list expect(json_response['error']).to include('sign in or sign up before continuing')
end
expect(response).to redirect_to(new_user_session_path)
end end
end end
end end
describe 'GET #environments_list' do describe 'GET #environments' do
it_behaves_like 'unlicensed', :get, :environments_list def get_environments(format, params = nil)
get :environments, params: params, format: format
end
context 'with an anonymous user' do describe 'format html' do
before do it_behaves_like 'unlicensed', :get, :environments, :html
sign_out(user)
end
it 'redirects to sign-in page' do it 'renders the view' do
get :environments_list get_environments(:html)
expect(response).to redirect_to(new_user_session_path) expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:environments)
end end
end
context 'with an authenticated user without sufficient access_level' do context 'with an anonymous user' do
it 'returns an empty project list' do before do
project = create(:project) sign_out(user)
project.add_reporter(user) end
user.update!(ops_dashboard_projects: [project])
get :environments_list it 'redirects to sign-in page' do
get_environments(:html)
expect(response).to have_gitlab_http_status(:ok) expect(response).to redirect_to(new_user_session_path)
expect(json_response['projects']).to eq([]) end
end end
end end
context 'with an authenticated developer' do describe 'format json' do
it 'returns an empty project list' do it_behaves_like 'unlicensed', :get, :environments, :json
get :environments_list
expect(response).to have_gitlab_http_status(:ok) context 'with an anonymous user' do
expect(json_response['projects']).to eq([]) before do
end sign_out(user)
end
it 'sets the polling interval header' do it 'returns unauthorized response' do
get :environments_list get_environments(:json)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:unauthorized)
expect(response.headers[Gitlab::PollingInterval::HEADER_NAME]).to eq('120000') expect(json_response['error']).to include('sign in or sign up before continuing')
end
end end
it "returns an empty project list when the project is not in the developer's dashboard" do context 'with an authenticated user without sufficient access_level' do
project = create(:project) it 'returns an empty project list' do
project.add_developer(user) project = create(:project)
user.update!(ops_dashboard_projects: []) project.add_reporter(user)
user.update!(ops_dashboard_projects: [project])
get :environments_list get_environments(:json)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['projects']).to eq([]) expect(json_response['projects']).to eq([])
end
end end
context 'with a project in the dashboard' do context 'with an authenticated developer' do
let(:project) { create(:project, :with_avatar, :repository) } it 'returns an empty project list' do
get_environments(:json)
before do expect(response).to have_gitlab_http_status(:ok)
project.add_developer(user) expect(json_response['projects']).to eq([])
user.update!(ops_dashboard_projects: [project])
end end
it 'returns a project without an environment' do it 'sets the polling interval header' do
get :environments_list get_environments(:json)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') expect(response.headers[Gitlab::PollingInterval::HEADER_NAME]).to eq('120000')
end
project_json = json_response['projects'].first it "returns an empty project list when the project is not in the developer's dashboard" do
project = create(:project)
project.add_developer(user)
user.update!(ops_dashboard_projects: [])
get_environments(:json)
expect(project_json['id']).to eq(project.id) expect(response).to have_gitlab_http_status(:ok)
expect(project_json['name']).to eq(project.name) expect(json_response['projects']).to eq([])
expect(project_json['namespace']['id']).to eq(project.namespace.id)
expect(project_json['namespace']['name']).to eq(project.namespace.name)
expect(project_json['environments']).to eq([])
end end
it 'returns one project with one environment' do context 'with a project in the dashboard' do
environment = create(:environment, project: project, name: 'staging') let(:project) { create(:project, :with_avatar, :repository) }
get :environments_list before do
project.add_developer(user)
user.update!(ops_dashboard_projects: [project])
end
expect(response).to have_gitlab_http_status(:ok) it 'returns a project without an environment' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') get_environments(:json)
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(project_json['id']).to eq(project.id) project_json = json_response['projects'].first
expect(project_json['name']).to eq(project.name)
expect(project_json['namespace']['id']).to eq(project.namespace.id)
expect(project_json['namespace']['name']).to eq(project.namespace.name)
expect(project_json['environments'].count).to eq(1)
expect(project_json['environments'].first['id']).to eq(environment.id)
expect(project_json['environments'].first['environment_path']).to eq(project_environment_path(project, environment))
end
it 'returns multiple projects and environments' do expect(project_json['id']).to eq(project.id)
project2 = create(:project) expect(project_json['name']).to eq(project.name)
project2.add_developer(user) expect(project_json['namespace']['id']).to eq(project.namespace.id)
user.update!(ops_dashboard_projects: [project, project2]) expect(project_json['namespace']['name']).to eq(project.namespace.name)
environment1 = create(:environment, project: project) expect(project_json['environments']).to eq([])
environment2 = create(:environment, project: project) end
environment3 = create(:environment, project: project2)
get :environments_list it 'returns one project with one environment' do
environment = create(:environment, project: project, name: 'staging')
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
expect(json_response['projects'].count).to eq(2)
expect(json_response['projects'].map { |p| p['id'] }.sort).to eq([project.id, project2.id])
project_json = json_response['projects'].find { |p| p['id'] == project.id } expect(response).to have_gitlab_http_status(:ok)
project2_json = json_response['projects'].find { |p| p['id'] == project2.id } expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(project_json['environments'].map { |e| e['id'] }.sort).to eq([environment1.id, environment2.id]) project_json = json_response['projects'].first
expect(project2_json['environments'].map { |e| e['id'] }).to eq([environment3.id])
end
it 'does not return environments that would be grouped into a folder' do expect(project_json['id']).to eq(project.id)
create(:environment, project: project, name: 'review/test-feature') expect(project_json['name']).to eq(project.name)
create(:environment, project: project, name: 'review/another-feature') expect(project_json['namespace']['id']).to eq(project.namespace.id)
expect(project_json['namespace']['name']).to eq(project.namespace.name)
expect(project_json['environments'].count).to eq(1)
expect(project_json['environments'].first['id']).to eq(environment.id)
expect(project_json['environments'].first['environment_path']).to eq(project_environment_path(project, environment))
end
get :environments_list it 'returns multiple projects and environments' do
project2 = create(:project)
project2.add_developer(user)
user.update!(ops_dashboard_projects: [project, project2])
environment1 = create(:environment, project: project)
environment2 = create(:environment, project: project)
environment3 = create(:environment, project: project2)
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(json_response['projects'].count).to eq(2)
expect(json_response['projects'].map { |p| p['id'] }.sort).to eq([project.id, project2.id])
expect(project_json['environments'].count).to eq(0) project_json = json_response['projects'].find { |p| p['id'] == project.id }
end project2_json = json_response['projects'].find { |p| p['id'] == project2.id }
it 'does not return environments that would be grouped into a folder even when there is only a single environment' do expect(project_json['environments'].map { |e| e['id'] }.sort).to eq([environment1.id, environment2.id])
create(:environment, project: project, name: 'staging/test-feature') expect(project2_json['environments'].map { |e| e['id'] }).to eq([environment3.id])
end
get :environments_list it 'does not return environments that would be grouped into a folder' do
create(:environment, project: project, name: 'review/test-feature')
create(:environment, project: project, name: 'review/another-feature')
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(project_json['environments'].count).to eq(0) project_json = json_response['projects'].first
end
it 'returns an environment not in a folder' do expect(project_json['environments'].count).to eq(0)
environment = create(:environment, project: project, name: 'production') end
get :environments_list it 'does not return environments that would be grouped into a folder even when there is only a single environment' do
create(:environment, project: project, name: 'staging/test-feature')
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(project_json['environments'].count).to eq(1) project_json = json_response['projects'].first
expect(project_json['environments'].first['id']).to eq(environment.id)
end
it 'returns the last deployment for an environment' do expect(project_json['environments'].count).to eq(0)
environment = create(:environment, project: project) end
deployment = create(:deployment, :success, project: project, environment: environment)
get :environments_list it 'returns an environment not in a folder' do
environment = create(:environment, project: project, name: 'production')
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
environment_json = project_json['environments'].first expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
last_deployment_json = environment_json['last_deployment']
expect(last_deployment_json['id']).to eq(deployment.id) project_json = json_response['projects'].first
end
it "returns the last deployment's deployable" do expect(project_json['environments'].count).to eq(1)
environment = create(:environment, project: project) expect(project_json['environments'].first['id']).to eq(environment.id)
ci_build = create(:ci_build, project: project) end
create(:deployment, :success, project: project, environment: environment, deployable: ci_build)
get :environments_list it 'returns the last deployment for an environment' do
environment = create(:environment, project: project)
deployment = create(:deployment, :success, project: project, environment: environment)
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
environment_json = project_json['environments'].first expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
deployable_json = environment_json['last_deployment']['deployable']
expect(deployable_json['id']).to eq(ci_build.id) project_json = json_response['projects'].first
expect(deployable_json['build_path']).to eq(project_job_path(project, ci_build)) environment_json = project_json['environments'].first
end last_deployment_json = environment_json['last_deployment']
it 'returns a failed deployment' do expect(last_deployment_json['id']).to eq(deployment.id)
environment = create(:environment, project: project) end
deployment = create(:deployment, :failed, project: project, environment: environment)
get :environments_list it "returns the last deployment's deployable" do
environment = create(:environment, project: project)
ci_build = create(:ci_build, project: project)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build)
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first expect(response).to have_gitlab_http_status(:ok)
environment_json = project_json['environments'].first expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
last_deployment_json = environment_json['last_deployment']
expect(last_deployment_json['id']).to eq(deployment.id) project_json = json_response['projects'].first
end environment_json = project_json['environments'].first
deployable_json = environment_json['last_deployment']['deployable']
context 'with environments pagination' do expect(deployable_json['id']).to eq(ci_build.id)
shared_examples_for 'environments pagination' do |params, projects_count| expect(deployable_json['build_path']).to eq(project_job_path(project, ci_build))
specify do end
get :environments_list, params: params
expect(response).to have_gitlab_http_status(:ok) it 'returns a failed deployment' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') environment = create(:environment, project: project)
expect(json_response['projects'].count).to eq(projects_count) deployment = create(:deployment, :failed, project: project, environment: environment)
expect(response).to include_pagination_headers
end get_environments(:json)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
project_json = json_response['projects'].first
environment_json = project_json['environments'].first
last_deployment_json = environment_json['last_deployment']
expect(last_deployment_json['id']).to eq(deployment.id)
end end
context 'pagination behaviour' do context 'with environments pagination' do
before do shared_examples_for 'environments pagination' do |params, projects_count|
projects = create_list(:project, 8) do |project| specify do
project.add_developer(user) get_environments(:json, params)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(json_response['projects'].count).to eq(projects_count)
expect(response).to include_pagination_headers
end end
user.update!(ops_dashboard_projects: projects)
end end
context 'with `per_page`' do context 'pagination behaviour' do
it_behaves_like 'environments pagination', { per_page: 7 }, 7 before do
end projects = create_list(:project, 8) do |project|
project.add_developer(user)
end
user.update!(ops_dashboard_projects: projects)
end
context 'with `page=1`' do context 'with `per_page`' do
it_behaves_like 'environments pagination', { per_page: 7, page: 1 }, 7 it_behaves_like 'environments pagination', { per_page: 7 }, 7
end end
context 'with `page=2`' do context 'with `page=1`' do
it_behaves_like 'environments pagination', { per_page: 7, page: 2 }, 1 it_behaves_like 'environments pagination', { per_page: 7, page: 1 }, 7
end
context 'with `page=2`' do
it_behaves_like 'environments pagination', { per_page: 7, page: 2 }, 1
end
end end
end
context 'N+1 queries' do context 'N+1 queries' do
subject { get :environments_list } subject { get_environments(:json) }
it 'avoids N+1 database queries' do it 'avoids N+1 database queries' do
control_count = ActiveRecord::QueryRecorder.new { subject }.count control_count = ActiveRecord::QueryRecorder.new { subject }.count
projects = create_list(:project, 8) do |project| projects = create_list(:project, 8) do |project|
project.add_developer(user) project.add_developer(user)
end end
user.update!(ops_dashboard_projects: projects) user.update!(ops_dashboard_projects: projects)
expect { subject }.not_to exceed_query_limit(control_count) expect { subject }.not_to exceed_query_limit(control_count)
end
end end
end end
end
it 'does not return a project for which the operations dashboard feature is unavailable' do
stub_application_setting(check_namespace_plan: true)
namespace = create(:namespace, visibility_level: PRIVATE)
unavailable_project = create(:project, namespace: namespace, visibility_level: PRIVATE)
unavailable_project.add_developer(user)
user.update!(ops_dashboard_projects: [unavailable_project])
get :environments_list it 'does not return a project for which the operations dashboard feature is unavailable' do
stub_application_setting(check_namespace_plan: true)
namespace = create(:namespace, visibility_level: PRIVATE)
unavailable_project = create(:project, namespace: namespace, visibility_level: PRIVATE)
unavailable_project.add_developer(user)
user.update!(ops_dashboard_projects: [unavailable_project])
expect(response).to have_gitlab_http_status(:ok) get_environments(:json)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
expect(json_response['projects'].count).to eq(0)
end
it 'returns seven projects when some projects do not have the dashboard feature available' do expect(response).to have_gitlab_http_status(:ok)
stub_application_setting(check_namespace_plan: true) expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(json_response['projects'].count).to eq(0)
public_namespace = create(:namespace, visibility_level: PUBLIC)
public_projects = Array.new(7).map do
project = create(:project, namespace: public_namespace, visibility_level: PUBLIC)
project.add_developer(user)
project
end end
private_namespace = create(:namespace, visibility_level: PRIVATE) it 'returns seven projects when some projects do not have the dashboard feature available' do
private_project = create(:project, namespace: private_namespace, visibility_level: PRIVATE) stub_application_setting(check_namespace_plan: true)
private_project.add_developer(user)
all_projects = [private_project] + public_projects public_namespace = create(:namespace, visibility_level: PUBLIC)
user.update!(ops_dashboard_projects: all_projects) public_projects = Array.new(7).map do
project = create(:project, namespace: public_namespace, visibility_level: PUBLIC)
project.add_developer(user)
project
end
get :environments_list private_namespace = create(:namespace, visibility_level: PRIVATE)
private_project = create(:project, namespace: private_namespace, visibility_level: PRIVATE)
private_project.add_developer(user)
expect(response).to have_gitlab_http_status(:ok) all_projects = [private_project] + public_projects
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') user.update!(ops_dashboard_projects: all_projects)
expect(json_response['projects'].count).to eq(7)
actual_ids = json_response['projects'].map { |p| p['id'].to_i } get_environments(:json)
expected_ids = public_projects.map(&:id)
expect(actual_ids).to contain_exactly(*expected_ids) expect(response).to have_gitlab_http_status(:ok)
end expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(json_response['projects'].count).to eq(7)
it 'returns a maximum of three environments for a project' do actual_ids = json_response['projects'].map { |p| p['id'].to_i }
create(:environment, project: project) expected_ids = public_projects.map(&:id)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
get :environments_list expect(actual_ids).to contain_exactly(*expected_ids)
end
expect(response).to have_gitlab_http_status(:ok) it 'returns a maximum of three environments for a project' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
project_json = json_response['projects'].first get_environments(:json)
expect(project_json['environments'].count).to eq(3) expect(response).to have_gitlab_http_status(:ok)
end expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
it 'returns a maximum of three environments for multiple projects' do project_json = json_response['projects'].first
project_b = create(:project)
project_b.add_developer(user)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project_b)
create(:environment, project: project_b)
create(:environment, project: project_b)
create(:environment, project: project_b)
user.update!(ops_dashboard_projects: [project, project_b])
get :environments_list
expect(response).to have_gitlab_http_status(:ok) expect(project_json['environments'].count).to eq(3)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') end
project_json = json_response['projects'].find { |p| p['id'] == project.id } it 'returns a maximum of three environments for multiple projects' do
project_b_json = json_response['projects'].find { |p| p['id'] == project_b.id } project_b = create(:project)
project_b.add_developer(user)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project)
create(:environment, project: project_b)
create(:environment, project: project_b)
create(:environment, project: project_b)
create(:environment, project: project_b)
user.update!(ops_dashboard_projects: [project, project_b])
get_environments(:json)
expect(project_json['environments'].count).to eq(3) expect(response).to have_gitlab_http_status(:ok)
expect(project_b_json['environments'].count).to eq(3) expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
end
context 'with a pipeline' do project_json = json_response['projects'].find { |p| p['id'] == project.id }
let(:project) { create(:project, :repository) } project_b_json = json_response['projects'].find { |p| p['id'] == project_b.id }
let(:commit) { project.commit }
let(:environment) { create(:environment, project: project) }
before do expect(project_json['environments'].count).to eq(3)
project.add_developer(user) expect(project_b_json['environments'].count).to eq(3)
user.update!(ops_dashboard_projects: [project])
end end
it 'returns the last pipeline for an environment' do context 'with a pipeline' do
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha) let(:project) { create(:project, :repository) }
ci_build = create(:ci_build, project: project, pipeline: pipeline) let(:commit) { project.commit }
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha) let(:environment) { create(:environment, project: project) }
get :environments_list before do
project.add_developer(user)
user.update!(ops_dashboard_projects: [project])
end
expect(response).to have_gitlab_http_status(:ok) it 'returns the last pipeline for an environment' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
project_json = json_response['projects'].first get_environments(:json)
environment_json = project_json['environments'].first
last_pipeline_json = environment_json['last_pipeline']
expect(last_pipeline_json['id']).to eq(pipeline.id) expect(response).to have_gitlab_http_status(:ok)
expect(last_pipeline_json['triggered']).to eq([]) expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(last_pipeline_json['triggered_by']).to be_nil
end
it 'returns the last pipeline details' do project_json = json_response['projects'].first
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha, status: :canceled) environment_json = project_json['environments'].first
ci_build = create(:ci_build, project: project, pipeline: pipeline) last_pipeline_json = environment_json['last_pipeline']
create(:deployment, :canceled, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
get :environments_list expect(last_pipeline_json['id']).to eq(pipeline.id)
expect(last_pipeline_json['triggered']).to eq([])
expect(last_pipeline_json['triggered_by']).to be_nil
end
expect(response).to have_gitlab_http_status(:ok) it 'returns the last pipeline details' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha, status: :canceled)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :canceled, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
project_json = json_response['projects'].first get_environments(:json)
environment_json = project_json['environments'].first
last_pipeline_json = environment_json['last_pipeline']
expected_details_path = project_pipeline_path(project, pipeline)
expect(last_pipeline_json.dig('details', 'status', 'group')).to eq('canceled') expect(response).to have_gitlab_http_status(:ok)
expect(last_pipeline_json.dig('details', 'status', 'tooltip')).to eq('canceled') expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(last_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path)
end
it 'returns an upstream pipeline' do project_json = json_response['projects'].first
project_b = create(:project, :repository) environment_json = project_json['environments'].first
project_b.add_developer(user) last_pipeline_json = environment_json['last_pipeline']
commit_b = project_b.commit expected_details_path = project_pipeline_path(project, pipeline)
pipeline_b = create(:ci_pipeline, project: project_b, user: user, sha: commit_b.sha)
ci_build_b = create(:ci_build, project: project_b, pipeline: pipeline_b)
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
create(:ci_sources_pipeline, project: project, pipeline: pipeline, source_project: project_b, source_pipeline: pipeline_b, source_job: ci_build_b)
get :environments_list expect(last_pipeline_json.dig('details', 'status', 'group')).to eq('canceled')
expect(last_pipeline_json.dig('details', 'status', 'tooltip')).to eq('canceled')
expect(last_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path)
end
expect(response).to have_gitlab_http_status(:ok) it 'returns an upstream pipeline' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') project_b = create(:project, :repository)
project_b.add_developer(user)
commit_b = project_b.commit
pipeline_b = create(:ci_pipeline, project: project_b, user: user, sha: commit_b.sha)
ci_build_b = create(:ci_build, project: project_b, pipeline: pipeline_b)
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
create(:ci_sources_pipeline, project: project, pipeline: pipeline, source_project: project_b, source_pipeline: pipeline_b, source_job: ci_build_b)
project_json = json_response['projects'].first get_environments(:json)
environment_json = project_json['environments'].first
last_pipeline_json = environment_json['last_pipeline']
triggered_by_pipeline_json = last_pipeline_json['triggered_by']
expected_details_path = project_pipeline_path(project_b, pipeline_b) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
expect(last_pipeline_json['id']).to eq(pipeline.id) project_json = json_response['projects'].first
expect(triggered_by_pipeline_json['id']).to eq(pipeline_b.id) environment_json = project_json['environments'].first
expect(triggered_by_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path) last_pipeline_json = environment_json['last_pipeline']
expect(triggered_by_pipeline_json.dig('project', 'full_name')).to eq(project_b.full_name) triggered_by_pipeline_json = last_pipeline_json['triggered_by']
end
it 'returns a downstream pipeline' do expected_details_path = project_pipeline_path(project_b, pipeline_b)
project_b = create(:project, :repository)
project_b.add_developer(user)
commit_b = project_b.commit
pipeline_b = create(:ci_pipeline, :failed, project: project_b, user: user, sha: commit_b.sha)
create(:ci_build, :failed, project: project_b, pipeline: pipeline_b)
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
create(:ci_sources_pipeline, project: project_b, pipeline: pipeline_b, source_project: project, source_pipeline: pipeline, source_job: ci_build)
get :environments_list expect(last_pipeline_json['id']).to eq(pipeline.id)
expect(triggered_by_pipeline_json['id']).to eq(pipeline_b.id)
expect(triggered_by_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path)
expect(triggered_by_pipeline_json.dig('project', 'full_name')).to eq(project_b.full_name)
end
expect(response).to have_gitlab_http_status(:ok) it 'returns a downstream pipeline' do
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee') project_b = create(:project, :repository)
project_b.add_developer(user)
commit_b = project_b.commit
pipeline_b = create(:ci_pipeline, :failed, project: project_b, user: user, sha: commit_b.sha)
create(:ci_build, :failed, project: project_b, pipeline: pipeline_b)
pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
ci_build = create(:ci_build, project: project, pipeline: pipeline)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
create(:ci_sources_pipeline, project: project_b, pipeline: pipeline_b, source_project: project, source_pipeline: pipeline, source_job: ci_build)
project_json = json_response['projects'].first get_environments(:json)
environment_json = project_json['environments'].first
last_pipeline_json = environment_json['last_pipeline']
expect(last_pipeline_json['triggered'].count).to eq(1) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments', dir: 'ee')
triggered_pipeline_json = last_pipeline_json['triggered'].first project_json = json_response['projects'].first
environment_json = project_json['environments'].first
last_pipeline_json = environment_json['last_pipeline']
expected_details_path = project_pipeline_path(project_b, pipeline_b) expect(last_pipeline_json['triggered'].count).to eq(1)
expect(last_pipeline_json['id']).to eq(pipeline.id) triggered_pipeline_json = last_pipeline_json['triggered'].first
expect(triggered_pipeline_json['id']).to eq(pipeline_b.id)
expect(triggered_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path) expected_details_path = project_pipeline_path(project_b, pipeline_b)
expect(triggered_pipeline_json.dig('details', 'status', 'group')).to eq('failed')
expect(triggered_pipeline_json.dig('project', 'full_name')).to eq(project_b.full_name) expect(last_pipeline_json['id']).to eq(pipeline.id)
expect(triggered_pipeline_json['id']).to eq(pipeline_b.id)
expect(triggered_pipeline_json.dig('details', 'status', 'details_path')).to eq(expected_details_path)
expect(triggered_pipeline_json.dig('details', 'status', 'group')).to eq('failed')
expect(triggered_pipeline_json.dig('project', 'full_name')).to eq(project_b.full_name)
end
end end
end end
end end
...@@ -649,88 +663,94 @@ RSpec.describe OperationsController do ...@@ -649,88 +663,94 @@ RSpec.describe OperationsController do
end end
describe 'POST #create' do describe 'POST #create' do
it_behaves_like 'unlicensed', :post, :create describe 'format json' do
it_behaves_like 'unlicensed', :post, :create, :json
context 'without added projects' do
let(:project_a) { create(:project) }
let(:project_b) { create(:project) }
before do def post_create(params)
project_a.add_developer(user) post :create, params: params, format: :json
project_b.add_developer(user)
end end
it 'adds projects to the dashboard' do context 'without added projects' do
post :create, params: { project_ids: [project_a.id, project_b.id.to_s] } let(:project_a) { create(:project) }
let(:project_b) { create(:project) }
expect(response).to have_gitlab_http_status(:ok) before do
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee') project_a.add_developer(user)
expect(json_response['added']).to contain_exactly(project_a.id, project_b.id) project_b.add_developer(user)
expect(json_response['duplicate']).to be_empty end
expect(json_response['invalid']).to be_empty
user.reload it 'adds projects to the dashboard' do
expect(user.ops_dashboard_projects).to contain_exactly(project_a, project_b) post_create({ project_ids: [project_a.id, project_b.id.to_s] })
end
it 'cannot add a project twice' do expect(response).to have_gitlab_http_status(:ok)
post :create, params: { project_ids: [project_a.id, project_a.id] } expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
expect(json_response['added']).to contain_exactly(project_a.id, project_b.id)
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to be_empty
expect(response).to have_gitlab_http_status(:ok) user.reload
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee') expect(user.ops_dashboard_projects).to contain_exactly(project_a, project_b)
expect(json_response['added']).to contain_exactly(project_a.id) end
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to be_empty
user.reload it 'cannot add a project twice' do
expect(user.ops_dashboard_projects).to eq([project_a]) post_create({ project_ids: [project_a.id, project_a.id] })
end
it 'does not add invalid project ids' do expect(response).to have_gitlab_http_status(:ok)
post :create, params: { project_ids: ['', -1, '-2'] } expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
expect(json_response['added']).to contain_exactly(project_a.id)
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to be_empty
expect(response).to have_gitlab_http_status(:ok) user.reload
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee') expect(user.ops_dashboard_projects).to eq([project_a])
expect(json_response['added']).to be_empty end
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to contain_exactly(0, -1, -2)
user.reload it 'does not add invalid project ids' do
expect(user.ops_dashboard_projects).to be_empty post_create({ project_ids: ['', -1, '-2'] })
end
end
context 'with added project' do expect(response).to have_gitlab_http_status(:ok)
let(:project) { create(:project) } expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
expect(json_response['added']).to be_empty
expect(json_response['duplicate']).to be_empty
expect(json_response['invalid']).to contain_exactly(0, -1, -2)
before do user.reload
user.ops_dashboard_projects << project expect(user.ops_dashboard_projects).to be_empty
project.add_developer(user) end
end end
it 'does not add already added project' do context 'with added project' do
post :create, params: { project_ids: [project.id] } let(:project) { create(:project) }
expect(response).to have_gitlab_http_status(:ok) before do
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee') user.ops_dashboard_projects << project
expect(json_response['added']).to be_empty project.add_developer(user)
expect(json_response['duplicate']).to contain_exactly(project.id) end
expect(json_response['invalid']).to be_empty
user.reload it 'does not add already added project' do
expect(user.ops_dashboard_projects).to eq([project]) post_create({ project_ids: [project.id] })
end
end
context 'with an anonymous user' do expect(response).to have_gitlab_http_status(:ok)
before do expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
sign_out(user) expect(json_response['added']).to be_empty
expect(json_response['duplicate']).to contain_exactly(project.id)
expect(json_response['invalid']).to be_empty
user.reload
expect(user.ops_dashboard_projects).to eq([project])
end
end end
it 'redirects to sign-in page' do context 'with an anonymous user' do
post :create before do
sign_out(user)
end
expect(response).to redirect_to(new_user_session_path) it 'redirects to sign-in page' do
post :create
expect(response).to redirect_to(new_user_session_path)
end
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Operations routing', 'routing' do
describe '/-/operations' do
it 'routes to the operations index action' do
expect(get("#{operations_path}.html")).to route_to(
controller: 'operations',
action: 'index',
format: 'html')
expect(get("#{operations_path}.json")).to route_to(
controller: 'operations',
action: 'index',
format: 'json')
end
it 'routes to the operations create action' do
expect(post("#{add_operations_project_path}.json")).to route_to(
controller: 'operations',
action: 'create',
format: 'json')
end
it 'routes to operations destroy action' do
expect(delete("#{remove_operations_project_path}.json")).to route_to(
controller: 'operations',
action: 'destroy',
format: 'json')
end
end
describe '/-/operations/environments' do
it 'routes to the environments list action' do
expect(get("#{operations_environments_path}.html")).to route_to(
controller: 'operations',
action: 'environments',
format: 'html')
expect(get("#{operations_environments_path}.json")).to route_to(
controller: 'operations',
action: 'environments',
format: 'json')
end
it 'routes to the environments create action' do
expect(post("#{add_operations_environments_project_path}.json")).to route_to(
controller: 'operations',
action: 'create',
format: 'json')
end
it 'routes to environments destroy action' do
expect(delete("#{remove_operations_environments_project_path}.json")).to route_to(
controller: 'operations',
action: 'destroy',
format: 'json')
end
end
end
...@@ -6,8 +6,8 @@ RSpec.describe 'operations/environments.html.haml' do ...@@ -6,8 +6,8 @@ RSpec.describe 'operations/environments.html.haml' do
it 'renders the frontend configuration' do it 'renders the frontend configuration' do
render render
expect(rendered).to match %r{data-add-path="/-/operations"} expect(rendered).to match %r{data-add-path="/-/operations/environments.json"}
expect(rendered).to match %r{data-list-path="/-/operations/environments_list"} expect(rendered).to match %r{data-list-path="/-/operations/environments.json"}
expect(rendered).to match %r{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"} expect(rendered).to match %r{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"}
expect(rendered).to match %r{data-empty-dashboard-help-path="/help/ci/environments/environments_dashboard.md"} expect(rendered).to match %r{data-empty-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
expect(rendered).to match %r{data-environments-dashboard-help-path="/help/ci/environments/environments_dashboard.md"} expect(rendered).to match %r{data-environments-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
......
...@@ -6,8 +6,8 @@ RSpec.describe 'operations/index.html.haml' do ...@@ -6,8 +6,8 @@ RSpec.describe 'operations/index.html.haml' do
it 'renders the frontend configuration' do it 'renders the frontend configuration' do
render render
expect(rendered).to match %r{data-add-path="/-/operations"} expect(rendered).to match %r{data-add-path="/-/operations.json"}
expect(rendered).to match %r{data-list-path="/-/operations/list"} expect(rendered).to match %r{data-list-path="/-/operations.json"}
expect(rendered).to match %{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"} expect(rendered).to match %{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"}
expect(rendered).to match %r{data-empty-dashboard-help-path="/help/user/operations_dashboard/index.md"} expect(rendered).to match %r{data-empty-dashboard-help-path="/help/user/operations_dashboard/index.md"}
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