Skip to content

Commit

Permalink
Merge pull request #25009 from jahfer/suppressor-keep-state
Browse files Browse the repository at this point in the history
Keep previous state around for nested calls to #suppress
  • Loading branch information
sgrif committed May 16, 2016
2 parents aa7ded6 + 25801cf commit a7ecc63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/suppressor.rb
Expand Up @@ -30,10 +30,11 @@ module Suppressor

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

Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/suppressor_test.rb
Expand Up @@ -60,4 +60,16 @@ def test_suppresses_validations_on_create
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

0 comments on commit a7ecc63

Please sign in to comment.