Last active
August 29, 2015 14:07
-
-
Save asabirov/5df147ec8d7fba97226b to your computer and use it in GitHub Desktop.
Alternative for no-peeping-toms on Rails4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add it to spec/spec_helper.rb | |
RSpec.configure do |config| | |
... | |
config.include TestObservers | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place file in spec/support | |
module TestObservers | |
def with_observers(*observers) | |
disabled_observers = ActiveRecord::Base.observers.send(:disabled_observers) | |
ActiveRecord::Base.observers.enable(*observers) | |
yield | |
ActiveRecord::Base.observers.disable(*disabled_observers.to_a) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment