Permalink
Browse files

Merge remote branch 'inventables/master'

* inventables/master:
  Switched to intentional enabling

Conflicts:
	init.rb
  • Loading branch information...
2 parents 55371f6 + 3be84a2 commit ddebd8c885ec9cb4f55bb9fa6f9c0619244585c5 @patmaddox committed Jan 6, 2010
Showing with 17 additions and 1 deletion.
  1. +4 −0 README
  2. +0 −1 init.rb
  3. +4 −0 lib/no_peeping_toms.rb
  4. +9 −0 spec/no_peeping_toms_spec.rb
View
4 README
@@ -5,6 +5,10 @@ Originally a plugin, now gemified. 'gem install no_peeping_toms'
This plugin disables observers in your specs, so that model specs can run in complete isolation.
+To disable observers, place the following code in your test.rb, or spec_helper.rb, or wherever:
+
+ NoPeepingToms.disable_observers
+
You can choose to run some code with observers turned on. This is useful when spec'ing an observer. For example, if you write the following observer:
class PersonObserver < ActiveRecord::Observer
View
@@ -1 +0,0 @@
-require 'no_peeping_toms' if "test" == RAILS_ENV
View
@@ -1,4 +1,8 @@
module NoPeepingToms
+ def self.disable_observers
+ ActiveRecord::Observer.send :include, NoPeepingToms
+ end
+
def self.included(base)
base.send :include, NoPeepingToms::InstanceMethods
base.extend NoPeepingToms::ClassMethods
@@ -1,5 +1,14 @@
require File.dirname(__FILE__) + '/spec_helper'
+describe "Configuring NoPeepingToms" do
+ describe "#disable_observers" do
+ it "mixes in NoPeepingToms module to ActiveRecord::Observer" do
+ ActiveRecord::Observer.should_receive(:send).with(:include, NoPeepingToms)
+ NoPeepingToms.disable_observers
+ end
+ end
+end
+
module NoPeepingTomsSpec
class Person < ActiveRecord::Base; end

0 comments on commit ddebd8c

Please sign in to comment.