Skip to content

Do not call callbacks when they are disabled #162

Closed
wants to merge 1 commit into from

2 participants

@joelind
joelind commented Feb 21, 2012

Hi,

I've been using state_machine with ActiveRecord and in some instances am using ActiveRecord::Observers.disable to turn off observers (for instance, to isolate certain model behaviors during tests). state_machine's definition of Observer.update_with_transition does not check for disabled_for? before using the send method to call the callback.

I added test cases to the ActiveModel and ActiveRecord integration tests to test the behavior and changed the update_with_transition method to match the current implementation in ActiveModel itself.

Thanks!
-Joe

@obrie obrie was assigned Feb 21, 2012
@obrie
PluginAWeek member
obrie commented Feb 23, 2012

Hey @joelind -

Thanks for reporting this and providing a fix! As it turns out, the problem is that ActiveModel just isn't properly detecting the disabled list of observers on the object -- state_machine doesn't need to actually implement those checks. I've gone with a different implementation that should resolve this issue in the same manner.

@obrie obrie added a commit that closed this pull request Feb 23, 2012
@obrie obrie Fix observer callbacks being run when disabled in ActiveModel / Activ…
…eRecord integrations. Closes #162
db84662
@obrie obrie closed this in db84662 Feb 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.