aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transaction_callbacks_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Prioritize checking `:on` actions before `:if` for transaction callbacksErol Fornoles2017-02-211-0/+40
|
* Emulate db trigger behaviour for after_commit :destroy, :updateStefan Budeanu2016-12-091-0/+45
| | | | | | Race conditions can occur when an ActiveRecord is destroyed twice or destroyed and updated. The callbacks should only be triggered once, similar to a SQL database trigger.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-6/+6
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-20/+20
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
|
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-6/+6
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-12/+12
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix corrupt transaction state caused by `before_commit` exceptionsJeremy Daer2016-02-011-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | When a `before_commit` callback raises, the database is rolled back but AR's record of the current transaction is not, leaving the connection in a perpetually broken state that affects all future users of the connection: subsequent requests, jobs, etc. They'll think a transaction is active when none is, so they won't BEGIN on their own. This manifests as missing `after_commit` callbacks and broken ROLLBACKs. This happens because `before_commit` callbacks fire before the current transaction is popped from the stack, but the exception-handling path they hit assumes that the current transaction was already popped. So the database ROLLBACK is issued, but the transaction stack is left intact. Common cause: deadlocked `#touch`, which is now implemented with `before_commit` callbacks. What's next: * We shouldn't allow active transaction state when checking in or out from the connection pool. Verify that conns are clean. * Closer review of txn manager sad paths. Are we missing other spots where we'd end up with incorrect txn state? What's the worst that can happen if txn state drifts? How can we guarantee it doesn't and contain the fallout if it does? Thanks for @tomafro for expert diagnosis!
* Introduce after_{create,update,delete}_commit callbacksGenadi Samokovarov2015-12-061-3/+3
| | | | | | | | | | | | | | | | Those are actually shortcuts for `after_commit`. Before: after_commit :add_to_index_later, on: :create after_commit :update_in_index_later, on: :update after_commit :remove_from_index_later, on: :destroy After: after_create_commit :add_to_index_later after_update_commit :update_in_index_later after_destroy_commit :remove_from_index_later
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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 before_commit when updating a record on the callbackArthur Neves2015-03-141-0/+22
|
* Rename testsArthur Neves2015-02-241-4/+4
|
* Add before_commitArthur Neves2015-02-241-2/+3
| | | | [fixes #18903]
* Add transaction callbacks that wont enroll to the transaction.Arthur Neves2015-02-241-0/+59
| | | | | | | | | Add after_commit_without_transaction_enrollment and after_rollback_without_transaction_enrollment private callbacks so we can create after_commit and after_rollback callbacks without having the records automatic enrolled in the transaction. [fixes #18904]
* TransactionManager should call rollback recordsArthur Neves2015-01-201-1/+1
|
* after_commit runs after transactions with non-joinable parentsbrainopia2015-01-161-14/+13
| | | | | | after_commit callbacks run after committing a transaction whose parent is not `joinable?`: un-nested transactions, transactions within test cases, and transactions in `console --sandbox`.
* Change transaction callbacks to not swallowing errors.Rafael Mendonça França2015-01-041-41/+0
| | | | | | | | Before this change any error raised inside a transaction callback are rescued and printed in the logs. Now these errors are not rescue anymore and just bubble up, as the other callbacks.
* Make error message clearer that :on requires a symbol, not a stringCarol Nichols2014-12-071-0/+4
| | | | | | | | | | | | | | The validation added in 5a3dc8092d19c816b0b1203945639cb91d065847 will reject values for the `:on` option for after_commit and after_rollback callbacks that are string values like `"create"`. However, the error message says ":on conditions for after_commit and after_rollback callbacks have to be one of create,destroy,update". That looks like a string value *would* be valid. This commit changes the error message to say ":on conditions for after_commit and after_rollback callbacks have to be one of [:create, :destroy, :update]", making it clearer that symbols are required.
* Add option to stop swallowing errors on callbacks.Arthur Neves2014-08-181-0/+76
| | | | | | | | | | | | | | | Currently, Active Record will rescue any errors raised within after_rollback/after_create callbacks and print them to the logs. Next versions of rails will not rescue those errors anymore, and just bubble them up, as the other callbacks. This adds a opt-in flag to enable that behaviour, of not rescuing the errors. Example: # For not swallow errors in after_commit/after_rollback config.active_record.errors_in_transactional_callbacks = true [fixes #13460]
* Fix regression on after_commit in nested transactions.Arthur Neves2014-08-151-0/+13
| | | | | | | | | after_commit should not run in nested transactions, however they should run once the outermost transaction gets committed. This patch fixes the problem copying the records from the Savepoint to its parent. So the RealTransaction will have all records that needs to run callbacks on it. [fixes #16425]
* Make sure transaction state resets after commitArthur Neves2014-02-031-0/+15
| | | | [fixes #12566]
* Do not set up a variable used only in two testsCarlos Antonio da Silva2014-01-161-15/+18
| | | | | Just create a local variable whenever we need the record, rather than doing an extra find for every test on the setup method.
* No need for instance vars on single testsCarlos Antonio da Silva2014-01-161-8/+8
|
* Cleanup duplicated setup of callbacks in transactions testsCarlos Antonio da Silva2014-01-161-48/+19
|
* No need to use #send with public methodsCarlos Antonio da Silva2014-01-161-10/+10
|
* Make AR::Base#touch fire the after_commit and after_rollback callbacksHarry Brundage2014-01-161-1/+46
|
* Don't rewrite AR connection#commit_db_transaction method globallyAkira Matsuda2013-07-291-4/+4
|
* Revert "Merge pull request #6226 from gnufied/master"Rafael Mendonça França2013-04-101-32/+0
| | | | | | | | | | | | | This reverts commit 9bf1a0db4acbbf9e8e6f707250269185224e7efe, reversing changes made to fed97091b9546d369a240d10b184793d49247dd3. Conflicts: activerecord/test/cases/transaction_callbacks_test.rb Reason: This fix introduces another issue described at #8937, so we are reverting it to restore the behavior of 3-2-stable. We will fix both issues when we come out with a better solution
* Deprecate #connection in favour of accessing it via the classBen Moss2013-03-091-4/+4
| | | | | This allows end-users to have a `connection` method on their models without clashing with ActiveRecord internals.
* multiple actions for :on option with `after_commit` and `after_rollback`Yves Senn2013-02-211-0/+35
| | | | Closes #988.
* Don't call after_commit when creating through an association and save fails, ↵James Miller2013-02-131-0/+27
| | | | fixes #5802
* validate :on option on after_commit and after_rollback callbacksPascal Friederich2012-12-261-0/+8
|
* Remove observers and sweepersRafael Mendonça França2012-11-281-81/+0
| | | | | | | | They was extracted from a plugin. See https://github.com/rails/rails-observers [Rafael Mendonça França + Steve Klabnik]
* Fix testJon Leighton2012-09-151-2/+2
| | | | Accidentally checked in commented test code. Fail. >_<
* Start to tease out transaction handling into a state machineJon Leighton2012-09-151-2/+2
|
* Merge pull request #5535 from markmcspadden/issue_5527_rollbacksAaron Patterson2012-05-161-0/+37
|\ | | | | Allow manual rollbacks in after_save to reset object correctly
| * Allow manual rollbacks in after_save to reset object correctlyMark McSpadden2012-03-211-0/+37
| |
* | make both cached and record_updated accessors in one lineHemant Kumar2012-05-091-2/+1
| |
* | after_commit :on => :update should be called when save isHemant Kumar2012-05-091-0/+7
| | | | | | | | called from after_commit callback
* | Fix transaction state not changing when after record gets commitedHemant Kumar2012-05-091-0/+25
|/
* Deprecate set_table_name in favour of self.table_name= or defining your own ↵Jon Leighton2011-11-291-2/+2
| | | | method.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* fisting after_rollback and after commit callbacksAaron Patterson2010-08-201-4/+8
|
* assert_equal hereSantiago Pastorino2010-08-161-2/+2
|