Skip to content

Commit

Permalink
Merge remote branch 'inventables/master'
Browse files Browse the repository at this point in the history
* inventables/master:
  Switched to intentional enabling

Conflicts:
	init.rb
  • Loading branch information
Pat Maddox committed Jan 6, 2010
2 parents 55371f6 + 3be84a2 commit ddebd8c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion init.rb
@@ -1 +0,0 @@
require 'no_peeping_toms' if "test" == RAILS_ENV
4 changes: 4 additions & 0 deletions lib/no_peeping_toms.rb
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/no_peeping_toms_spec.rb
@@ -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

Expand Down

0 comments on commit ddebd8c

Please sign in to comment.