Skip to content

Commit

Permalink
ActiveRecord::Base.no_touching no longer triggers callbacks or star…
Browse files Browse the repository at this point in the history
…t empty transactions.

Closes #14841.
  • Loading branch information
lucasmazza committed Apr 23, 2014
1 parent d10e2ca commit 4866399
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.

Fixes #14841.

*Lucas Mazza*

* Fix name collision with `Array#select!` with `Relation#select!`.

Fixes #14752.
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -296,7 +296,6 @@ class Base

include Core
include Persistence
include NoTouching
include ReadonlyAttributes
include ModelSchema
include Inheritance
Expand All @@ -318,6 +317,7 @@ class Base
include NestedAttributes
include Aggregations
include Transactions
include NoTouching
include Reflection
include Serialization
include Store
Expand Down
21 changes: 20 additions & 1 deletion activerecord/test/cases/timestamp_test.rb
Expand Up @@ -112,7 +112,7 @@ def test_touching_many_attributes_updates_them
previous_starting = task.starting
previous_ending = task.ending
task.touch(:starting, :ending)

assert_not_equal previous_starting, task.starting
assert_not_equal previous_ending, task.ending
assert_in_delta Time.now, task.starting, 1
Expand Down Expand Up @@ -170,6 +170,25 @@ def test_no_touching_threadsafe
assert !@developer.no_touching?
end

def test_no_touching_with_callbacks
klass = Class.new(ActiveRecord::Base) do
self.table_name = "developers"

attr_accessor :after_touch_called

after_touch do |user|
user.after_touch_called = true
end
end

developer = klass.first

klass.no_touching do
developer.touch
assert_not developer.after_touch_called
end
end

def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
pet = Pet.first
owner = pet.owner
Expand Down

0 comments on commit 4866399

Please sign in to comment.