Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

when the transactional fixtures keeps a database transaction alive wi…

…thout using the transaction method, don't retain references to all the records saved in the fixtures transaction once their subtransaction completes
  • Loading branch information...
commit d731f5c1676c42ecfadc645c7e621527ed92d1b0 1 parent 7b84e36
@willbryant authored
View
3  activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -217,8 +217,7 @@ def transaction(options = {})
else
release_savepoint
save_point_records = @_current_transaction_records.pop
- unless save_point_records.blank?
- @_current_transaction_records.push([]) if @_current_transaction_records.empty?
+ unless save_point_records.blank? || @_current_transaction_records.empty?
@_current_transaction_records.last.concat(save_point_records)
end
end
View
25 activerecord/test/cases/fixtures_test.rb
@@ -335,6 +335,31 @@ def test_destroy_just_kidding
end
end
+class TransactionalFixturesTest < ActiveRecord::TestCase
+ self.use_instantiated_fixtures = true
+ self.use_transactional_fixtures = true
+
+ fixtures :topics
+
+ def test_records_saved_in_fixture_transaction_not_recorded
+ @first.update_attributes!(:title => "New title")
+ assert !Topic.connection.instance_variable_get("@_current_transaction_records").flatten.include?(@first)
+ end
+
+ def test_records_saved_in_explicit_transaction_recorded
+ Topic.transaction(:requires_new => true) do
+ @first.update_attributes!(:title => "New title")
+ assert Topic.connection.instance_variable_get("@_current_transaction_records").flatten.include?(@first)
+ end
+ Topic.transaction do
+ @second.update_attributes!(:title => "New title")
+ assert Topic.connection.instance_variable_get("@_current_transaction_records").flatten.include?(@second)
+ end
+ assert !Topic.connection.instance_variable_get("@_current_transaction_records").flatten.include?(@first)
+ assert !Topic.connection.instance_variable_get("@_current_transaction_records").flatten.include?(@second)
+ end
+end
+
class MultipleFixturesTest < ActiveRecord::TestCase
fixtures :topics
fixtures :developers, :accounts
Please sign in to comment.
Something went wrong with that request. Please try again.