aasm 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/gemfiles/rails_3.2.gemfile +1 -1
- data/gemfiles/rails_4.0.gemfile +1 -1
- data/gemfiles/rails_4.1.gemfile +1 -1
- data/lib/aasm/event.rb +3 -3
- data/lib/aasm/transition.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/models/guard_within_block.rb +64 -0
- data/spec/unit/callbacks_spec.rb +43 -19
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0591e36b1ec9ec8d001ad39aa0acb2a2ca1b6b1e
|
4
|
+
data.tar.gz: a2ea3e316659e38c6f3ac4c97ebfd9028191188a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6226703caef5b98f8a113542fb881d05a061ef0a2cd7c634ad6660620c60974fe4dd16afecd2c1be9e7dc79323ab4bfae7ae735271b04fcef23d1182ec1ad7
|
7
|
+
data.tar.gz: 3d6182336e70ca8b07638545441f5cf75a93f1981f87d04ca3c7fad08cef0c3b14d7c4950f55efabbf9e1411c37be2cf4e9ba0a806b9ff45f219dccb4c357a21
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
* `aasm_human_event_name` is deprecated, use `aasm.human_event_name` instead
|
6
6
|
|
7
|
+
## 4.0.2
|
8
|
+
|
9
|
+
* bugfix: really support block-guards (defined within a transition block) (see [issue #186](https://github.com/aasm/aasm/issues/186) for details)
|
10
|
+
|
7
11
|
## 4.0.1
|
8
12
|
|
9
13
|
* fire guards only once per transition (see [issue #184](https://github.com/aasm/aasm/issues/184) for details)
|
data/README.md
CHANGED
@@ -270,11 +270,11 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
|
|
270
270
|
|
271
271
|
```ruby
|
272
272
|
event :clean do
|
273
|
-
transitions :from => :running, :to => :cleaning, :
|
273
|
+
transitions :from => :running, :to => :cleaning, :if => :cleaning_needed?
|
274
274
|
end
|
275
275
|
|
276
276
|
event :sleep do
|
277
|
-
transitions :from => :running, :to => :sleeping, :
|
277
|
+
transitions :from => :running, :to => :sleeping, :unless => :cleaning_needed?
|
278
278
|
end
|
279
279
|
end
|
280
280
|
```
|
data/gemfiles/rails_3.2.gemfile
CHANGED
@@ -6,7 +6,7 @@ gem 'rubysl', :platforms => :rbx
|
|
6
6
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
7
7
|
gem "jruby-openssl", :platforms => :jruby
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
|
-
gem "rails", "3.2.
|
9
|
+
gem "rails", "3.2.21"
|
10
10
|
gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
11
11
|
gem 'sequel'
|
12
12
|
|
data/gemfiles/rails_4.0.gemfile
CHANGED
@@ -6,7 +6,7 @@ gem 'rubysl', :platforms => :rbx
|
|
6
6
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
7
7
|
gem "jruby-openssl", :platforms => :jruby
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
|
-
gem "rails", "4.0.
|
9
|
+
gem "rails", "4.0.12"
|
10
10
|
|
11
11
|
# mongoid is not yet compatible with Rails >= 4
|
12
12
|
# gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
data/gemfiles/rails_4.1.gemfile
CHANGED
@@ -6,7 +6,7 @@ gem 'rubysl', :platforms => :rbx
|
|
6
6
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
7
7
|
gem "jruby-openssl", :platforms => :jruby
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
|
-
gem "rails", "4.1.
|
9
|
+
gem "rails", "4.1.8"
|
10
10
|
|
11
11
|
# mongoid is not yet compatible with Rails >= 4
|
12
12
|
# gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
data/lib/aasm/event.rb
CHANGED
@@ -57,15 +57,15 @@ module AASM
|
|
57
57
|
end
|
58
58
|
|
59
59
|
## DSL interface
|
60
|
-
def transitions(definitions=nil)
|
60
|
+
def transitions(definitions=nil, &block)
|
61
61
|
if definitions # define new transitions
|
62
62
|
# Create a separate transition for each from-state to the given state
|
63
63
|
Array(definitions[:from]).each do |s|
|
64
|
-
@transitions << AASM::Transition.new(attach_event_guards(definitions.merge(:from => s.to_sym)))
|
64
|
+
@transitions << AASM::Transition.new(attach_event_guards(definitions.merge(:from => s.to_sym)), &block)
|
65
65
|
end
|
66
66
|
# Create a transition if :to is specified without :from (transitions from ANY state)
|
67
67
|
if @transitions.empty? && definitions[:to]
|
68
|
-
@transitions << AASM::Transition.new(attach_event_guards(definitions))
|
68
|
+
@transitions << AASM::Transition.new(attach_event_guards(definitions), &block)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
@transitions
|
data/lib/aasm/transition.rb
CHANGED
@@ -10,7 +10,7 @@ module AASM
|
|
10
10
|
|
11
11
|
@from = opts[:from]
|
12
12
|
@to = opts[:to]
|
13
|
-
@guards = Array(opts[:
|
13
|
+
@guards = Array(opts[:guards]) + Array(opts[:guard]) + Array(opts[:if])
|
14
14
|
@unless = Array(opts[:unless]) #TODO: This could use a better name
|
15
15
|
|
16
16
|
if opts[:on_transition]
|
data/lib/aasm/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
class GuardWithinBlock
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
def initialize(options={})
|
5
|
+
@fail_event_guard = options[:fail_event_guard]
|
6
|
+
@fail_transition_guard = options[:fail_transition_guard]
|
7
|
+
@log = options[:log]
|
8
|
+
end
|
9
|
+
|
10
|
+
aasm do
|
11
|
+
state :open, :initial => true,
|
12
|
+
:before_enter => :before_enter_open,
|
13
|
+
:enter => :enter_open,
|
14
|
+
:after_enter => :after_enter_open,
|
15
|
+
:before_exit => :before_exit_open,
|
16
|
+
:exit => :exit_open,
|
17
|
+
:after_exit => :after_exit_open
|
18
|
+
|
19
|
+
state :closed,
|
20
|
+
:before_enter => :before_enter_closed,
|
21
|
+
:enter => :enter_closed,
|
22
|
+
:after_enter => :after_enter_closed,
|
23
|
+
:before_exit => :before_exit_closed,
|
24
|
+
:exit => :exit_closed,
|
25
|
+
:after_exit => :after_exit_closed
|
26
|
+
|
27
|
+
event :close, :before => :before, :after => :after, :guard => :event_guard do
|
28
|
+
transitions :to => :closed, :from => [:open], :after => :transitioning do
|
29
|
+
guard do
|
30
|
+
transition_guard
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
event :open, :before => :before, :after => :after do
|
36
|
+
transitions :to => :open, :from => :closed
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def log(text)
|
41
|
+
puts text if @log
|
42
|
+
end
|
43
|
+
|
44
|
+
def before_enter_open; log('before_enter_open'); end
|
45
|
+
def enter_open; log('enter_open'); end
|
46
|
+
def before_exit_open; log('before_exit_open'); end
|
47
|
+
def after_enter_open; log('after_enter_open'); end
|
48
|
+
def exit_open; log('exit_open'); end
|
49
|
+
def after_exit_open; log('after_exit_open'); end
|
50
|
+
|
51
|
+
def before_enter_closed; log('before_enter_closed'); end
|
52
|
+
def enter_closed; log('enter_closed'); end
|
53
|
+
def before_exit_closed; log('before_exit_closed'); end
|
54
|
+
def exit_closed; log('exit_closed'); end
|
55
|
+
def after_enter_closed; log('after_enter_closed'); end
|
56
|
+
def after_exit_closed; log('after_exit_closed'); end
|
57
|
+
|
58
|
+
def event_guard; log('event_guard'); !@fail_event_guard; end
|
59
|
+
def transition_guard; log('transition_guard'); !@fail_transition_guard; end
|
60
|
+
def transitioning; log('transitioning'); end
|
61
|
+
|
62
|
+
def before; log('before'); end
|
63
|
+
def after; log('after'); end
|
64
|
+
end
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -47,26 +47,50 @@ describe 'callbacks for the new DSL' do
|
|
47
47
|
}.to raise_error(AASM::InvalidTransition)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
callback
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
context "if the transition guard fails" do
|
51
|
+
it "does not run any state callback if guard is defined inline" do
|
52
|
+
callback = CallbackNewDsl.new
|
53
|
+
callback.aasm.current_state
|
54
|
+
|
55
|
+
expect(callback).to receive(:before).once.ordered
|
56
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
57
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
58
|
+
expect(callback).to_not receive(:before_exit_open)
|
59
|
+
expect(callback).to_not receive(:exit_open)
|
60
|
+
expect(callback).to_not receive(:transitioning)
|
61
|
+
expect(callback).to_not receive(:before_enter_closed)
|
62
|
+
expect(callback).to_not receive(:enter_closed)
|
63
|
+
expect(callback).to_not receive(:aasm_write_state)
|
64
|
+
expect(callback).to_not receive(:after_exit_open)
|
65
|
+
expect(callback).to_not receive(:after_enter_closed)
|
66
|
+
expect(callback).to_not receive(:after)
|
67
|
+
|
68
|
+
expect {
|
69
|
+
callback.close!
|
70
|
+
}.to raise_error(AASM::InvalidTransition)
|
71
|
+
end
|
66
72
|
|
67
|
-
|
68
|
-
callback.
|
69
|
-
|
73
|
+
it "does not run any state callback if guard is defined with block" do
|
74
|
+
callback = GuardWithinBlock.new #(:log => true, :fail_transition_guard => true)
|
75
|
+
callback.aasm.current_state
|
76
|
+
|
77
|
+
expect(callback).to receive(:before).once.ordered
|
78
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
79
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
80
|
+
expect(callback).to_not receive(:before_exit_open)
|
81
|
+
expect(callback).to_not receive(:exit_open)
|
82
|
+
expect(callback).to_not receive(:transitioning)
|
83
|
+
expect(callback).to_not receive(:before_enter_closed)
|
84
|
+
expect(callback).to_not receive(:enter_closed)
|
85
|
+
expect(callback).to_not receive(:aasm_write_state)
|
86
|
+
expect(callback).to_not receive(:after_exit_open)
|
87
|
+
expect(callback).to_not receive(:after_enter_closed)
|
88
|
+
expect(callback).to_not receive(:after)
|
89
|
+
|
90
|
+
expect {
|
91
|
+
callback.close!
|
92
|
+
}.to raise_error(AASM::InvalidTransition)
|
93
|
+
end
|
70
94
|
end
|
71
95
|
|
72
96
|
it "should properly pass arguments" do
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Barron
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-11-
|
13
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- spec/models/double_definer.rb
|
152
152
|
- spec/models/father.rb
|
153
153
|
- spec/models/foo.rb
|
154
|
+
- spec/models/guard_within_block.rb
|
154
155
|
- spec/models/guardian.rb
|
155
156
|
- spec/models/invalid_persistor.rb
|
156
157
|
- spec/models/mongoid/no_scope_mongoid.rb
|
@@ -225,6 +226,7 @@ test_files:
|
|
225
226
|
- spec/models/double_definer.rb
|
226
227
|
- spec/models/father.rb
|
227
228
|
- spec/models/foo.rb
|
229
|
+
- spec/models/guard_within_block.rb
|
228
230
|
- spec/models/guardian.rb
|
229
231
|
- spec/models/invalid_persistor.rb
|
230
232
|
- spec/models/mongoid/no_scope_mongoid.rb
|