Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/factory_bot/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def error_message_type

def in_transaction
if defined?(ActiveRecord::Base)
ActiveRecord::Base.transaction do
ActiveRecord::Base.transaction(joinable: false) do
yield
raise ActiveRecord::Rollback
end
Expand Down
17 changes: 17 additions & 0 deletions spec/acceptance/lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@
expect { FactoryBot.lint }.to_not raise_error
end

it "runs after_commit callbacks when linting in a ActiveRecord::Base transaction" do
define_model "ModelWithAfterCommitCallbacks" do
class_attribute :after_commit_callbacks_received

after_commit do
self.class.after_commit_callbacks_received = true
end
end

FactoryBot.define do
factory :model_with_after_commit_callbacks
end

FactoryBot.lint
expect(ModelWithAfterCommitCallbacks.after_commit_callbacks_received).to be true
end

it "does not raise when all factories are valid" do
define_model "User", name: :string do
validates :name, presence: true
Expand Down