From b85942e8ccf31107dffde7f13124e24991557bea Mon Sep 17 00:00:00 2001
From: Vilius Paulauskas <viliusp@gmail.com>
Date: Fri, 14 Sep 2018 19:44:53 +0200
Subject: [PATCH] Fixes AR saving when around_* observer is disabled.

---
 lib/rails/observers/active_model/observing.rb |  4 +++-
 test/lifecycle_test.rb                        | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/rails/observers/active_model/observing.rb b/lib/rails/observers/active_model/observing.rb
index 3f01a90..1ae7136 100644
--- a/lib/rails/observers/active_model/observing.rb
+++ b/lib/rails/observers/active_model/observing.rb
@@ -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
 
diff --git a/test/lifecycle_test.rb b/test/lifecycle_test.rb
index bfb0537..78ee68f 100644
--- a/test/lifecycle_test.rb
+++ b/test/lifecycle_test.rb
@@ -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