Skip to content

Commit

Permalink
Use after_commit for tracked callbacks instead of after_create/after_…
Browse files Browse the repository at this point in the history
…update
  • Loading branch information
Nguyễn Đức Long committed Apr 16, 2019
1 parent 07f13c1 commit 7da7c34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/activity_notification/roles/acts_as_notifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ def add_tracked_callbacks(target_type, tracked_option = {})
# @param [Symbol] tracked_action Tracked action (:create or :update)
# @param [Proc] tracked_proc Proc or lambda function to execute
def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc)
if tracked_callbacks.include? tracked_action
return unless tracked_callbacks.include? tracked_action

if response_to? :after_commit
after_commit tracked_proc, on: tracked_action
else
case tracked_action
when :create
after_create tracked_proc
Expand Down
1 change: 1 addition & 0 deletions spec/roles/acts_as_notifiable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
dummy_notifiable_class.reset_callbacks :create
dummy_notifiable_class.reset_callbacks :update
dummy_notifiable_class.reset_callbacks :destroy
dummy_notifiable_class.reset_callbacks :commit if dummy_notifiable_class.respond_to? :after_commit
@notifiable = dummy_notifiable_class.create
end

Expand Down

0 comments on commit 7da7c34

Please sign in to comment.