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

Keep previous state around for nested calls to #suppress #25009

Merged
merged 1 commit into from May 16, 2016

Conversation

Projects
None yet
4 participants
@jahfer
Contributor

jahfer commented May 13, 2016

If a call to #suppress from the same class occurred inside another #suppress block, the suppression state would be set to false before the outer block completes.

User.suppress do
  # somewhere deep inside another method…
  User.suppress { ... }
  @user.save! # not suppressed in old implementation
end

This change keeps the previous state around in memory and unwinds it as the blocks exit.

Also verified that the test fails without the change in ActiveRecord::Suppressor.

@casperisfine

View changes

activerecord/lib/active_record/suppressor.rb Outdated
@@ -30,10 +30,11 @@ module Suppressor
module ClassMethods
def suppress(&block)
previous_state = SuppressorRegistry.suppressed[name] || false

This comment has been minimized.

@casperisfine

casperisfine May 13, 2016

Why the || false. If the previous value was nil, we might as well put it back to nil no?

This comment has been minimized.

@jahfer

jahfer May 13, 2016

Contributor

Yeah I don't have strong feelings on this. Only reason was to make sure SuppressorRegistry.suppressed[name] is always a boolean. I'm fine with leaving the value falsy.

This comment has been minimized.

@sgrif

sgrif May 16, 2016

Member

I agree that we should set it back to nil if it was nil previously

Keep state around for nested calls to #suppress
If a call to #suppress from the same class occurred inside another #suppress
block, the suppression state would be set to false before the outer block
completes.

This change keeps the previous state around in memory and unwinds it
as the blocks exit.

@jahfer jahfer force-pushed the jahfer:suppressor-keep-state branch to 25801cf May 16, 2016

@jahfer

This comment has been minimized.

Contributor

jahfer commented May 16, 2016

Updated to remove the default false value. Now it will set the value back to nil if it was previously nil.

@sgrif sgrif merged commit a7ecc63 into rails:master May 16, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment