summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Knox <psimyn@gmail.com>2019-01-08 16:24:52 +1100
committerSimon Knox <psimyn@gmail.com>2019-01-08 16:24:52 +1100
commit6fc7c3b143d5b05c51117186358591df714f1af8 (patch)
treeb4568e2585c2805531aae9a34e31c3f9546fc3e1
parent84cd0b122e87345a160fcd58f024223d3e404e1b (diff)
parentd86a2f68fe929ced686c8695b4180d4c2cfdd826 (diff)
downloadgitlab-ce-error_tracking_feature_flag_fe.tar.gz
Merge branch '55178-error-tracking-controller' of gitlab.com:gitlab-org/gitlab-ce into error_tracking_feature_flag_feerror_tracking_feature_flag_fe
-rw-r--r--app/controllers/projects/error_tracking_controller.rb19
-rw-r--r--app/views/projects/error_tracking/index.html.haml (renamed from app/views/projects/error_tracking/list.html.haml)0
-rw-r--r--config/routes/project.rb6
-rw-r--r--spec/controllers/projects/error_tracking_controller_spec.rb205
4 files changed, 96 insertions, 134 deletions
diff --git a/app/controllers/projects/error_tracking_controller.rb b/app/controllers/projects/error_tracking_controller.rb
index fa3f8aba513..a0c3ceddc88 100644
--- a/app/controllers/projects/error_tracking_controller.rb
+++ b/app/controllers/projects/error_tracking_controller.rb
@@ -5,16 +5,17 @@ class Projects::ErrorTrackingController < Projects::ApplicationController
before_action :authorize_read_environment!
before_action :push_feature_flag_to_frontend
- def list
- end
-
def index
- external_url, errors = errors_for(@project)
-
- render json: {
- external_url: external_url,
- errors: errors
- }
+ respond_to do |format|
+ format.html
+ format.json do
+ external_url, errors = errors_for(@project)
+ render json: {
+ errors: errors,
+ external_url: external_url
+ }
+ end
+ end
end
private
diff --git a/app/views/projects/error_tracking/list.html.haml b/app/views/projects/error_tracking/index.html.haml
index bc02c5f0e5a..bc02c5f0e5a 100644
--- a/app/views/projects/error_tracking/list.html.haml
+++ b/app/views/projects/error_tracking/index.html.haml
diff --git a/config/routes/project.rb b/config/routes/project.rb
index 8662b6fef8a..6f5025ff3cf 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -441,11 +441,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
end
- resources :error_tracking, only: [:index], controller: :error_tracking do
- collection do
- get :list
- end
- end
+ resources :error_tracking, only: [:index], controller: :error_tracking
# Since both wiki and repository routing contains wildcard characters
# its preferable to keep it below all other project routes
diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb
index a79a0a3e42e..1c386c5b2e9 100644
--- a/spec/controllers/projects/error_tracking_controller_spec.rb
+++ b/spec/controllers/projects/error_tracking_controller_spec.rb
@@ -2,175 +2,140 @@
require 'rails_helper'
-RSpec.describe Projects::ErrorTrackingController, type: :controller do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
- let(:json_response) { JSON.parse(response.body) }
+describe Projects::ErrorTrackingController do
+ set(:project) { create(:project) }
+ set(:user) { create(:user) }
before do
sign_in(user)
project.add_maintainer(user)
end
- describe 'GET #list' do
- it 'renders index with 200 status code' do
- get :list, params: project_params
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to render_template(:list)
- end
-
- context 'with feature flag disabled' do
- before do
- stub_feature_flags(error_tracking: false)
- end
-
- it 'returns 404' do
- get :list, params: project_params
-
- expect(response).to have_gitlab_http_status(:not_found)
- end
- end
-
- context 'with insufficient permissions' do
- before do
- project.add_guest(user)
- end
-
- it 'returns 404' do
- get :list, params: project_params
-
- expect(response).to have_gitlab_http_status(:not_found)
- end
- end
-
- context 'with an anonymous user' do
- before do
- sign_out(user)
- end
-
- it 'redirects to sign-in page' do
- get :list, params: project_params
-
- expect(response).to redirect_to(new_user_session_path)
- end
- end
- end
-
describe 'GET #index' do
- shared_examples 'no data' do
- it 'returns no data' do
+ describe 'html' do
+ it 'renders index with 200 status code' do
get :index, params: project_params
expect(response).to have_gitlab_http_status(:ok)
- expect(response).to match_response_schema('error_tracking/index')
- expect(json_response['external_url']).to be_nil
- expect(json_response['errors']).to eq([])
+ expect(response).to render_template(:index)
end
- end
- context 'with error tracking enabled' do
- let(:issues_service) { spy(:sentry_issues_service) }
- let(:external_url) { 'http://example.com' }
+ context 'with feature flag disabled' do
+ before do
+ stub_feature_flags(error_tracking: false)
+ end
- let!(:setting) do
- create(:project_error_tracking_setting, project: project, enabled: true)
- end
+ it 'returns 404' do
+ get :index, params: project_params
- before do
- expect(ErrorTracking::SentryIssuesService)
- .to receive(:new).with(setting.api_url, setting.token)
- .and_return(issues_service)
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
end
- context 'with errors' do
+ context 'with insufficient permissions' do
before do
- expect(issues_service).to receive(:execute).and_return([error])
- expect(issues_service).to receive(:external_url).and_return(external_url)
+ project.add_guest(user)
end
- let(:error) { build_error_tracking_error }
-
- it 'returns a list of errors' do
+ it 'returns 404' do
get :index, params: project_params
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to match_response_schema('error_tracking/index')
- expect(json_response['external_url']).to eq(external_url)
- expect(json_response['errors']).to eq([error].as_json)
+ expect(response).to have_gitlab_http_status(:not_found)
end
end
- end
- context 'with error tracking disabled' do
- before do
- create(:project_error_tracking_setting, project: project, enabled: false)
- expect(ErrorTracking::SentryIssuesService).not_to receive(:new)
- end
+ context 'with an anonymous user' do
+ before do
+ sign_out(user)
+ end
- it_behaves_like 'no data'
- end
+ it 'redirects to sign-in page' do
+ get :index, params: project_params
- context 'without error tracking setting' do
- before do
- expect(ErrorTracking::SentryIssuesService).not_to receive(:new)
+ expect(response).to redirect_to(new_user_session_path)
+ end
end
-
- it_behaves_like 'no data'
end
- context 'without error tracking setting' do
- it 'returns no data' do
- get :index, params: project_params
+ describe 'format json' do
+ shared_examples 'no data' do
+ it 'returns no data' do
+ get :index, params: project_params(format: :json)
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to match_response_schema('error_tracking/index')
- expect(json_response['external_url']).to be_nil
- expect(json_response['errors']).to eq([])
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('error_tracking/index')
+ expect(json_response['external_url']).to be_nil
+ expect(json_response['errors']).to eq([])
+ end
end
- end
- context 'with feature flag disabled' do
- before do
- stub_feature_flags(error_tracking: false)
- end
+ context 'with error tracking enabled' do
+ let(:issues_service) { spy(:sentry_issues_service) }
+ let(:external_url) { 'http://example.com' }
- it 'returns 404' do
- get :index, params: project_params
+ let!(:setting) do
+ create(:project_error_tracking_setting, project: project, enabled: true)
+ end
- expect(response).to have_gitlab_http_status(:not_found)
- end
- end
+ before do
+ expect(ErrorTracking::SentryIssuesService)
+ .to receive(:new).with(setting.api_url, setting.token)
+ .and_return(issues_service)
+ end
+
+ context 'with errors' do
+ before do
+ expect(issues_service).to receive(:execute).and_return([error])
+ expect(issues_service).to receive(:external_url).and_return(external_url)
+ end
+
+ let(:error) { build_error_tracking_error }
+
+ it 'returns a list of errors' do
+ get :index, params: project_params(format: :json)
- context 'with insufficient permissions' do
- before do
- project.add_guest(user)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('error_tracking/index')
+ expect(json_response['external_url']).to eq(external_url)
+ expect(json_response['errors']).to eq([error].as_json)
+ end
+ end
end
- it 'returns 404' do
- get :index, params: project_params
+ context 'with error tracking disabled' do
+ before do
+ create(:project_error_tracking_setting, project: project, enabled: false)
+ expect(ErrorTracking::SentryIssuesService).not_to receive(:new)
+ end
- expect(response).to have_gitlab_http_status(:not_found)
+ it_behaves_like 'no data'
end
- end
- context 'with an anonymous user' do
- before do
- sign_out(user)
+ context 'without error tracking setting' do
+ before do
+ expect(ErrorTracking::SentryIssuesService).not_to receive(:new)
+ end
+
+ it_behaves_like 'no data'
end
- it 'redirects to sign-in page' do
- get :index, params: project_params
+ context 'without error tracking setting' do
+ it 'returns no data' do
+ get :index, params: project_params(format: :json)
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('error_tracking/index')
+ expect(json_response['external_url']).to be_nil
+ expect(json_response['errors']).to eq([])
+ end
end
end
end
private
- def project_params
- { namespace_id: project.namespace, project_id: project }
+ def project_params(opts = {})
+ opts.reverse_merge(namespace_id: project.namespace, project_id: project)
end
def build_error_tracking_error