has-guarded-handlers 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  # [develop](https://github.com/adhearsion/has-guarded-handlers)
2
2
 
3
+ # [1.4.1](https://github.com/adhearsion/has-guarded-handlers/compare/v1.4.0...v1.4.1) - [2012-12-08](https://rubygems.org/gems/has-guarded-handlers/versions/1.4.1)
4
+ * Bugfix: Report handler execution correctly in edge cases
5
+
3
6
  # [1.4.0](https://github.com/adhearsion/has-guarded-handlers/compare/v1.3.1...v1.4.0) - [2012-12-08](https://rubygems.org/gems/has-guarded-handlers/versions/1.4.0)
4
7
  * Feature: Return true/false from #trigger_handler depending on wether a handler was called or not
5
8
 
@@ -80,13 +80,23 @@ module HasGuardedHandlers
80
80
  # @param [Object] the event object to yield to the handler block
81
81
  def trigger_handler(type, event)
82
82
  return unless handler = handlers_of_type(type)
83
+ called = false
83
84
  catch :halt do
84
- handler.find do |guards, handler, tmp|
85
- val = catch(:pass) { call_handler handler, guards, event }
85
+ h = handler.find do |guards, handler, tmp|
86
+ called = true
87
+ val = catch(:pass) do
88
+ if guarded?(guards, event)
89
+ called = false
90
+ else
91
+ handler.call event
92
+ true
93
+ end
94
+ end
86
95
  delete_handler_if(type) { |_, h, _| h.equal? handler } if tmp && val
87
96
  val
88
97
  end
89
98
  end
99
+ !!called
90
100
  end
91
101
 
92
102
  private
@@ -110,12 +120,6 @@ module HasGuardedHandlers
110
120
  values
111
121
  end
112
122
 
113
- def call_handler(handler, guards, event) # :nodoc:
114
- return if guarded?(guards, event)
115
- handler.call event
116
- true
117
- end
118
-
119
123
  def new_handler_id # :nodoc:
120
124
  SecureRandom.uuid
121
125
  end
@@ -1,3 +1,3 @@
1
1
  module HasGuardedHandlers
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -25,16 +25,21 @@ describe HasGuardedHandlers do
25
25
  end
26
26
 
27
27
  it 'can register a one-shot (tmp) handler' do
28
- response.expects(:call).once.with(event)
29
- event.expects(:foo).once.returns :bar
28
+ response.expects(:call).times(3).with(event)
29
+ event.expects(:foo).times(3).returns :bar
30
30
 
31
31
  nomatch_event = mock 'Event(nomatch)'
32
- nomatch_event.expects(:foo).once.returns :baz
32
+ nomatch_event.expects(:foo).twice.returns :baz
33
33
 
34
+ subject.register_handler(:event, :foo => :bar) do |e|
35
+ response.call e
36
+ throw :pass
37
+ end
34
38
  subject.register_tmp_handler(:event, :foo => :bar) { |e| response.call e }
35
39
 
36
- subject.trigger_handler :event, nomatch_event
37
- subject.trigger_handler :event, event
40
+ subject.trigger_handler(:event, nomatch_event).should be_false
41
+ subject.trigger_handler(:event, event).should be_true
42
+ subject.trigger_handler(:event, event).should be_true
38
43
  end
39
44
 
40
45
  it 'can unregister a handler after registration' do
@@ -60,7 +65,7 @@ describe HasGuardedHandlers do
60
65
  throw :halt
61
66
  response.fail
62
67
  end
63
- subject.trigger_handler :event, event
68
+ subject.trigger_handler(:event, event).should be_true
64
69
  end
65
70
 
66
71
  it 'allows for passing to the next handler of the same type' do
@@ -75,7 +80,20 @@ describe HasGuardedHandlers do
75
80
  subject.register_handler :event do |_|
76
81
  response.handle2
77
82
  end
78
- subject.trigger_handler :event, event
83
+ subject.trigger_handler(:event, event).should be_true
84
+ end
85
+
86
+ context 'when there is nothing to pass to' do
87
+ it 'correctly indicates that a handler was called' do
88
+ response.expects(:handle1).once
89
+ response.expects(:fail).never
90
+ subject.register_handler :event do |_|
91
+ response.handle1
92
+ throw :pass
93
+ response.fail
94
+ end
95
+ subject.trigger_handler(:event, event).should be_true
96
+ end
79
97
  end
80
98
 
81
99
  describe 'when registering handlers with the same priority' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has-guarded-handlers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: 1393339349049738714
163
+ hash: -1217172567679436302
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: 1393339349049738714
172
+ hash: -1217172567679436302
173
173
  requirements: []
174
174
  rubyforge_project: has-guarded-handlers
175
175
  rubygems_version: 1.8.24