-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix FixtureSupport#run_in_transaction? #2495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,33 @@ module RSpec::Rails | |
end | ||
end | ||
|
||
context "with use_transactional_tests set to true" do | ||
it "works with #uses_transaction helper" do | ||
group = RSpec::Core::ExampleGroup.describe do | ||
include FixtureSupport | ||
self.use_transactional_tests = true | ||
|
||
uses_transaction "doesn't run in transaction" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not documented. But yes, based on the code and the current behavior it turns that off for the given tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If its not documented I'm hesitant to support it, if its public api fine but private api I'm a bit reluctant about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Public https://api.rubyonrails.org/classes/ActiveRecord/TestFixtures/ClassMethods.html#method-i-uses_transaction, but undocumented. Originally introduced here. Frankly, a couple of times I needed it desperately to test code that needs to have control of the outermost transaction or has a conditional statement with a check if the transaction is an outermost or a nested. With DatabaseCleaner it's possible to turn off per-example transaction for select examples. With |
||
|
||
it "doesn't run in transaction" do | ||
expect(ActiveRecord::Base.connection.transaction_open?).to eq(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having a big WTF moment at this, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. No doubt |
||
end | ||
|
||
it "runs in transaction" do | ||
expect(ActiveRecord::Base.connection.transaction_open?).to eq(true) | ||
end | ||
end | ||
|
||
expect_to_pass(group) | ||
end | ||
|
||
def expect_to_pass(group) | ||
result = group.run(failure_reporter) | ||
failure_reporter.exceptions.map { |e| raise e } | ||
expect(result).to be true | ||
end | ||
end | ||
st0012 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it "will allow #setup_fixture to run successfully", skip: Rails.version.to_f <= 6.0 do | ||
group = RSpec::Core::ExampleGroup.describe do | ||
include FixtureSupport | ||
|
Uh oh!
There was an error while loading. Please reload this page.