no_peeping_toms 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ === Version 2.1.3 / 2012-07-26
2
+ * Fix deprecation warning
3
+
1
4
  === Version 2.0.1 / 2011-02-16
2
5
  * Supports current Rails 3.x release. No longer supports Rails 2.
3
6
 
@@ -45,32 +45,36 @@ module NoPeepingToms
45
45
  end
46
46
  end
47
47
 
48
- module InstanceMethods
49
- # Overrides ActiveRecord#define_callbacks so that observers are only called
50
- # when enabled.
51
- #
52
- # This is a bit yuck being a protected method, but appears to be the cleanest
53
- # way so far
54
- def define_callbacks_with_enabled_check(klass)
55
- observer = self
56
- observer_name = observer.class.name.underscore.gsub('/', '__')
48
+ # Overrides ActiveRecord#define_callbacks so that observers are only called
49
+ # when enabled.
50
+ #
51
+ # This is a bit yuck being a protected method, but appears to be the cleanest
52
+ # way so far
53
+ def define_callbacks_with_enabled_check(klass)
54
+ observer = self
55
+ observer_name = observer.class.name.underscore.gsub('/', '__')
57
56
 
58
- ActiveRecord::Callbacks::CALLBACKS.each do |callback|
59
- next unless respond_to?(callback)
60
- callback_meth = :"_notify_#{observer_name}_for_#{callback}"
61
- unless klass.respond_to?(callback_meth)
62
- klass.send(:define_method, callback_meth) do
63
- observer.send(callback, self) if observer.observer_enabled?
64
- end
65
- klass.send(callback, callback_meth)
57
+ ActiveRecord::Callbacks::CALLBACKS.each do |callback|
58
+ next unless respond_to?(callback)
59
+ callback_meth = :"_notify_#{observer_name}_for_#{callback}"
60
+ unless klass.respond_to?(callback_meth)
61
+ klass.send(:define_method, callback_meth) do
62
+ observer.send(callback, self) if observer.observer_enabled?
66
63
  end
64
+ klass.send(callback, callback_meth)
67
65
  end
68
66
  end
67
+ end
69
68
 
70
- # Determines whether this observer should be run
71
- def observer_enabled?
72
- self.class.observer_enabled?(self)
73
- end
69
+ # Enables interception of custom observer notifications, i.e.
70
+ # notify_observers(:custom_notification)
71
+ def update(*args, &block)
72
+ super if observer_enabled?
73
+ end
74
+
75
+ # Determines whether this observer should be run
76
+ def observer_enabled?
77
+ self.class.observer_enabled?(self)
74
78
  end
75
79
  end
76
80
 
@@ -1,3 +1,3 @@
1
1
  module NoPeepingToms
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
@@ -3,7 +3,22 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  module NoPeepingTomsSpec
4
4
  class Person < ActiveRecord::Base; end
5
5
  class SpecialPerson < Person; end
6
-
6
+ class HungryPerson < Person
7
+ def eat_dinner!
8
+ notify_observers(:ate_dinner)
9
+ end
10
+ end
11
+
12
+ class DinnerObserver < ActiveRecord::Observer
13
+ observe Person
14
+ cattr_accessor :called
15
+
16
+ def ate_dinner(person)
17
+ self.class.called ||= 0
18
+ self.class.called += 1
19
+ end
20
+ end
21
+
7
22
  class PersonObserver < ActiveRecord::Observer
8
23
  cattr_accessor :called
9
24
 
@@ -12,7 +27,7 @@ module NoPeepingTomsSpec
12
27
  self.class.called += 1
13
28
  end
14
29
  end
15
-
30
+
16
31
  class AnotherObserver < ActiveRecord::Observer
17
32
  observe Person
18
33
  cattr_accessor :called
@@ -26,6 +41,7 @@ module NoPeepingTomsSpec
26
41
  # Register the observers with the host app
27
42
  PersonObserver.instance
28
43
  AnotherObserver.instance
44
+ DinnerObserver.instance
29
45
 
30
46
  describe NoPeepingToms, "configuration" do
31
47
  it "enables observers by default" do
@@ -82,6 +98,22 @@ module NoPeepingTomsSpec
82
98
  AnotherObserver.called.should be_true
83
99
  end
84
100
 
101
+ it "should not call observers with custom notifications if they are disabled" do
102
+ DinnerObserver.called = 0
103
+ lambda {
104
+ HungryPerson.new.eat_dinner!
105
+ }.should_not change(DinnerObserver, :called)
106
+ end
107
+
108
+ it "should call observers with custom notifications if they are enabled" do
109
+ DinnerObserver.called = 0
110
+ ActiveRecord::Observer.with_observers(NoPeepingTomsSpec::DinnerObserver) do
111
+ lambda {
112
+ HungryPerson.new.eat_dinner!
113
+ }.should change(DinnerObserver, :called).by(1)
114
+ end
115
+ end
116
+
85
117
  it "should ensure peeping toms are reset after raised exception" do
86
118
  lambda {
87
119
  ActiveRecord::Observer.with_observers(NoPeepingTomsSpec::PersonObserver) do
metadata CHANGED
@@ -1,71 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: no_peeping_toms
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.3
4
5
  prerelease:
5
- version: 2.1.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Pat Maddox
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-10-24 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70118143254060 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 3.0.0
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: activesupport
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70118143254060
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70118143253560 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
34
32
  version: 3.0.0
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70118143253560
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70118143253100 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "2.5"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.5'
46
44
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: sqlite3
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70118143253100
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: &70118143252720 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :development
58
- version_requirements: *id004
59
- description: Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer.
60
- email:
56
+ prerelease: false
57
+ version_requirements: *70118143252720
58
+ description: Disables observers during testing, allowing you to write model tests
59
+ that are completely decoupled from the observer.
60
+ email:
61
61
  - pat.maddox@gmail.com
62
62
  executables: []
63
-
64
63
  extensions: []
65
-
66
64
  extra_rdoc_files: []
67
-
68
- files:
65
+ files:
69
66
  - History.rdoc
70
67
  - README.rdoc
71
68
  - lib/no_peeping_toms/version.rb
@@ -77,30 +74,27 @@ files:
77
74
  - spec/spec_helper.rb
78
75
  homepage: https://github.com/patmaddox/no-peeping-toms
79
76
  licenses: []
80
-
81
77
  post_install_message:
82
78
  rdoc_options: []
83
-
84
- require_paths:
79
+ require_paths:
85
80
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
81
+ required_ruby_version: !ruby/object:Gem::Requirement
87
82
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
92
- required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
88
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
98
93
  requirements: []
99
-
100
94
  rubyforge_project: no_peeping_toms
101
- rubygems_version: 1.8.11
95
+ rubygems_version: 1.8.17
102
96
  signing_key:
103
97
  specification_version: 3
104
- summary: Disables observers during testing, allowing you to write model tests that are completely decoupled from the observer.
98
+ summary: Disables observers during testing, allowing you to write model tests that
99
+ are completely decoupled from the observer.
105
100
  test_files: []
106
-