File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,12 +39,15 @@ def destroyed(time = nil)
3939
4040 # Set an object's destroyed_at time.
4141 def destroy ( timestamp = nil )
42- timestamp ||= @marked_for_destruction_at || current_time_from_proper_timezone
43- raw_write_attribute ( :destroyed_at , timestamp )
44- run_callbacks ( :destroy ) do
45- destroy_associations
46- self . class . unscoped . where ( self . class . primary_key => id ) . update_all ( destroyed_at : timestamp )
47- @destroyed = true
42+ with_transaction_returning_status do
43+ timestamp ||= @marked_for_destruction_at || current_time_from_proper_timezone
44+ raw_write_attribute ( :destroyed_at , timestamp )
45+
46+ run_callbacks ( :destroy ) do
47+ destroy_associations
48+ self . class . unscoped . where ( self . class . primary_key => id ) . update_all ( destroyed_at : timestamp )
49+ @destroyed = true
50+ end
4851 end
4952 end
5053
Original file line number Diff line number Diff line change 260260 end
261261end
262262
263+ describe 'destroying on object should call after_commit callback' do
264+ it 'calls after_commit callback on: :destroy' do
265+ comment = Comment . create
266+ comment . destroy
267+
268+ comment . after_commited . must_equal true
269+ end
270+ end
Original file line number Diff line number Diff line change @@ -80,6 +80,14 @@ class Comment < ActiveRecord::Base
8080 belongs_to :commenter
8181
8282 has_many :likes , as : :likeable , dependent : :destroy
83+
84+ after_commit :foo , on : :destroy
85+
86+ attr_reader :after_commited
87+
88+ def foo
89+ @after_commited = true
90+ end
8391end
8492
8593class Commenter < ActiveRecord ::Base
You can’t perform that action at this time.
0 commit comments