Commit 00437641 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix_open_transactions_baseline' into 'master'

Fix open_transactions_baseline to check the base class

See merge request gitlab-org/gitlab!76406
parents fe220095 5d23374f
......@@ -8,7 +8,7 @@ module Transactions
# transaction. Handles special cases when running inside a test environment,
# where tests may be wrapped in transactions
def inside_transaction?
base = Rails.env.test? ? @open_transactions_baseline.to_i : 0
base = Rails.env.test? ? open_transactions_baseline.to_i : 0
connection.open_transactions > base
end
......@@ -24,5 +24,15 @@ module Transactions
def reset_open_transactions_baseline
@open_transactions_baseline = 0
end
def open_transactions_baseline
return unless Rails.env.test?
if @open_transactions_baseline.nil?
return self == ApplicationRecord ? nil : superclass.open_transactions_baseline
end
@open_transactions_baseline
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Transactions do
let(:model) { build(:project) }
it 'is not in a transaction' do
expect(model.class).not_to be_inside_transaction
end
it 'is in a transaction', :aggregate_failures do
Project.transaction do
expect(model.class).to be_inside_transaction
end
ApplicationRecord.transaction do
expect(model.class).to be_inside_transaction
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