Skip to content

Commit ae82efb

Browse files
committed
Properly call destroy method so after_commit callback is called.
1 parent 9d6d9d9 commit ae82efb

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/destroyed_at.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def destroyed(time = nil)
3939

4040
# Set an object's destroyed_at time.
4141
def destroy(timestamp = nil)
42-
transaction do
42+
with_transaction_returning_status do
4343
timestamp ||= @marked_for_destruction_at || current_time_from_proper_timezone
4444
raw_write_attribute(:destroyed_at, timestamp)
4545

test/destroyed_at_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,11 @@
269269
end
270270
end
271271

272+
describe 'destroying on object should call after_commit callback' do
273+
it 'calls after_commit callback on: :destroy' do
274+
comment = Comment.create
275+
comment.destroy
276+
277+
comment.after_committed.must_equal true
278+
end
279+
end

test/test_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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 :set_after_committed_flag, on: :destroy
85+
86+
attr_reader :after_committed
87+
88+
def set_after_committed_flag
89+
@after_committed = true
90+
end
8391
end
8492

8593
class Commenter < ActiveRecord::Base

0 commit comments

Comments
 (0)