aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transactions_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* Fix transaction state for unsynced records when entering transactionbrainopia2015-03-041-0/+9
|
* Fix rollback of frozen recordsbrainopia2015-03-041-0/+9
|
* prefer `drop_table if_exists: true` over raw SQL.Yves Senn2015-02-181-1/+1
| | | | | | | /cc @yahonda This makes it easier for third party adapters to run our tests, even if that database does not support IF EXISTS.
* Whitespace fixes from #18349Sean Griffin2015-01-051-2/+1
|
* Merge pull request #18349 from jdelStrother/primarykeylessSean Griffin2015-01-051-0/+22
|\ | | | | Fix rollback of primarykey-less tables
| * Fix rollback of primarykey-less tablesJonathan del Strother2015-01-051-0/+22
| | | | | | If you have a table without a primary key, and an `after_commit` callback on that table (ie `has_transactional_callbacks?` returns true), then trying to rollback a transaction involving that record would result in “ActiveModel::MissingAttributeError: can't write unknown attribute ``”
* | can't kill thread with in-memory db. fixes `rake test:sqlite3_mem`.Yves Senn2015-01-051-0/+2
| |
* | Remove Thread hack for Ruby 1.9claudiob2015-01-041-23/+18
|/ | | | | | | | The hack so skip a Thread test for Ruby 1.9 can be removed now that Rails requires Ruby >= 2.0. Conflicts: activerecord/test/cases/transactions_test.rb
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-021-1/+11
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* Merge branch 'brainopia-remember_frozen_state_in_transaction'Sean Griffin2014-12-261-0/+15
|\
| * Propagate frozen state during transaction changesbrainopia2014-12-261-0/+14
|/
* skip test to get `sqlite3_mem` suite passing.Yves Senn2014-12-031-1/+1
|
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-3/+3
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Roll back open transactions when the running thread is killed.Chris Hanks2014-08-221-0/+31
|
* Use *_transaction methods in TransactionManagerArthur Neves2014-08-151-0/+24
| | | | | | Use `commit_transaction`/`rollback_transaction` on `within_new_transaction` method, so they make sure they `pop` the transaction from the stack before calling the methods `commit`/`rollback`.
* Cleanup Transaction inheritance.Arthur Neves2014-08-051-2/+2
| | | | | | | | | Transaction class doesnt need to encapsulate the transaction state using inheritance. This removes all Transaction subclasses, and let the Transaction object controls different actions based on its own state. Basically the only actions would behave differently are `being`,`commit`,`rollback` as they could act in a savepoint or in a real transaction.
* Remove being/number methods from transaction classArthur Neves2014-07-311-2/+2
|
* savepoint_name should return nil for non-savepoint transactionsArthur Neves2014-07-281-0/+20
| | | | Also add test to assets the savepoint name
* Clear transaction state if callback raise rollbackArthur Neves2014-05-151-0/+13
|
* Reverts "Fix bugs with changed attributes tracking when transaction gets ↵Arthur Neves2014-05-091-42/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | rollback" We are reverting these commits, because there are other caveats related to dirty attributes not being restored when a transaction is rollback. For instance, nested transactions cannot proper restore the dirty attributes state after a rollback. At the moment, the dirty attributes are scoped by the transaction. When we call `.save` on a record, the dirty attributes will be reset even if the transaction gets rollback. [related #13166] [related #15018] [related #15016] [closes #15019] This reverts commits * bab48f0a3d53a08bc23ea0887219e8deb963c3d9 * b0fa7cf3ff8432cc2eef3682b34763b7f8c93cc8. * 73fb39b6faa9de593ae75ad4e3b8e065ea0e53af * 37c238927fbed059de3f26a90d8923fb377568a5. * 8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa Revert "Merge pull request #13166 from bogdan/transaction-magic"
* Keep track of dirty attrs after after rollback.Arthur Neves2014-05-071-18/+4
| | | | [related #13166]
* Merge pull request #13166 from bogdan/transaction-magicRafael Mendonça França2014-05-071-0/+56
|\ | | | | | | [Regression 3.2 -> 4.0] Fix bugs with changed attributes tracking when transaction gets rollback
| * Fix bugs with changed attributes tracking when transaction gets rollbackBogdan Gusiev2013-12-041-0/+56
| |
* | AR .persisted? throws SystemStackError for an unsaved model with achrisfinne2014-03-271-0/+6
| | | | | | | | custom primary_key that didn't save due to validation error
* | Restore ActiveRecord states after a rollback for models w/o callbacksGodfrey Chan2014-01-181-0/+11
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression (#13744) that was caused by 67d8bb9. In 67d8bb9, we introduced lazy rollback for records, such that the record's internal states and attributes are not restored immediately after a transaction rollback, but deferred until they are first accessed. This optimization is only performed when the model does not have any transactional callbacks (e.g. `after_commit` and `after_create`). Unfortunately, the models used to test the affected codepaths all comes with some sort of transactional callbacks. Therefore this codepath remains largely untested until now and as a result there are a few issues in the implementation that remains hidden until now. First, the `sync_with_transaction_state` (or more accurately, `update_attributes_from_transaction_state`) would perform the synchronization prematurely before a transaction is finalized (i.e. comitted or rolled back). As a result, when the actuall rollback happens, the record will incorrectly assumes that its internal states match the transaction state, and neglect to perform the restore. Second, `update_attributes_from_transaction_state` calls `committed!` in some cases. This in turns checks for the `destroyed?` state which also requires synchronization with the transaction stae, which causes an infnite recurrsion. This fix works by deferring the synchronization until the transaction has been finalized (addressing the first point), and also unrolled the `committed!` and `rolledback!` logic in-place (addressing the second point). It should be noted that the primary purpose of the `committed!` and `rolledback!` methods are to trigger the relevant transactional callbacks. Since this code path is only entered when there are no transactional callbacks on the model, this shouldn't be necessary. By unrolling the method calls, the intention here (to restore the states when necessary) becomes more clear.
* Ensure that a column added in a test is being removed after allAkira Matsuda2013-11-131-0/+7
|
* Don't skip tests if we don't need to.Rafael Mendonça França2013-11-081-14/+14
| | | | | | | We can conditional define the tests depending on the adapter or connection. Lets keep the skip for fail tests that need to be fixed.
* Assert presence of "frozen" in error message, not the full MRI message.Federico Ravasio2013-10-081-1/+3
| | | | | | | | | | Related to all the other issues regarding message independent assertions to make Rails compatible with other Ruby implementations other than MRI. The best way here would be to have a specific error raised when modifying frozen objects, like FrozenObjectError or something. But since Ruby doesn't provide such a thing, we must limit the assertion to the lowest common denominator, which is word "frozen".
* change the savepoint interface to allow passing the name.Yves Senn2013-09-301-0/+30
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2013-08-171-5/+0
|\ | | | | | | | | | | | | | | Conflicts: actionview/README.rdoc activerecord/lib/active_record/migration.rb guides/source/development_dependencies_install.md guides/source/getting_started.md
| * Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-171-5/+0
| | | | | | | | | | | | | | This reverts commit 70d6e16fbad75b89dd1798ed697e7732b8606fa3, reversing changes made to ea4db3bc078fb3093ecdddffdf4f2f4ff3e1e8f9. Seems to be a code merge done by mistake.
* | Fix indentationRafael Mendonça França2013-08-061-3/+2
| |
* | asakusa.rb hack night!Aaron Patterson + Akira Matsuda2013-08-061-0/+3
|/ | | | Fix in-memory tests
* fix order dependent testNeeraj Singh2013-07-281-0/+5
| | | | | `ReflectionTest` uses column information in tests and those tests break if tests are run in random order.
* #4566: Remove extra decrement of transaction levelPaul Nikitochkin2013-07-141-0/+14
| | | | | | | | | | | | `rollback_active_record_state!` tries to restore model state on `Exception` by invoking `restore_transaction_record_state` it decrement deep level by `1`. After restoring it ensure that states to be cleared and level decremented by invoking `clear_transaction_record_state`, which cause the bug: because state already reduced in `restore_transaction_record_state`. Removed double derement of transaction level and removed duplicated code which clear transaction state for top level.
* close our connection when we are doneAaron Patterson2013-07-081-13/+11
|
* Remove deprecated `transaction_joinable=`Arun Agrawal2013-07-031-9/+0
| | | | | in favor of `begin_transaction` with `:joinable` option.
* remove deprecated `PostgreSQLAdapter#outside_transaction?` method.Yves Senn2013-07-031-10/+0
|
* Reduced memory leak problem in transactions by lazily updating AR objects ↵wangjohn2013-02-201-2/+2
| | | | with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks.
* Refactored transaction state into its own object. Each transaction creates a ↵wangjohn2013-01-211-2/+10
| | | | new transaction state object upon initialization.
* Created state for a transaction and added tests.wangjohn2013-01-201-0/+20
|
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-4/+4
|
* Alias refute methods to assert_not and perfer assert_not on testsRafael Mendonça França2012-12-311-2/+2
|
* frozen state should be restored after txn is abortedAaron Patterson2012-10-221-0/+15
|
* Get rid of global variable in AR transactions testCarlos Antonio da Silva2012-09-201-7/+7
|
* Remove our use of #outside_transaction?Jon Leighton2012-09-151-29/+3
| | | | | | | | | | | | | | | | This method was first seen in 045713ee240fff815edb5962b25d668512649478, and subsequently reimplemented in fb2325e35855d62abd2c76ce03feaa3ca7992e4f. According to @jeremy, this is okay to remove. He thinks it was added because at the time we didn't have much transaction state to keep track of, and he viewed it as a hack for us to track it internally, thinking it was better to ask the connection for the transaction state. Over the years we have added more and more state to track, a lot of which is impossible to ask the connection for. So it seems that this is just a relic of the passed and we will just track the state internally only.
* Remove the transaction_open variableJon Leighton2012-09-151-0/+5
|
* Move transaction joinability into the transaction objectJon Leighton2012-09-151-0/+9
|