Permalink
Browse files

Major refactor, including Rails 3.0.4 support

  • Loading branch information...
1 parent adcaf5e commit 3df8369148b7ca3d3b342ebb9c93ec1f5b597671 @alindeman alindeman committed Feb 16, 2011
Showing with 159 additions and 8,772 deletions.
  1. +5 −3 .gitignore
  2. +4 −0 Gemfile
  3. +3 −0 History.rdoc
  4. +0 −60 README
  5. +67 −0 README.rdoc
  6. +0 −41 Rakefile
  7. +0 −1 VERSION
  8. +0 −1 init.rb
  9. +0 −1 install.rb
  10. +53 −24 lib/no_peeping_toms.rb
  11. +3 −0 lib/no_peeping_toms/version.rb
  12. +17 −50 no_peeping_toms.gemspec
  13. +0 −2 spec/host_app/.gitignore
  14. +0 −243 spec/host_app/README
  15. +0 −10 spec/host_app/Rakefile
  16. +0 −1 spec/host_app/app/controllers/application.rb
  17. +0 −2 spec/host_app/app/controllers/application_controller.rb
  18. +0 −3 spec/host_app/app/helpers/application_helper.rb
  19. +0 −110 spec/host_app/config/boot.rb
  20. +0 −22 spec/host_app/config/database.yml
  21. +0 −5 spec/host_app/config/environment.rb
  22. +0 −17 spec/host_app/config/environments/development.rb
  23. +0 −28 spec/host_app/config/environments/production.rb
  24. +0 −28 spec/host_app/config/environments/test.rb
  25. +0 −5 spec/host_app/config/locales/en.yml
  26. +0 −43 spec/host_app/config/routes.rb
  27. +0 −7 spec/host_app/db/seeds.rb
  28. +0 −2 spec/host_app/doc/README_FOR_APP
  29. +0 −144 spec/host_app/lib/tasks/rspec.rake
  30. 0 spec/host_app/log/.keep
  31. +0 −30 spec/host_app/public/404.html
  32. +0 −30 spec/host_app/public/422.html
  33. +0 −30 spec/host_app/public/500.html
  34. 0 spec/host_app/public/favicon.ico
  35. BIN spec/host_app/public/images/rails.png
  36. +0 −275 spec/host_app/public/index.html
  37. +0 −2 spec/host_app/public/javascripts/application.js
  38. +0 −963 spec/host_app/public/javascripts/controls.js
  39. +0 −973 spec/host_app/public/javascripts/dragdrop.js
  40. +0 −1,128 spec/host_app/public/javascripts/effects.js
  41. +0 −4,320 spec/host_app/public/javascripts/prototype.js
  42. +0 −5 spec/host_app/public/robots.txt
  43. +0 −4 spec/host_app/script/about
  44. +0 −6 spec/host_app/script/autospec
  45. +0 −3 spec/host_app/script/console
  46. +0 −3 spec/host_app/script/dbconsole
  47. +0 −3 spec/host_app/script/destroy
  48. +0 −3 spec/host_app/script/generate
  49. +0 −3 spec/host_app/script/performance/benchmarker
  50. +0 −3 spec/host_app/script/performance/profiler
  51. +0 −3 spec/host_app/script/plugin
  52. +0 −3 spec/host_app/script/runner
  53. +0 −3 spec/host_app/script/server
  54. +0 −10 spec/host_app/script/spec
  55. +0 −2 spec/host_app/spec/rcov.opts
  56. +0 −4 spec/host_app/spec/spec.opts
  57. +0 −54 spec/host_app/spec/spec_helper.rb
  58. +0 −9 spec/host_app/test/performance/browsing_test.rb
  59. +0 −38 spec/host_app/test/test_helper.rb
  60. +1 −1 spec/no_peeping_toms_spec.rb
  61. +6 −7 spec/spec_helper.rb
  62. +0 −1 uninstall.rb
