Commit 18210fdb authored by Dan Jensen's avatar Dan Jensen

Fix feature flag check for productivity analytics

Previously the productivity_analytics endpoint would return a 404 if
there was no entry in the features table. This fixes the bug so the
page will be rendered in that case.
parent bbf5faea
---
title: Fix feature flag check for productivity analytics
merge_request: 19025
author:
type: fixed
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
namespace :analytics do namespace :analytics do
root to: 'analytics#index' root to: 'analytics#index'
constraints(::Constraints::FeatureConstrainer.new(Gitlab::Analytics::PRODUCTIVITY_ANALYTICS_FEATURE_FLAG)) do resource :productivity_analytics, only: :show, constraints: lambda { |req| Gitlab::Analytics.productivity_analytics_enabled? }
resource :productivity_analytics, only: :show
end
constraints(::Constraints::FeatureConstrainer.new(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG)) do constraints(::Constraints::FeatureConstrainer.new(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG)) do
resource :cycle_analytics, only: :show resource :cycle_analytics, only: :show
......
...@@ -3,10 +3,36 @@ ...@@ -3,10 +3,36 @@
require 'spec_helper' require 'spec_helper'
describe 'Analytics' do describe 'Analytics' do
include RSpec::Rails::RequestExampleGroup
include Warden::Test::Helpers include Warden::Test::Helpers
it 'redirects to sign_in if user is not authenticated' do it 'redirects to sign_in if user is not authenticated' do
expect(get('/-/analytics')).to redirect_to('/users/sign_in') expect(get('/-/analytics')).to route_to('analytics/analytics#index')
end
context 'when user is logged in' do
let(:user) { create(:user) }
before do
login_as(user)
end
context 'productivity_analytics feature flag is enabled by default' do
it 'succeeds' do
# make sure we call this method for checking the feature availability
expect(Gitlab::Analytics).to receive(:productivity_analytics_enabled?).and_call_original
expect(get('/-/analytics/productivity_analytics')).to route_to('analytics/productivity_analytics#show')
end
end
context 'productivity_analytics feature flag is disabled' do
before do
stub_feature_flags(Gitlab::Analytics::PRODUCTIVITY_ANALYTICS_FEATURE_FLAG => false)
end
it 'routes to `not_found`' do
expect(get('/-/analytics/productivity_analytics')).to route_to('application#route_not_found', unmatched_route: '-/analytics/productivity_analytics')
end
end
end end
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