gitlab-ce/spec/lib/gitlab/middleware/action_controller_static_co...

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Middleware::ActionControllerStaticContext, feature_category: :error_budgets do
# to check the end to end tests, go to spec/requests/application_controller_spec.rb
let(:env) do
# env mimicking a controller action parsed by the rails routes
{ 'action_dispatch.request.path_parameters' => { controller: "dashboard/groups", action: "index" } }
end
let(:app) { ->(_env) { [200, {}, ["Hello World"]] } }
context 'when feature flag is disabled' do
it 'does not update context' do
stub_feature_flags(controller_static_context: false)
described_class.new(app).call(env)
expect(Gitlab::ApplicationContext.current.keys).not_to include('meta.feature_category', 'meta.caller_id')
end
end
context 'when feature flag is enabled' do
it 'populates context with static controller attributes' do
stub_feature_flags(controller_static_context: true)
described_class.new(app).call(env)
expect(Labkit::Context.current.to_h).to include({
'meta.feature_category' => 'groups_and_projects',
'meta.caller_id' => 'Dashboard::GroupsController#index'
})
end
end
end