View
@@ -1,3 +1,5 @@
-*.log
-pkg
-coverage
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+spec/debug.log
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in no-peeping-toms.gemspec
+gemspec
View
@@ -1,3 +1,6 @@
+=== Version 2.0.1 / 2011-02-16
+* Supports current Rails 3.x release. No longer supports Rails 2.
+
=== Version 1.1.0 / 2010-01-06
* Explicit enable/disable API (Corey Haines & Drew Olson)
View
@@ -1,60 +0,0 @@
-no_peeping_toms
-=============
-
-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:
-
- ActiveRecord::Observer.disable_observers
-
-You can easily reenable observers:
-
- ActiveRecord::Observer.enable_observers
-
-You can choose to run some code with specific observers turned on. This is useful when spec'ing an observer. For example, if you write the following observer:
-
- class PersonObserver < ActiveRecord::Observer
- def before_update(person)
- old_person = Person.find person.id
- if old_person.name != person.name
- NameChange.create! :person => person, :old_name => old_person.name, :new_name => person.name
- end
- end
- end
-
-You can spec the Person class in complete isolation.
-
- describe Person, " when changing a name" do
- before(:each) do
- @person = Person.create! :name => "Pat Maddox"
- end
-
- # By default, don't run any observers
- it "should not register a name change" do
- lambda { @person.update_attribute :name, "Don Juan Demarco" }.should_not change(NameChange, :count)
- end
-
- # Run only a portion of code with certain observers turned on
- it "should register a name change with the person observer turned on" do
- ActiveRecord::Observer.with_observers(:person_observer) do
- lambda { @person.update_attribute :name, "Don Juan Demarco" }.should change(NameChange, :count).by(1)
- end
-
- lambda { @person.update_attribute :name, "Man Without a Name" }.should_not change(NameChange, :count)
- end
- end
-
-Known to work against Rails versions >= 2.2.2 (run rake:multi_rails:all to test against versions installed on your machine)
-
-Cool people who have contributed to NoPeepingToms:
- * Brandon Keepers
- * Corey Haines
- * Drew Olson
- * Jeff Siegel
- * Zach Dennis
-
-If you think your name should be here, shoot me an email and I'll add it ASAP.
-
-Copyright (c) 2007-2010 Pat Maddox, released under the MIT license
View
@@ -0,0 +1,67 @@
+= no_peeping_toms
+
+This plugin disables observers in your specs, so that model specs can run in complete isolation.
+
+== Installation
+
+Add to your Gemfile:
+
+ gem 'no_peeping_toms', :git => 'git://github.com/alindeman/no_peeping_toms.git'
+
+and run `bundle install`.
+
+no_peeping_toms >= 2.0.0 only supports on Rails 3. If you need Rails 2 support, use 1.1.0: `gem install no_peeping_toms -v 1.1.0`
+
+== Usage
+
+To disable observers, place the following code in your test.rb, or spec_helper.rb, or wherever:
+
+ ActiveRecord::Observer.disable_observers
+
+You can easily reenable observers:
+
+ ActiveRecord::Observer.enable_observers
+
+You can choose to run some code with specific observers turned on. This is useful when spec'ing an observer. For example, if you write the following observer:
+
+ class PersonObserver < ActiveRecord::Observer
+ def before_update(person)
+ old_person = Person.find person.id
+ if old_person.name != person.name
+ NameChange.create! :person => person, :old_name => old_person.name, :new_name => person.name
+ end
+ end
+ end
+
+You can spec the Person class in complete isolation.
+
+ describe Person, " when changing a name" do
+ before(:each) do
+ @person = Person.create! :name => "Pat Maddox"
+ end
+
+ # By default, don't run any observers
+ it "should not register a name change" do
+ lambda { @person.update_attribute :name, "Don Juan Demarco" }.should_not change(NameChange, :count)
+ end
+
+ # Run only a portion of code with certain observers turned on
+ it "should register a name change with the person observer turned on" do
+ ActiveRecord::Observer.with_observers(:person_observer) do
+ lambda { @person.update_attribute :name, "Don Juan Demarco" }.should change(NameChange, :count).by(1)
+ end
+
+ lambda { @person.update_attribute :name, "Man Without a Name" }.should_not change(NameChange, :count)
+ end
+ end
+
+== Credits
+
+* Brandon Keepers
+* Corey Haines
+* Drew Olson
+* Jeff Siegel
+* Zach Dennis
+* Andy Lindeman
+
+Copyright (c) 2007-2011 Pat Maddox, released under the MIT license.
View
@@ -1,41 +0,0 @@
-begin
- require 'jeweler'
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
- exit 1
-end
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'rcov/rcovtask'
-require "load_multi_rails_rake_tasks"
-
-Jeweler::Tasks.new do |s|
- s.name = "no_peeping_toms"
- s.summary = "Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer."
- s.description = s.summary
- s.email = "pat.maddox@gmail.com"
- s.homepage = "http://github.com/patmaddox/no-peeping-toms"
- s.authors = ["Pat Maddox", "Brandon Keepers"]
- s.add_dependency "activerecord", ['>= 1.1']
- s.files -= ['.gitignore', 'init.rb']
- s.test_files = Dir['spec/**/*']
- s.test_files -= ['spec/debug.log']
-end
-
-Jeweler::GemcutterTasks.new
-
-require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
- spec.rcov_opts = ['--exclude', 'gems/,spec/']
-end
-
-task :spec => :check_dependencies
-task :test => :spec
View
@@ -1 +0,0 @@
-1.1.0
View
@@ -1 +0,0 @@
-require 'no_peeping_toms'
View
@@ -1 +0,0 @@
-# Install hook code here
@@ -1,42 +1,71 @@
+require 'active_record'
+require 'active_support/core_ext/class/attribute_accessors'
+
module NoPeepingToms
- def self.included(base)
- unless base.included_modules.include?(NoPeepingToms::InstanceMethods)
- base.send :include, NoPeepingToms::InstanceMethods
- base.extend NoPeepingToms::ClassMethods
- base.alias_method_chain :update, :neighborhood_watch
- base.cattr_accessor :peeping_toms, :default_observers_enabled
- base.peeping_toms = [] # toms that are allowed to peep
- end
+ extend ActiveSupport::Concern
- base.enable_observers
- end
+ included do
+ # Define class-level accessors
+ cattr_accessor :default_observers_enabled, :observers_enabled
- module InstanceMethods
- def update_with_neighborhood_watch(*args)
- if self.class.default_observers_enabled || self.class.peeping_toms.include?(self)
- update_without_neighborhood_watch(*args)
- end
- end
+ # By default, enable all observers
+ enable_observers
+ self.observers_enabled = []
+
+ alias_method_chain :define_callbacks, :enabled_check
end
-
+
module ClassMethods
+ # Enables all observers (default behavior)
+ def enable_observers
+ self.default_observers_enabled = true
+ end
+
+ # Disables all observers
+ def disable_observers
+ self.default_observers_enabled = false
+ end
+
+ # Run a block with a specific set of observers enabled
def with_observers(*observer_syms)
- self.peeping_toms = Array(observer_syms).map do |o|
+ self.observers_enabled = Array(observer_syms).map do |o|
o.respond_to?(:instance) ? o.instance : o.to_s.classify.constantize.instance
end
yield
ensure
- self.peeping_toms.clear
+ self.observers_enabled = []
end
- def disable_observers
- self.default_observers_enabled = false
+ # Determines whether an observer is enabled. Either:
+ # - All observers are enabled OR
+ # - The observer is in the whitelist
+ def observer_enabled?(observer)
+ default_observers_enabled or self.observers_enabled.include?(observer)
end
+ end
- def enable_observers
- self.default_observers_enabled = true
+ module InstanceMethods
+ # Overrides ActiveRecord#define_callbacks so that observers are only called
+ # when enabled.
+ #
+ # This is a bit yuck being a protected method, but appears to be the cleanest
+ # way so far
+ def define_callbacks_with_enabled_check(klass)
+ observer = self
+
+ ActiveRecord::Callbacks::CALLBACKS.each do |callback|
+ next unless respond_to?(callback)
+ klass.send(callback) do |record|
+ observer.send(callback, record) if observer.observer_enabled?
+ end
+ end
+ end
+
+ # Determines whether this observer should be run
+ def observer_enabled?
+ self.class.observer_enabled?(self)
end
end
end
-ActiveRecord::Observer.send :include, NoPeepingToms
+ActiveRecord::Observer.__send__ :include, NoPeepingToms
@@ -0,0 +1,3 @@
+module NoPeepingToms
+ VERSION = "2.0.1"
+end
@@ -1,58 +1,25 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "no_peeping_toms/version"
Gem::Specification.new do |s|
- s.name = %q{no_peeping_toms}
- s.version = "1.1.0"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Pat Maddox", "Brandon Keepers"]
- s.date = %q{2010-01-06}
+ s.name = "no_peeping_toms"
+ s.version = NoPeepingToms::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Andy Lindeman", "Pat Maddox", "Brandon Keepers"]
+ s.email = ["alindeman@gmail.com", "pat.maddox@gmail.com"]
+ s.homepage = "https://github.com/alindeman/no_peeping_toms"
+ s.summary = %q{Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer.}
s.description = %q{Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer.}
- s.email = %q{pat.maddox@gmail.com}
- s.extra_rdoc_files = [
- "README"
- ]
- s.files = [
- "History.rdoc",
- "README",
- "Rakefile",
- "VERSION",
- "install.rb",
- "lib/no_peeping_toms.rb",
- "no_peeping_toms.gemspec",
- "spec/db/database.yml",
- "spec/db/schema.rb",
- "spec/no_peeping_toms_spec.rb",
- "spec/spec_helper.rb",
- "uninstall.rb"
- ]
- s.homepage = %q{http://github.com/patmaddox/no-peeping-toms}
- s.rdoc_options = ["--charset=UTF-8"]
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.5}
- s.summary = %q{Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer.}
- s.test_files = [
- "spec/db",
- "spec/db/database.yml",
- "spec/db/schema.rb",
- "spec/no_peeping_toms_spec.rb",
- "spec/spec_helper.rb"
- ]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ s.add_runtime_dependency 'activerecord', '>=3.0.0'
+ s.add_runtime_dependency 'activesupport', '>=3.0.0'
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<activerecord>, [">= 1.1"])
- else
- s.add_dependency(%q<activerecord>, [">= 1.1"])
- end
- else
- s.add_dependency(%q<activerecord>, [">= 1.1"])
- end
+ s.add_development_dependency 'rspec', '~>2.5'
+ s.add_development_dependency 'sqlite3'
end
-
@@ -1,2 +0,0 @@
-db/*.sqlite3
-log/*.log
Oops, something went wrong. Retry.

0 comments on commit 3df8369

Please sign in to comment.