aasm 4.0.3 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +10 -11
- data/CHANGELOG.md +28 -1
- data/Gemfile +6 -2
- data/README.md +31 -12
- data/README_FROM_VERSION_3_TO_4.md +1 -1
- data/aasm.gemspec +9 -10
- data/gemfiles/rails_3.2.gemfile +3 -1
- data/gemfiles/rails_4.0.gemfile +2 -5
- data/gemfiles/rails_4.0_bson1.gemfile +14 -0
- data/gemfiles/rails_4.1.gemfile +2 -5
- data/gemfiles/rails_4.1_bson1.gemfile +14 -0
- data/gemfiles/rails_4.2.gemfile +13 -0
- data/gemfiles/rails_4.2_bson1.gemfile +14 -0
- data/lib/aasm/aasm.rb +1 -19
- data/lib/aasm/base.rb +8 -8
- data/lib/aasm/{event.rb → core/event.rb} +13 -5
- data/lib/aasm/{state.rb → core/state.rb} +1 -1
- data/lib/aasm/{transition.rb → core/transition.rb} +1 -3
- data/lib/aasm/instance_base.rb +1 -1
- data/lib/aasm/persistence/active_record_persistence.rb +14 -13
- data/lib/aasm/persistence/base.rb +4 -1
- data/lib/aasm/persistence/mongo_mapper_persistence.rb +174 -0
- data/lib/aasm/persistence/mongoid_persistence.rb +5 -7
- data/lib/aasm/persistence/plain_persistence.rb +24 -0
- data/lib/aasm/persistence/sequel_persistence.rb +2 -0
- data/lib/aasm/persistence.rb +19 -11
- data/lib/aasm/state_machine.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/lib/aasm.rb +13 -15
- data/spec/database.rb +5 -1
- data/spec/models/callbacks/basic.rb +75 -0
- data/spec/models/callbacks/guard_within_block.rb +66 -0
- data/spec/models/callbacks/private_method.rb +44 -0
- data/spec/models/callbacks/with_args.rb +61 -0
- data/spec/models/callbacks/with_state_args.rb +26 -0
- data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +10 -0
- data/spec/models/mongo_mapper/simple_mongo_mapper.rb +11 -0
- data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +12 -0
- data/spec/models/mongoid/simple_new_dsl_mongoid.rb +1 -1
- data/spec/models/persistence.rb +79 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/unit/callbacks_spec.rb +101 -62
- data/spec/unit/complex_example_spec.rb +9 -9
- data/spec/unit/event_spec.rb +12 -12
- data/spec/unit/inspection_spec.rb +2 -2
- data/spec/unit/memory_leak_spec.rb +12 -12
- data/spec/unit/persistence/active_record_persistence_spec.rb +58 -72
- data/spec/unit/persistence/mongo_mapper_persistance_spec.rb +135 -0
- data/spec/unit/persistence/mongoid_persistance_spec.rb +4 -10
- data/spec/unit/persistence/sequel_persistence_spec.rb +2 -1
- data/spec/unit/state_spec.rb +2 -2
- data/spec/unit/subclassing_spec.rb +1 -1
- data/spec/unit/transition_spec.rb +33 -33
- metadata +32 -40
- data/spec/models/callback_new_dsl.rb +0 -129
- data/spec/models/guard_within_block.rb +0 -64
data/spec/models/persistence.rb
CHANGED
|
@@ -2,7 +2,29 @@ class Gate < ActiveRecord::Base
|
|
|
2
2
|
include AASM
|
|
3
3
|
|
|
4
4
|
# Fake this column for testing purposes
|
|
5
|
-
attr_accessor :aasm_state
|
|
5
|
+
# attr_accessor :aasm_state
|
|
6
|
+
|
|
7
|
+
def value
|
|
8
|
+
'value'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
aasm do
|
|
12
|
+
state :opened
|
|
13
|
+
state :closed
|
|
14
|
+
|
|
15
|
+
event :view do
|
|
16
|
+
transitions :to => :read, :from => [:needs_attention]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class FalseState < ActiveRecord::Base
|
|
22
|
+
include AASM
|
|
23
|
+
|
|
24
|
+
def initialize(*args)
|
|
25
|
+
super
|
|
26
|
+
self.aasm_state = false
|
|
27
|
+
end
|
|
6
28
|
|
|
7
29
|
aasm do
|
|
8
30
|
state :opened
|
|
@@ -14,6 +36,62 @@ class Gate < ActiveRecord::Base
|
|
|
14
36
|
end
|
|
15
37
|
end
|
|
16
38
|
|
|
39
|
+
class WithEnum < ActiveRecord::Base
|
|
40
|
+
include AASM
|
|
41
|
+
|
|
42
|
+
# Fake this column for testing purposes
|
|
43
|
+
attr_accessor :aasm_state
|
|
44
|
+
|
|
45
|
+
def self.test
|
|
46
|
+
{}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
aasm :enum => :test do
|
|
50
|
+
state :opened
|
|
51
|
+
state :closed
|
|
52
|
+
|
|
53
|
+
event :view do
|
|
54
|
+
transitions :to => :read, :from => [:needs_attention]
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class WithTrueEnum < ActiveRecord::Base
|
|
60
|
+
include AASM
|
|
61
|
+
|
|
62
|
+
# Fake this column for testing purposes
|
|
63
|
+
attr_accessor :aasm_state
|
|
64
|
+
|
|
65
|
+
def value
|
|
66
|
+
'value'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
aasm :enum => true do
|
|
70
|
+
state :opened
|
|
71
|
+
state :closed
|
|
72
|
+
|
|
73
|
+
event :view do
|
|
74
|
+
transitions :to => :read, :from => [:needs_attention]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class WithFalseEnum < ActiveRecord::Base
|
|
80
|
+
include AASM
|
|
81
|
+
|
|
82
|
+
# Fake this column for testing purposes
|
|
83
|
+
attr_accessor :aasm_state
|
|
84
|
+
|
|
85
|
+
aasm :enum => false do
|
|
86
|
+
state :opened
|
|
87
|
+
state :closed
|
|
88
|
+
|
|
89
|
+
event :view do
|
|
90
|
+
transitions :to => :read, :from => [:needs_attention]
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
17
95
|
class Reader < ActiveRecord::Base
|
|
18
96
|
include AASM
|
|
19
97
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,7 +3,6 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
|
|
|
3
3
|
require 'aasm'
|
|
4
4
|
|
|
5
5
|
require 'rspec'
|
|
6
|
-
require 'rspec/autorun'
|
|
7
6
|
|
|
8
7
|
require 'coveralls'
|
|
9
8
|
Coveralls.wear!
|
|
@@ -12,6 +11,8 @@ Coveralls.wear!
|
|
|
12
11
|
# require 'ruby-debug/completion'
|
|
13
12
|
# require 'pry'
|
|
14
13
|
|
|
14
|
+
SEQUEL_DB = defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
|
15
|
+
|
|
15
16
|
def load_schema
|
|
16
17
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
|
17
18
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
data/spec/unit/callbacks_spec.rb
CHANGED
|
@@ -1,71 +1,88 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
Dir[File.dirname(__FILE__) + "/../models/callbacks/*.rb"].sort.each { |f| require File.expand_path(f) }
|
|
2
3
|
|
|
3
4
|
describe 'callbacks for the new DSL' do
|
|
4
5
|
|
|
5
6
|
it "be called in order" do
|
|
6
|
-
|
|
7
|
+
show_debug_log = false
|
|
8
|
+
|
|
9
|
+
callback = Callbacks::Basic.new(:log => show_debug_log)
|
|
7
10
|
callback.aasm.current_state
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
unless show_debug_log
|
|
13
|
+
expect(callback).to receive(:before_event).once.ordered
|
|
14
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
|
15
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
|
16
|
+
expect(callback).to receive(:before_exit_open).once.ordered # these should be before the state changes
|
|
17
|
+
expect(callback).to receive(:exit_open).once.ordered
|
|
18
|
+
# expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
|
19
|
+
# expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
|
20
|
+
expect(callback).to receive(:after_transition).once.ordered
|
|
21
|
+
expect(callback).to receive(:before_enter_closed).once.ordered
|
|
22
|
+
expect(callback).to receive(:enter_closed).once.ordered
|
|
23
|
+
expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
|
24
|
+
expect(callback).to receive(:after_exit_open).once.ordered # these should be after the state changes
|
|
25
|
+
expect(callback).to receive(:after_enter_closed).once.ordered
|
|
26
|
+
expect(callback).to receive(:after_event).once.ordered
|
|
27
|
+
end
|
|
23
28
|
|
|
24
29
|
# puts "------- close!"
|
|
25
30
|
callback.close!
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
it "does not run any state callback if the event guard fails" do
|
|
29
|
-
callback =
|
|
34
|
+
callback = Callbacks::Basic.new(:log => false)
|
|
30
35
|
callback.aasm.current_state
|
|
31
36
|
|
|
32
|
-
expect(callback).to receive(:
|
|
37
|
+
expect(callback).to receive(:before_event).once.ordered
|
|
33
38
|
expect(callback).to receive(:event_guard).once.ordered.and_return(false)
|
|
34
39
|
expect(callback).to_not receive(:transition_guard)
|
|
35
40
|
expect(callback).to_not receive(:before_exit_open)
|
|
36
41
|
expect(callback).to_not receive(:exit_open)
|
|
37
|
-
expect(callback).to_not receive(:
|
|
42
|
+
expect(callback).to_not receive(:after_transition)
|
|
38
43
|
expect(callback).to_not receive(:before_enter_closed)
|
|
39
44
|
expect(callback).to_not receive(:enter_closed)
|
|
40
45
|
expect(callback).to_not receive(:aasm_write_state)
|
|
41
46
|
expect(callback).to_not receive(:after_exit_open)
|
|
42
47
|
expect(callback).to_not receive(:after_enter_closed)
|
|
43
|
-
expect(callback).to_not receive(:
|
|
48
|
+
expect(callback).to_not receive(:after_event)
|
|
44
49
|
|
|
45
50
|
expect {
|
|
46
51
|
callback.close!
|
|
47
52
|
}.to raise_error(AASM::InvalidTransition)
|
|
48
53
|
end
|
|
49
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
|
+
|
|
50
67
|
context "if the transition guard fails" do
|
|
51
68
|
it "does not run any state callback if guard is defined inline" do
|
|
52
69
|
show_debug_log = false
|
|
53
|
-
callback =
|
|
70
|
+
callback = Callbacks::Basic.new(:log => show_debug_log, :fail_transition_guard => true)
|
|
54
71
|
callback.aasm.current_state
|
|
55
72
|
|
|
56
73
|
unless show_debug_log
|
|
57
|
-
expect(callback).to receive(:
|
|
74
|
+
expect(callback).to receive(:before_event).once.ordered
|
|
58
75
|
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
|
59
76
|
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
|
60
77
|
expect(callback).to_not receive(:before_exit_open)
|
|
61
78
|
expect(callback).to_not receive(:exit_open)
|
|
62
|
-
expect(callback).to_not receive(:
|
|
79
|
+
expect(callback).to_not receive(:after_transition)
|
|
63
80
|
expect(callback).to_not receive(:before_enter_closed)
|
|
64
81
|
expect(callback).to_not receive(:enter_closed)
|
|
65
82
|
expect(callback).to_not receive(:aasm_write_state)
|
|
66
83
|
expect(callback).to_not receive(:after_exit_open)
|
|
67
84
|
expect(callback).to_not receive(:after_enter_closed)
|
|
68
|
-
expect(callback).to_not receive(:
|
|
85
|
+
expect(callback).to_not receive(:after_event)
|
|
69
86
|
end
|
|
70
87
|
|
|
71
88
|
expect {
|
|
@@ -74,8 +91,6 @@ describe 'callbacks for the new DSL' do
|
|
|
74
91
|
end
|
|
75
92
|
|
|
76
93
|
it "does not run transition_guard twice for multiple permitted transitions" do
|
|
77
|
-
require 'models/callbacks/multiple_transitions_transition_guard'
|
|
78
|
-
|
|
79
94
|
show_debug_log = false
|
|
80
95
|
callback = Callbacks::MultipleTransitionsTransitionGuard.new(:log => show_debug_log, :fail_transition_guard => true)
|
|
81
96
|
callback.aasm.current_state
|
|
@@ -102,7 +117,7 @@ describe 'callbacks for the new DSL' do
|
|
|
102
117
|
end
|
|
103
118
|
|
|
104
119
|
it "does not run any state callback if guard is defined with block" do
|
|
105
|
-
callback = GuardWithinBlock.new #(:log => true, :fail_transition_guard => true)
|
|
120
|
+
callback = Callbacks::GuardWithinBlock.new #(:log => true, :fail_transition_guard => true)
|
|
106
121
|
callback.aasm.current_state
|
|
107
122
|
|
|
108
123
|
expect(callback).to receive(:before).once.ordered
|
|
@@ -125,51 +140,44 @@ describe 'callbacks for the new DSL' do
|
|
|
125
140
|
end
|
|
126
141
|
|
|
127
142
|
it "should properly pass arguments" do
|
|
128
|
-
cb =
|
|
129
|
-
|
|
130
|
-
# TODO: use expect syntax here
|
|
131
|
-
cb.should_receive(:before).with(:arg1, :arg2).once.ordered
|
|
132
|
-
cb.should_receive(:before_exit_open).once.ordered # these should be before the state changes
|
|
133
|
-
cb.should_receive(:transition_proc).with(:arg1, :arg2).once.ordered
|
|
134
|
-
cb.should_receive(:before_enter_closed).once.ordered
|
|
135
|
-
cb.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
|
136
|
-
cb.should_receive(:after_exit_open).once.ordered # these should be after the state changes
|
|
137
|
-
cb.should_receive(:after_enter_closed).once.ordered
|
|
138
|
-
cb.should_receive(:after).with(:arg1, :arg2).once.ordered
|
|
143
|
+
cb = Callbacks::WithArgs.new(:log => false)
|
|
144
|
+
cb.aasm.current_state
|
|
139
145
|
|
|
146
|
+
cb.reset_data
|
|
140
147
|
cb.close!(:arg1, :arg2)
|
|
148
|
+
expect(cb.data).to eql 'before(:arg1,:arg2) before_exit_open transition_proc(:arg1,:arg2) before_enter_closed aasm_write_state after_exit_open after_enter_closed after(:arg1,:arg2)'
|
|
141
149
|
end
|
|
142
150
|
|
|
143
151
|
it "should call the callbacks given the to-state as argument" do
|
|
144
|
-
cb =
|
|
145
|
-
cb.
|
|
146
|
-
cb.
|
|
147
|
-
cb.
|
|
148
|
-
cb.
|
|
152
|
+
cb = Callbacks::WithStateArg.new
|
|
153
|
+
expect(cb).to receive(:before_method).with(:arg1).once.ordered
|
|
154
|
+
expect(cb).to receive(:transition_method).never
|
|
155
|
+
expect(cb).to receive(:transition_method2).with(:arg1).once.ordered
|
|
156
|
+
expect(cb).to receive(:after_method).with(:arg1).once.ordered
|
|
149
157
|
cb.close!(:out_to_lunch, :arg1)
|
|
150
158
|
|
|
151
|
-
cb =
|
|
159
|
+
cb = Callbacks::WithStateArg.new
|
|
152
160
|
some_object = double('some object')
|
|
153
|
-
cb.
|
|
154
|
-
cb.
|
|
155
|
-
cb.
|
|
161
|
+
expect(cb).to receive(:before_method).with(some_object).once.ordered
|
|
162
|
+
expect(cb).to receive(:transition_method2).with(some_object).once.ordered
|
|
163
|
+
expect(cb).to receive(:after_method).with(some_object).once.ordered
|
|
156
164
|
cb.close!(:out_to_lunch, some_object)
|
|
157
165
|
end
|
|
158
166
|
|
|
159
167
|
it "should call the proper methods just with arguments" do
|
|
160
|
-
cb =
|
|
161
|
-
cb.
|
|
162
|
-
cb.
|
|
163
|
-
cb.
|
|
164
|
-
cb.
|
|
168
|
+
cb = Callbacks::WithStateArg.new
|
|
169
|
+
expect(cb).to receive(:before_method).with(:arg1).once.ordered
|
|
170
|
+
expect(cb).to receive(:transition_method).with(:arg1).once.ordered
|
|
171
|
+
expect(cb).to receive(:transition_method).never
|
|
172
|
+
expect(cb).to receive(:after_method).with(:arg1).once.ordered
|
|
165
173
|
cb.close!(:arg1)
|
|
166
174
|
|
|
167
|
-
cb =
|
|
175
|
+
cb = Callbacks::WithStateArg.new
|
|
168
176
|
some_object = double('some object')
|
|
169
|
-
cb.
|
|
170
|
-
cb.
|
|
171
|
-
cb.
|
|
172
|
-
cb.
|
|
177
|
+
expect(cb).to receive(:before_method).with(some_object).once.ordered
|
|
178
|
+
expect(cb).to receive(:transition_method).with(some_object).once.ordered
|
|
179
|
+
expect(cb).to receive(:transition_method).never
|
|
180
|
+
expect(cb).to receive(:after_method).with(some_object).once.ordered
|
|
173
181
|
cb.close!(some_object)
|
|
174
182
|
end
|
|
175
183
|
end
|
|
@@ -178,6 +186,10 @@ describe 'event callbacks' do
|
|
|
178
186
|
describe "with an error callback defined" do
|
|
179
187
|
before do
|
|
180
188
|
class Foo
|
|
189
|
+
# this hack is needed to allow testing of parameters, since RSpec
|
|
190
|
+
# destroys a method's arity when mocked
|
|
191
|
+
attr_accessor :data
|
|
192
|
+
|
|
181
193
|
aasm do
|
|
182
194
|
event :safe_close, :success => :success_callback, :error => :error_callback do
|
|
183
195
|
transitions :to => :closed, :from => [:open]
|
|
@@ -188,16 +200,42 @@ describe 'event callbacks' do
|
|
|
188
200
|
@foo = Foo.new
|
|
189
201
|
end
|
|
190
202
|
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
context "error_callback defined" do
|
|
204
|
+
it "should run error_callback if an exception is raised" do
|
|
205
|
+
def @foo.error_callback(e)
|
|
206
|
+
@data = [e]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
|
|
210
|
+
|
|
211
|
+
@foo.safe_close!
|
|
212
|
+
expect(@foo.data).to eql [e]
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "should run error_callback without parameters if callback does not support any" do
|
|
216
|
+
def @foo.error_callback(e)
|
|
217
|
+
@data = []
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
|
|
221
|
+
|
|
222
|
+
@foo.safe_close!('arg1', 'arg2')
|
|
223
|
+
expect(@foo.data).to eql []
|
|
224
|
+
end
|
|
193
225
|
|
|
194
|
-
|
|
195
|
-
|
|
226
|
+
it "should run error_callback with parameters if callback supports them" do
|
|
227
|
+
def @foo.error_callback(e, arg1, arg2)
|
|
228
|
+
@data = [arg1, arg2]
|
|
229
|
+
end
|
|
196
230
|
|
|
197
|
-
|
|
231
|
+
allow(@foo).to receive(:before_enter).and_raise(e = StandardError.new)
|
|
232
|
+
|
|
233
|
+
@foo.safe_close!('arg1', 'arg2')
|
|
234
|
+
expect(@foo.data).to eql ['arg1', 'arg2']
|
|
235
|
+
end
|
|
198
236
|
end
|
|
199
237
|
|
|
200
|
-
it "should raise NoMethodError if
|
|
238
|
+
it "should raise NoMethodError if exception is raised and error_callback is declared but not defined" do
|
|
201
239
|
allow(@foo).to receive(:before_enter).and_raise(StandardError)
|
|
202
240
|
expect{@foo.safe_close!}.to raise_error(NoMethodError)
|
|
203
241
|
end
|
|
@@ -253,4 +291,5 @@ describe 'event callbacks' do
|
|
|
253
291
|
@foo.close!
|
|
254
292
|
end
|
|
255
293
|
end
|
|
294
|
+
|
|
256
295
|
end
|
|
@@ -8,7 +8,7 @@ describe 'on initialization' do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'should have an activation code' do
|
|
11
|
-
expect(auth.has_activation_code?).to
|
|
11
|
+
expect(auth.has_activation_code?).to be_truthy
|
|
12
12
|
expect(auth.activation_code).not_to be_nil
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -19,24 +19,24 @@ describe 'when being unsuspended' do
|
|
|
19
19
|
it 'should be able to be unsuspended' do
|
|
20
20
|
auth.activate!
|
|
21
21
|
auth.suspend!
|
|
22
|
-
expect(auth.may_unsuspend?).to
|
|
22
|
+
expect(auth.may_unsuspend?).to be true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'should not be able to be unsuspended into active' do
|
|
26
26
|
auth.suspend!
|
|
27
|
-
expect(auth.may_unsuspend?(:active)).not_to
|
|
27
|
+
expect(auth.may_unsuspend?(:active)).not_to be true
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'should be able to be unsuspended into active if polite' do
|
|
31
31
|
auth.suspend!
|
|
32
|
-
expect(auth.may_wait?(:waiting, :please)).to
|
|
32
|
+
expect(auth.may_wait?(:waiting, :please)).to be true
|
|
33
33
|
auth.wait!(nil, :please)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should not be able to be unsuspended into active if not polite' do
|
|
37
37
|
auth.suspend!
|
|
38
|
-
expect(auth.may_wait?(:waiting)).not_to
|
|
39
|
-
expect(auth.may_wait?(:waiting, :rude)).not_to
|
|
38
|
+
expect(auth.may_wait?(:waiting)).not_to be true
|
|
39
|
+
expect(auth.may_wait?(:waiting, :rude)).not_to be true
|
|
40
40
|
expect {auth.wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
|
|
41
41
|
expect {auth.wait!}.to raise_error(AASM::InvalidTransition)
|
|
42
42
|
end
|
|
@@ -46,7 +46,7 @@ describe 'when being unsuspended' do
|
|
|
46
46
|
auth.suspend!
|
|
47
47
|
auth.unsuspend!
|
|
48
48
|
|
|
49
|
-
expect(auth.may_unpassify?).not_to
|
|
49
|
+
expect(auth.may_unpassify?).not_to be true
|
|
50
50
|
expect {auth.unpassify!}.to raise_error(AASM::InvalidTransition)
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -74,11 +74,11 @@ describe 'when being unsuspended' do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "should be able to fire known events" do
|
|
77
|
-
expect(auth.aasm.may_fire_event?(:activate)).to
|
|
77
|
+
expect(auth.aasm.may_fire_event?(:activate)).to be true
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "should not be able to fire unknown events" do
|
|
81
|
-
expect(auth.aasm.may_fire_event?(:unknown)).to
|
|
81
|
+
expect(auth.aasm.may_fire_event?(:unknown)).to be false
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
end
|
data/spec/unit/event_spec.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe 'adding an event' do
|
|
4
4
|
let(:event) do
|
|
5
|
-
AASM::Event.new(:close_order, {:success => :success_callback}) do
|
|
5
|
+
AASM::Core::Event.new(:close_order, {:success => :success_callback}) do
|
|
6
6
|
before :before_callback
|
|
7
7
|
after :after_callback
|
|
8
8
|
transitions :to => :closed, :from => [:open, :received]
|
|
@@ -36,41 +36,41 @@ end
|
|
|
36
36
|
|
|
37
37
|
describe 'transition inspection' do
|
|
38
38
|
let(:event) do
|
|
39
|
-
AASM::Event.new(:run) do
|
|
39
|
+
AASM::Core::Event.new(:run) do
|
|
40
40
|
transitions :to => :running, :from => :sleeping
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it 'should support inspecting transitions from other states' do
|
|
45
45
|
expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
|
|
46
|
-
expect(event.transitions_from_state?(:sleeping)).to
|
|
46
|
+
expect(event.transitions_from_state?(:sleeping)).to be_truthy
|
|
47
47
|
|
|
48
48
|
expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([])
|
|
49
|
-
expect(event.transitions_from_state?(:cleaning)).to
|
|
49
|
+
expect(event.transitions_from_state?(:cleaning)).to be_falsey
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it 'should support inspecting transitions to other states' do
|
|
53
53
|
expect(event.transitions_to_state(:running).map(&:from)).to eq([:sleeping])
|
|
54
|
-
expect(event.transitions_to_state?(:running)).to
|
|
54
|
+
expect(event.transitions_to_state?(:running)).to be_truthy
|
|
55
55
|
|
|
56
56
|
expect(event.transitions_to_state(:cleaning).map(&:to)).to eq([])
|
|
57
|
-
expect(event.transitions_to_state?(:cleaning)).to
|
|
57
|
+
expect(event.transitions_to_state?(:cleaning)).to be_falsey
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
describe 'transition inspection without from' do
|
|
62
62
|
let(:event) do
|
|
63
|
-
AASM::Event.new(:run) do
|
|
63
|
+
AASM::Core::Event.new(:run) do
|
|
64
64
|
transitions :to => :running
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it 'should support inspecting transitions from other states' do
|
|
69
69
|
expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
|
|
70
|
-
expect(event.transitions_from_state?(:sleeping)).to
|
|
70
|
+
expect(event.transitions_from_state?(:sleeping)).to be_truthy
|
|
71
71
|
|
|
72
72
|
expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([:running])
|
|
73
|
-
expect(event.transitions_from_state?(:cleaning)).to
|
|
73
|
+
expect(event.transitions_from_state?(:cleaning)).to be_truthy
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
end
|
|
@@ -79,12 +79,12 @@ describe 'firing an event' do
|
|
|
79
79
|
it 'should return nil if the transitions are empty' do
|
|
80
80
|
obj = double('object', :aasm => double('aasm', :current_state => 'open'))
|
|
81
81
|
|
|
82
|
-
event = AASM::Event.new(:event)
|
|
82
|
+
event = AASM::Core::Event.new(:event)
|
|
83
83
|
expect(event.fire(obj)).to be_nil
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it 'should return the state of the first matching transition it finds' do
|
|
87
|
-
event = AASM::Event.new(:event) do
|
|
87
|
+
event = AASM::Core::Event.new(:event) do
|
|
88
88
|
transitions :to => :closed, :from => [:open, :received]
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -94,7 +94,7 @@ describe 'firing an event' do
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
it 'should call the guard with the params passed in' do
|
|
97
|
-
event = AASM::Event.new(:event) do
|
|
97
|
+
event = AASM::Core::Event.new(:event) do
|
|
98
98
|
transitions :to => :closed, :from => [:open, :received], :guard => :guard_fn
|
|
99
99
|
end
|
|
100
100
|
|
|
@@ -67,11 +67,11 @@ describe "special cases" do
|
|
|
67
67
|
expect(Argument.aasm.states).to include(:valid)
|
|
68
68
|
|
|
69
69
|
argument = Argument.new
|
|
70
|
-
expect(argument.invalid?).to
|
|
70
|
+
expect(argument.invalid?).to be_truthy
|
|
71
71
|
expect(argument.aasm.current_state).to eq(:invalid)
|
|
72
72
|
|
|
73
73
|
argument.valid!
|
|
74
|
-
expect(argument.valid?).to
|
|
74
|
+
expect(argument.valid?).to be_truthy
|
|
75
75
|
expect(argument.aasm.current_state).to eq(:valid)
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -12,27 +12,27 @@
|
|
|
12
12
|
|
|
13
13
|
# it "should be created without memory leak" do
|
|
14
14
|
# machines_count = machines.size
|
|
15
|
-
# state_count = number_of_objects(AASM::State)
|
|
16
|
-
# event_count = number_of_objects(AASM::Event)
|
|
15
|
+
# state_count = number_of_objects(AASM::Core::State)
|
|
16
|
+
# event_count = number_of_objects(AASM::Core::Event)
|
|
17
17
|
# puts "event_count = #{event_count}"
|
|
18
|
-
# transition_count = number_of_objects(AASM::Transition)
|
|
18
|
+
# transition_count = number_of_objects(AASM::Core::Transition)
|
|
19
19
|
|
|
20
20
|
# load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb')
|
|
21
21
|
# machines.size.should == machines_count + 1 # + Process
|
|
22
22
|
# number_of_objects(Models::Process).should == 0
|
|
23
|
-
# number_of_objects(AASM::State).should == state_count + 3 # + Process
|
|
24
|
-
# puts "event_count = #{number_of_objects(AASM::Event)}"
|
|
25
|
-
# number_of_objects(AASM::Event).should == event_count + 2 # + Process
|
|
26
|
-
# number_of_objects(AASM::Transition).should == transition_count + 2 # + Process
|
|
23
|
+
# number_of_objects(AASM::Core::State).should == state_count + 3 # + Process
|
|
24
|
+
# puts "event_count = #{number_of_objects(AASM::Core::Event)}"
|
|
25
|
+
# number_of_objects(AASM::Core::Event).should == event_count + 2 # + Process
|
|
26
|
+
# number_of_objects(AASM::Core::Transition).should == transition_count + 2 # + Process
|
|
27
27
|
|
|
28
28
|
# Models.send(:remove_const, "Process") if Models.const_defined?("Process")
|
|
29
29
|
# load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb')
|
|
30
30
|
# machines.size.should == machines_count + 1 # + Process
|
|
31
|
-
# number_of_objects(AASM::State).should == state_count + 3 # + Process
|
|
32
|
-
# # ObjectSpace.each_object(AASM::Event) {|o| puts o.inspect}
|
|
33
|
-
# puts "event_count = #{number_of_objects(AASM::Event)}"
|
|
34
|
-
# number_of_objects(AASM::Event).should == event_count + 2 # + Process
|
|
35
|
-
# number_of_objects(AASM::Transition).should == transition_count + 2 # + Process
|
|
31
|
+
# number_of_objects(AASM::Core::State).should == state_count + 3 # + Process
|
|
32
|
+
# # ObjectSpace.each_object(AASM::Core::Event) {|o| puts o.inspect}
|
|
33
|
+
# puts "event_count = #{number_of_objects(AASM::Core::Event)}"
|
|
34
|
+
# number_of_objects(AASM::Core::Event).should == event_count + 2 # + Process
|
|
35
|
+
# number_of_objects(AASM::Core::Transition).should == transition_count + 2 # + Process
|
|
36
36
|
# end
|
|
37
37
|
|
|
38
38
|
# end
|