summaryrefslogtreecommitdiff
path: root/spec/controllers/concerns
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r--spec/controllers/concerns/enforces_admin_authentication_spec.rb6
-rw-r--r--spec/controllers/concerns/redis_tracking_spec.rb32
-rw-r--r--spec/controllers/concerns/renders_commits_spec.rb12
3 files changed, 38 insertions, 12 deletions
diff --git a/spec/controllers/concerns/enforces_admin_authentication_spec.rb b/spec/controllers/concerns/enforces_admin_authentication_spec.rb
index c6ad1a00484..106b1d53fd2 100644
--- a/spec/controllers/concerns/enforces_admin_authentication_spec.rb
+++ b/spec/controllers/concerns/enforces_admin_authentication_spec.rb
@@ -19,7 +19,7 @@ RSpec.describe EnforcesAdminAuthentication do
end
end
- context 'feature flag :user_mode_in_session is enabled' do
+ context 'application setting :admin_mode is enabled' do
describe 'authenticate_admin!' do
context 'as an admin' do
let(:user) { create(:admin) }
@@ -61,9 +61,9 @@ RSpec.describe EnforcesAdminAuthentication do
end
end
- context 'feature flag :user_mode_in_session is disabled' do
+ context 'application setting :admin_mode is disabled' do
before do
- stub_feature_flags(user_mode_in_session: false)
+ stub_application_setting(admin_mode: false)
end
describe 'authenticate_admin!' do
diff --git a/spec/controllers/concerns/redis_tracking_spec.rb b/spec/controllers/concerns/redis_tracking_spec.rb
index 53b49dd30a6..4077f4f5cce 100644
--- a/spec/controllers/concerns/redis_tracking_spec.rb
+++ b/spec/controllers/concerns/redis_tracking_spec.rb
@@ -9,8 +9,8 @@ RSpec.describe RedisTracking do
include RedisTracking
skip_before_action :authenticate_user!, only: :show
- track_redis_hll_event :index, :show, name: 'g_compliance_approval_rules',
- if: [:custom_condition_one?, :custom_condition_two?]
+ track_redis_hll_event(:index, :show, name: 'g_compliance_approval_rules',
+ if: [:custom_condition_one?, :custom_condition_two?]) { |controller| controller.get_custom_id }
def index
render html: 'index'
@@ -24,6 +24,10 @@ RSpec.describe RedisTracking do
render html: 'show'
end
+ def get_custom_id
+ 'some_custom_id'
+ end
+
private
def custom_condition_one?
@@ -92,19 +96,15 @@ RSpec.describe RedisTracking do
end
end
- context 'when user is not logged in and there is a visitor_id' do
+ context 'when user is not logged in' do
let(:visitor_id) { SecureRandom.uuid }
- before do
- routes.draw { get 'show' => 'anonymous#show' }
- end
-
- it 'tracks the event' do
+ it 'tracks the event when there is a visitor id' do
cookies[:visitor_id] = { value: visitor_id, expires: 24.months }
expect_tracking
- get :show
+ get :show, params: { id: 1 }
end
end
@@ -114,5 +114,19 @@ RSpec.describe RedisTracking do
get :index
end
+
+ it 'tracks the event when there is custom id' do
+ expect_tracking
+
+ get :show, params: { id: 1 }
+ end
+
+ it 'does not track the event when there is no custom id' do
+ expect(controller).to receive(:get_custom_id).and_return(nil)
+
+ expect_no_tracking
+
+ get :show, params: { id: 2 }
+ end
end
end
diff --git a/spec/controllers/concerns/renders_commits_spec.rb b/spec/controllers/concerns/renders_commits_spec.rb
index 7be5f75c19d..7b241fc29af 100644
--- a/spec/controllers/concerns/renders_commits_spec.rb
+++ b/spec/controllers/concerns/renders_commits_spec.rb
@@ -57,4 +57,16 @@ RSpec.describe RendersCommits do
end.not_to exceed_all_query_limit(control_count)
end
end
+
+ describe '.prepare_commits_for_rendering' do
+ it 'avoids N+1' do
+ control = ActiveRecord::QueryRecorder.new do
+ subject.prepare_commits_for_rendering(merge_request.commits.take(1))
+ end
+
+ expect do
+ subject.prepare_commits_for_rendering(merge_request.commits)
+ end.not_to exceed_all_query_limit(control.count)
+ end
+ end
end