aasm 4.0.6 → 4.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -9
- data/CHANGELOG.md +4 -0
- data/aasm.gemspec +2 -0
- data/lib/aasm/core/event.rb +2 -2
- data/lib/aasm/version.rb +1 -1
- data/spec/models/callbacks/private_method.rb +44 -0
- data/spec/unit/callbacks_spec.rb +13 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b5ff962a4061c7b5c90ef8615cc68a91201001c
|
4
|
+
data.tar.gz: 5f05fb22ab55b5e2101ed50ecd270182ffa16d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd75c3602fc6d7f0a432f8a776434f8db864998533f59227de2a617bc1f346bbaa7ef28884b3ecf242e215506d9c1f77f3fbd88c223f8b0631c2d2ea439dfc4
|
7
|
+
data.tar.gz: 61d2d2b38f233d7241b21a122e748cc6ded58f15475bca1a557febb4523cb288d050f0f5208d1bc3820411dbe6b7959105dfe123c5e441beb49d2379003e452d
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ cache: bundler
|
|
4
4
|
|
5
5
|
rvm:
|
6
6
|
# - 1.8.7
|
7
|
-
- 1.9.2
|
7
|
+
# - 1.9.2
|
8
8
|
- 1.9.3
|
9
9
|
- 2.0.0
|
10
10
|
- 2.1
|
@@ -24,14 +24,6 @@ matrix:
|
|
24
24
|
- rvm: rbx-2.2.1
|
25
25
|
- rvm: jruby-19mode
|
26
26
|
exclude:
|
27
|
-
- rvm: 1.8.7
|
28
|
-
gemfile: gemfiles/rails_4.0.gemfile
|
29
|
-
- rvm: 1.8.7
|
30
|
-
gemfile: gemfiles/rails_4.1.gemfile
|
31
|
-
- rvm: 1.9.2
|
32
|
-
gemfile: gemfiles/rails_4.0.gemfile
|
33
|
-
- rvm: 1.9.2
|
34
|
-
gemfile: gemfiles/rails_4.1.gemfile
|
35
27
|
- rvm: 1.9.3
|
36
28
|
gemfile: gemfiles/rails_4.1.gemfile
|
37
29
|
- rvm: jruby-19mode
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
* `aasm_column` has been removed. Use `aasm.attribute_name` instead
|
6
6
|
* `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
|
7
7
|
|
8
|
+
## 4.0.7
|
9
|
+
|
10
|
+
* bugfix: take private methods into account when checking for callbacks (see [issue #197](https://github.com/aasm/aasm/issues/197) for details)
|
11
|
+
|
8
12
|
## 4.0.6
|
9
13
|
|
10
14
|
* bugfix: `false` is treated as uninitialised state (same as `nil`) (see [issue #195](https://github.com/aasm/aasm/issues/195) for details)
|
data/aasm.gemspec
CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
# s.add_development_dependency 'mime-types', '~> 1.25' # needed by coveralls (>= 2.0 needs Ruby >=1.9.2)
|
26
26
|
# s.add_development_dependency 'coveralls'
|
27
27
|
|
28
|
+
s.platform = Gem::Platform::RUBY
|
29
|
+
# s.required_ruby_version = '>= 1.9.3'
|
28
30
|
s.files = `git ls-files`.split("\n")
|
29
31
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
32
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/aasm/core/event.rb
CHANGED
@@ -124,8 +124,8 @@ module AASM::Core
|
|
124
124
|
def invoke_callbacks(code, record, args)
|
125
125
|
case code
|
126
126
|
when Symbol, String
|
127
|
-
unless record.respond_to?(code)
|
128
|
-
raise NoMethodError.new("NoMethodError: undefined method `#{code}' for #{
|
127
|
+
unless record.respond_to?(code, true)
|
128
|
+
raise NoMethodError.new("NoMethodError: undefined method `#{code}' for #{record.inspect}:#{record.class}")
|
129
129
|
end
|
130
130
|
arity = record.send(:method, code.to_sym).arity
|
131
131
|
record.send(code, *(arity < 0 ? args : args[0...arity]))
|
data/lib/aasm/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Callbacks
|
2
|
+
class PrivateMethod
|
3
|
+
include AASM
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@fail_event_guard = options[:fail_event_guard]
|
7
|
+
@fail_transition_guard = options[:fail_transition_guard]
|
8
|
+
@log = options[:log]
|
9
|
+
reset_data
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset_data
|
13
|
+
@data = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
@data.join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
aasm do
|
21
|
+
state :open, :initial => true
|
22
|
+
state :closed
|
23
|
+
|
24
|
+
event :close, :after => :after_event do
|
25
|
+
transitions :to => :closed, :from => [:open]
|
26
|
+
end
|
27
|
+
|
28
|
+
event :open, :after => :after_event do
|
29
|
+
transitions :to => :open, :from => :closed
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def log(text)
|
34
|
+
@data << text
|
35
|
+
puts text if @log
|
36
|
+
end
|
37
|
+
|
38
|
+
def aasm_write_state(*args); log('aasm_write_state'); true; end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def after_event; log('after_event'); end
|
43
|
+
end
|
44
|
+
end
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -52,6 +52,18 @@ describe 'callbacks for the new DSL' do
|
|
52
52
|
}.to raise_error(AASM::InvalidTransition)
|
53
53
|
end
|
54
54
|
|
55
|
+
it "it handles private callback methods as well" do
|
56
|
+
show_debug_log = false
|
57
|
+
|
58
|
+
callback = Callbacks::PrivateMethod.new(:log => show_debug_log)
|
59
|
+
callback.aasm.current_state
|
60
|
+
|
61
|
+
# puts "------- close!"
|
62
|
+
expect {
|
63
|
+
callback.close!
|
64
|
+
}.to_not raise_error
|
65
|
+
end
|
66
|
+
|
55
67
|
context "if the transition guard fails" do
|
56
68
|
it "does not run any state callback if guard is defined inline" do
|
57
69
|
show_debug_log = false
|
@@ -279,4 +291,5 @@ describe 'event callbacks' do
|
|
279
291
|
@foo.close!
|
280
292
|
end
|
281
293
|
end
|
294
|
+
|
282
295
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Barron
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- spec/models/callbacks/basic.rb
|
123
123
|
- spec/models/callbacks/guard_within_block.rb
|
124
124
|
- spec/models/callbacks/multiple_transitions_transition_guard.rb
|
125
|
+
- spec/models/callbacks/private_method.rb
|
125
126
|
- spec/models/callbacks/with_args.rb
|
126
127
|
- spec/models/callbacks/with_state_args.rb
|
127
128
|
- spec/models/conversation.rb
|
@@ -200,6 +201,7 @@ test_files:
|
|
200
201
|
- spec/models/callbacks/basic.rb
|
201
202
|
- spec/models/callbacks/guard_within_block.rb
|
202
203
|
- spec/models/callbacks/multiple_transitions_transition_guard.rb
|
204
|
+
- spec/models/callbacks/private_method.rb
|
203
205
|
- spec/models/callbacks/with_args.rb
|
204
206
|
- spec/models/callbacks/with_state_args.rb
|
205
207
|
- spec/models/conversation.rb
|