diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-16 14:11:32 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-16 14:11:32 -0400 |
commit | a7ecc636794a8cf1d90fc60b4fa5f7c70a19d573 (patch) | |
tree | ba9515783b6f1a28d200271130c14ec3ec72e04f /activerecord | |
parent | aa7ded6a362c609cd00b6c4ebc91b1d089bca4c4 (diff) | |
parent | 25801cfe78a124e868d7be068febf628d5fc1247 (diff) | |
download | rails-a7ecc636794a8cf1d90fc60b4fa5f7c70a19d573.tar.gz rails-a7ecc636794a8cf1d90fc60b4fa5f7c70a19d573.tar.bz2 rails-a7ecc636794a8cf1d90fc60b4fa5f7c70a19d573.zip |
Merge pull request #25009 from jahfer/suppressor-keep-state
Keep previous state around for nested calls to #suppress
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/suppressor.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/suppressor_test.rb | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/suppressor.rb b/activerecord/lib/active_record/suppressor.rb index 8ec4b48d31..d9acb1a1dc 100644 --- a/activerecord/lib/active_record/suppressor.rb +++ b/activerecord/lib/active_record/suppressor.rb @@ -30,10 +30,11 @@ module ActiveRecord module ClassMethods def suppress(&block) + previous_state = SuppressorRegistry.suppressed[name] SuppressorRegistry.suppressed[name] = true yield ensure - SuppressorRegistry.suppressed[name] = false + SuppressorRegistry.suppressed[name] = previous_state end end diff --git a/activerecord/test/cases/suppressor_test.rb b/activerecord/test/cases/suppressor_test.rb index 7d44e36419..2f00241de2 100644 --- a/activerecord/test/cases/suppressor_test.rb +++ b/activerecord/test/cases/suppressor_test.rb @@ -60,4 +60,16 @@ class SuppressorTest < ActiveRecord::TestCase end end end + + def test_suppresses_when_nested_multiple_times + assert_no_difference -> { Notification.count } do + Notification.suppress do + Notification.suppress { } + Notification.create + Notification.create! + Notification.new.save + Notification.new.save! + end + end + end end |