Skip to content

Commit

Permalink
Avoid Rails issue that after commit callbacks on update does not trig…
Browse files Browse the repository at this point in the history
…gered - #99
  • Loading branch information
simukappu committed Apr 30, 2019
1 parent 83e79af commit c2ff4bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/activity_notification/roles/acts_as_notifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,15 @@ def add_tracked_callbacks(target_type, tracked_option = {})
def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc)
return unless tracked_callbacks.include? tracked_action

if respond_to? :after_commit
# FIXME: Avoid Rails issue that after commit callbacks on update does not triggered when optimistic locking is enabled
# See the followings:
# https://github.com/rails/rails/issues/30779
# https://github.com/rails/rails/pull/32167
# :only-rails-without-callback-issue:
if !(Gem::Version.new("5.1.6") <= Rails.gem_version && Rails.gem_version < Gem::Version.new("5.2.2")) && respond_to?(:after_commit)
after_commit tracked_proc, on: tracked_action
# :only-rails-without-callback-issue:
# :only-rails-with-callback-issue:
else
case tracked_action
when :create
Expand All @@ -290,6 +297,7 @@ def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc)
after_update tracked_proc
end
end
# :only-rails-with-callback-issue:
end

# Adds destroy dependency.
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
else
nocov_token 'only-rails5+'
end
if Gem::Version.new("5.1.6") <= Rails.gem_version && Rails.gem_version < Gem::Version.new("5.2.2")
nocov_token 'only-rails-without-callback-issue'
else
nocov_token 'only-rails-with-callback-issue'
end
if ENV['AN_ORM'] == 'mongoid'
add_filter '/lib/activity_notification/orm/active_record'
else
Expand Down

0 comments on commit c2ff4bb

Please sign in to comment.