Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes AR saving when around_* observer is disabled. #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rails/observers/active_model/observing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ def observed_classes #:nodoc:
# Send observed_method(object) if the method exists and
# the observer is enabled for the given object's class.
def update(observed_method, object, *extra_args, &block) #:nodoc:
return if !respond_to?(observed_method) || disabled_for?(object)
if !respond_to?(observed_method) || disabled_for?(object)
return block && block.call
end
send(observed_method, object, *extra_args, &block)
end

Expand Down
11 changes: 11 additions & 0 deletions test/lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def test_invalid_observer
assert_not_nil observer.topic_ids.last
end

test "disabling around filter does not impact ActiveRecord saving" do
observer = AroundTopicObserver.instance
observer.topic_ids.clear
ActiveRecord::Base.observers.disable AroundTopicObserver do
topic = AroundTopic.new
topic.save
assert_not_nil topic.id
end
assert_empty observer.topic_ids
end

test "able to disable observers" do
observer = DeveloperObserver.instance # activate
observer.calls.clear
Expand Down