aasm 3.0.26 → 3.1.0
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 -1
- data/CHANGELOG.md +9 -1
- data/README.md +56 -4
- data/aasm.gemspec +1 -1
- data/lib/aasm/base.rb +21 -15
- data/lib/aasm/event.rb +15 -4
- data/lib/aasm/instance_base.rb +2 -0
- data/lib/aasm/persistence/active_record_persistence.rb +17 -1
- data/lib/aasm/transition.rb +13 -6
- data/lib/aasm/version.rb +1 -1
- data/spec/models/guardian.rb +48 -0
- data/spec/unit/api_spec.rb +12 -12
- data/spec/unit/callbacks_spec.rb +25 -25
- data/spec/unit/complex_example_spec.rb +15 -15
- data/spec/unit/event_spec.rb +44 -44
- data/spec/unit/guard_spec.rb +60 -0
- data/spec/unit/initial_state_spec.rb +3 -3
- data/spec/unit/inspection_spec.rb +36 -36
- data/spec/unit/localizer_spec.rb +12 -12
- data/spec/unit/new_dsl_spec.rb +2 -2
- data/spec/unit/persistence/active_record_persistence_spec.rb +107 -67
- data/spec/unit/persistence/mongoid_persistance_spec.rb +24 -24
- data/spec/unit/simple_example_spec.rb +20 -20
- data/spec/unit/state_spec.rb +16 -16
- data/spec/unit/subclassing_spec.rb +6 -6
- data/spec/unit/transition_spec.rb +55 -40
- metadata +8 -4
@@ -27,15 +27,15 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
27
27
|
|
28
28
|
context "Does not already respond_to? the scope name" do
|
29
29
|
it "should add a scope" do
|
30
|
-
SimpleMongoid.
|
31
|
-
SimpleMongoid.unknown_scope.class.
|
30
|
+
expect(SimpleMongoid).to respond_to(:unknown_scope)
|
31
|
+
expect(SimpleMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context "Already respond_to? the scope name" do
|
36
36
|
it "should not add a scope" do
|
37
|
-
SimpleMongoid.
|
38
|
-
SimpleMongoid.new.class.
|
37
|
+
expect(SimpleMongoid).to respond_to(:new)
|
38
|
+
expect(SimpleMongoid.new.class).to eq(SimpleMongoid)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,20 +45,20 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
45
45
|
|
46
46
|
context "Does not already respond_to? the scope name" do
|
47
47
|
it "should add a scope" do
|
48
|
-
SimpleNewDslMongoid.
|
49
|
-
SimpleNewDslMongoid.unknown_scope.class.
|
48
|
+
expect(SimpleNewDslMongoid).to respond_to(:unknown_scope)
|
49
|
+
expect(SimpleNewDslMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
context "Already respond_to? the scope name" do
|
54
54
|
it "should not add a scope" do
|
55
|
-
SimpleNewDslMongoid.
|
56
|
-
SimpleNewDslMongoid.new.class.
|
55
|
+
expect(SimpleNewDslMongoid).to respond_to(:new)
|
56
|
+
expect(SimpleNewDslMongoid.new.class).to eq(SimpleNewDslMongoid)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
it "does not create scopes if requested" do
|
61
|
-
NoScopeMongoid.
|
61
|
+
expect(NoScopeMongoid).not_to respond_to(:ignored_scope)
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
@@ -69,12 +69,12 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
69
69
|
let!(:model_id) { model._id }
|
70
70
|
|
71
71
|
it "should respond to method" do
|
72
|
-
SimpleNewDslMongoid.
|
72
|
+
expect(SimpleNewDslMongoid).to respond_to(:find_in_state)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should find the model when given the correct scope and model id" do
|
76
|
-
SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').class.
|
77
|
-
SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').
|
76
|
+
expect(SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope').class).to eq(SimpleNewDslMongoid)
|
77
|
+
expect(SimpleNewDslMongoid.find_in_state(model_id, 'unknown_scope')).to eq(model)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should raise DocumentNotFound error when given incorrect scope" do
|
@@ -94,17 +94,17 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should respond to method" do
|
97
|
-
SimpleNewDslMongoid.
|
97
|
+
expect(SimpleNewDslMongoid).to respond_to(:count_in_state)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should return n for a scope with n records persisted" do
|
101
|
-
SimpleNewDslMongoid.count_in_state('unknown_scope').class.
|
102
|
-
SimpleNewDslMongoid.count_in_state('unknown_scope').
|
101
|
+
expect(SimpleNewDslMongoid.count_in_state('unknown_scope').class).to eq(Fixnum)
|
102
|
+
expect(SimpleNewDslMongoid.count_in_state('unknown_scope')).to eq(3)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should return zero for a scope without records persisted" do
|
106
|
-
SimpleNewDslMongoid.count_in_state('new').class.
|
107
|
-
SimpleNewDslMongoid.count_in_state('new').
|
106
|
+
expect(SimpleNewDslMongoid.count_in_state('new').class).to eq(Fixnum)
|
107
|
+
expect(SimpleNewDslMongoid.count_in_state('new')).to eq(0)
|
108
108
|
end
|
109
109
|
|
110
110
|
end
|
@@ -117,16 +117,16 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should respond to method" do
|
120
|
-
SimpleNewDslMongoid.
|
120
|
+
expect(SimpleNewDslMongoid).to respond_to(:with_state_scope)
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should correctly process block" do
|
124
|
-
SimpleNewDslMongoid.with_state_scope('unknown_scope') do
|
124
|
+
expect(SimpleNewDslMongoid.with_state_scope('unknown_scope') do
|
125
125
|
SimpleNewDslMongoid.count
|
126
|
-
end.
|
127
|
-
SimpleNewDslMongoid.with_state_scope('new') do
|
126
|
+
end).to eq(3)
|
127
|
+
expect(SimpleNewDslMongoid.with_state_scope('new') do
|
128
128
|
SimpleNewDslMongoid.count
|
129
|
-
end.
|
129
|
+
end).to eq(2)
|
130
130
|
end
|
131
131
|
|
132
132
|
end
|
@@ -136,12 +136,12 @@ describe 'mongoid', :if => Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version
|
|
136
136
|
let(:simple) {SimpleNewDslMongoid.new}
|
137
137
|
|
138
138
|
it "should call aasm_ensure_initial_state on validation before create" do
|
139
|
-
simple.
|
139
|
+
expect(simple).to receive(:aasm_ensure_initial_state).and_return(true)
|
140
140
|
simple.valid?
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should call aasm_ensure_initial_state before create, even if skipping validations" do
|
144
|
-
simple.
|
144
|
+
expect(simple).to receive(:aasm_ensure_initial_state).and_return(true)
|
145
145
|
simple.save(:validate => false)
|
146
146
|
end
|
147
147
|
end
|
@@ -20,39 +20,39 @@ describe 'state machine' do
|
|
20
20
|
let(:payment) {Payment.new}
|
21
21
|
|
22
22
|
it 'starts with an initial state' do
|
23
|
-
payment.aasm.current_state.
|
24
|
-
payment.
|
25
|
-
payment.
|
23
|
+
expect(payment.aasm.current_state).to eq(:initialised)
|
24
|
+
expect(payment).to respond_to(:initialised?)
|
25
|
+
expect(payment).to be_initialised
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'allows transitions to other states' do
|
29
|
-
payment.
|
30
|
-
payment.
|
29
|
+
expect(payment).to respond_to(:fill_out)
|
30
|
+
expect(payment).to respond_to(:fill_out!)
|
31
31
|
payment.fill_out!
|
32
|
-
payment.
|
33
|
-
payment.
|
32
|
+
expect(payment).to respond_to(:filled_out?)
|
33
|
+
expect(payment).to be_filled_out
|
34
34
|
|
35
|
-
payment.
|
36
|
-
payment.
|
35
|
+
expect(payment).to respond_to(:authorise)
|
36
|
+
expect(payment).to respond_to(:authorise!)
|
37
37
|
payment.authorise
|
38
|
-
payment.
|
39
|
-
payment.
|
38
|
+
expect(payment).to respond_to(:authorised?)
|
39
|
+
expect(payment).to be_authorised
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'denies transitions to other states' do
|
43
|
-
|
44
|
-
|
43
|
+
expect {payment.authorise}.to raise_error(AASM::InvalidTransition)
|
44
|
+
expect {payment.authorise!}.to raise_error(AASM::InvalidTransition)
|
45
45
|
payment.fill_out
|
46
|
-
|
47
|
-
|
46
|
+
expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
|
47
|
+
expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
|
48
48
|
payment.authorise
|
49
|
-
|
50
|
-
|
49
|
+
expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
|
50
|
+
expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'defines constants for each state name' do
|
54
|
-
Payment::STATE_INITIALISED.
|
55
|
-
Payment::STATE_FILLED_OUT.
|
56
|
-
Payment::STATE_AUTHORISED.
|
54
|
+
expect(Payment::STATE_INITIALISED).to eq(:initialised)
|
55
|
+
expect(Payment::STATE_FILLED_OUT).to eq(:filled_out)
|
56
|
+
expect(Payment::STATE_AUTHORISED).to eq(:authorised)
|
57
57
|
end
|
58
58
|
end
|
data/spec/unit/state_spec.rb
CHANGED
@@ -12,34 +12,34 @@ describe AASM::State do
|
|
12
12
|
|
13
13
|
it 'should set the name' do
|
14
14
|
state = new_state
|
15
|
-
state.name.
|
15
|
+
expect(state.name).to eq(:astate)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should set the display_name from name' do
|
19
|
-
new_state.display_name.
|
19
|
+
expect(new_state.display_name).to eq('Astate')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should set the display_name from options' do
|
23
|
-
new_state(:display => "A State").display_name.
|
23
|
+
expect(new_state(:display => "A State").display_name).to eq('A State')
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should set the options and expose them as options' do
|
27
|
-
new_state.options.
|
27
|
+
expect(new_state.options).to eq(@options)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should be equal to a symbol of the same name' do
|
31
|
-
new_state.
|
31
|
+
expect(new_state).to eq(:astate)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should be equal to a State of the same name' do
|
35
|
-
new_state.
|
35
|
+
expect(new_state).to eq(new_state)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should send a message to the record for an action if the action is present as a symbol' do
|
39
39
|
state = new_state(:entering => :foo)
|
40
40
|
|
41
41
|
record = double('record')
|
42
|
-
record.
|
42
|
+
expect(record).to receive(:foo)
|
43
43
|
|
44
44
|
state.fire_callbacks(:entering, record)
|
45
45
|
end
|
@@ -48,7 +48,7 @@ describe AASM::State do
|
|
48
48
|
state = new_state(:entering => 'foo')
|
49
49
|
|
50
50
|
record = double('record')
|
51
|
-
record.
|
51
|
+
expect(record).to receive(:foo)
|
52
52
|
|
53
53
|
state.fire_callbacks(:entering, record)
|
54
54
|
end
|
@@ -57,10 +57,10 @@ describe AASM::State do
|
|
57
57
|
state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])
|
58
58
|
|
59
59
|
record = double('record')
|
60
|
-
record.
|
61
|
-
record.
|
62
|
-
record.
|
63
|
-
record.
|
60
|
+
expect(record).to receive(:a)
|
61
|
+
expect(record).to receive(:b)
|
62
|
+
expect(record).to receive(:c)
|
63
|
+
expect(record).to receive(:foobar)
|
64
64
|
|
65
65
|
state.fire_callbacks(:entering, record)
|
66
66
|
end
|
@@ -69,9 +69,9 @@ describe AASM::State do
|
|
69
69
|
state = new_state(:entering => [:a, :b, :c])
|
70
70
|
|
71
71
|
record = double('record')
|
72
|
-
record.
|
73
|
-
record.
|
74
|
-
record.
|
72
|
+
expect(record).to receive(:a)
|
73
|
+
expect(record).to receive(:b).and_throw(:halt_aasm_chain)
|
74
|
+
expect(record).not_to receive(:c)
|
75
75
|
|
76
76
|
state.fire_callbacks(:entering, record)
|
77
77
|
end
|
@@ -80,7 +80,7 @@ describe AASM::State do
|
|
80
80
|
state = new_state(:entering => Proc.new {|r| r.foobar})
|
81
81
|
|
82
82
|
record = double('record')
|
83
|
-
record.
|
83
|
+
expect(record).to receive(:foobar)
|
84
84
|
|
85
85
|
state.fire_callbacks(:entering, record)
|
86
86
|
end
|
@@ -5,26 +5,26 @@ describe 'subclassing' do
|
|
5
5
|
|
6
6
|
it 'should have the parent states' do
|
7
7
|
Foo.aasm.states.each do |state|
|
8
|
-
FooTwo.aasm.states.
|
8
|
+
expect(FooTwo.aasm.states).to include(state)
|
9
9
|
end
|
10
|
-
Baz.aasm.states.
|
10
|
+
expect(Baz.aasm.states).to eq(Bar.aasm.states)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should not add the child states to the parent machine' do
|
14
|
-
Foo.aasm.states.
|
14
|
+
expect(Foo.aasm.states).not_to include(:foo)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have the same events as its parent" do
|
18
|
-
Baz.aasm.events.
|
18
|
+
expect(Baz.aasm.events).to eq(Bar.aasm.events)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should know how to respond to `may_add_details?`' do
|
22
|
-
son.may_add_details
|
22
|
+
expect(son.may_add_details?).to be_true
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should not break if I call Son#update_state' do
|
26
26
|
son.update_state
|
27
|
-
son.aasm.current_state.
|
27
|
+
expect(son.aasm.current_state).to eq(:pending_details_confirmation)
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -4,46 +4,46 @@ describe 'transitions' do
|
|
4
4
|
|
5
5
|
it 'should raise an exception when whiny' do
|
6
6
|
process = ProcessWithNewDsl.new
|
7
|
-
|
8
|
-
process.
|
7
|
+
expect { process.stop! }.to raise_error(AASM::InvalidTransition)
|
8
|
+
expect(process).to be_sleeping
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should not raise an exception when not whiny' do
|
12
12
|
silencer = Silencer.new
|
13
|
-
silencer.smile
|
14
|
-
silencer.
|
13
|
+
expect(silencer.smile!).to be_false
|
14
|
+
expect(silencer).to be_silent
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should not raise an exception when superclass not whiny' do
|
18
18
|
sub = SubClassing.new
|
19
|
-
sub.smile
|
20
|
-
sub.
|
19
|
+
expect(sub.smile!).to be_false
|
20
|
+
expect(sub).to be_silent
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should not raise an exception when from is nil even if whiny' do
|
24
24
|
silencer = Silencer.new
|
25
|
-
silencer.smile_any
|
26
|
-
silencer.
|
25
|
+
expect(silencer.smile_any!).to be_true
|
26
|
+
expect(silencer).to be_smiling
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should call the block when success' do
|
30
30
|
silencer = Silencer.new
|
31
31
|
success = false
|
32
|
-
|
32
|
+
expect {
|
33
33
|
silencer.smile_any! do
|
34
34
|
success = true
|
35
35
|
end
|
36
|
-
}.
|
36
|
+
}.to change { success }.to(true)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should not call the block when failure' do
|
40
40
|
silencer = Silencer.new
|
41
41
|
success = false
|
42
|
-
|
42
|
+
expect {
|
43
43
|
silencer.smile! do
|
44
44
|
success = true
|
45
45
|
end
|
46
|
-
}.
|
46
|
+
}.not_to change { success }.to(true)
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -56,9 +56,9 @@ describe AASM::Transition do
|
|
56
56
|
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
57
57
|
st = AASM::Transition.new(opts)
|
58
58
|
|
59
|
-
st.from.
|
60
|
-
st.to.
|
61
|
-
st.opts.
|
59
|
+
expect(st.from).to eq(opts[:from])
|
60
|
+
expect(st.to).to eq(opts[:to])
|
61
|
+
expect(st.opts).to eq(opts)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should pass equality check if from and to are the same' do
|
@@ -66,10 +66,10 @@ describe AASM::Transition do
|
|
66
66
|
st = AASM::Transition.new(opts)
|
67
67
|
|
68
68
|
obj = double('object')
|
69
|
-
obj.
|
70
|
-
obj.
|
69
|
+
allow(obj).to receive(:from).and_return(opts[:from])
|
70
|
+
allow(obj).to receive(:to).and_return(opts[:to])
|
71
71
|
|
72
|
-
st.
|
72
|
+
expect(st).to eq(obj)
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'should fail equality check if from are not the same' do
|
@@ -77,10 +77,10 @@ describe AASM::Transition do
|
|
77
77
|
st = AASM::Transition.new(opts)
|
78
78
|
|
79
79
|
obj = double('object')
|
80
|
-
obj.
|
81
|
-
obj.
|
80
|
+
allow(obj).to receive(:from).and_return('blah')
|
81
|
+
allow(obj).to receive(:to).and_return(opts[:to])
|
82
82
|
|
83
|
-
st.
|
83
|
+
expect(st).not_to eq(obj)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should fail equality check if to are not the same' do
|
@@ -88,10 +88,10 @@ describe AASM::Transition do
|
|
88
88
|
st = AASM::Transition.new(opts)
|
89
89
|
|
90
90
|
obj = double('object')
|
91
|
-
obj.
|
92
|
-
obj.
|
91
|
+
allow(obj).to receive(:from).and_return(opts[:from])
|
92
|
+
allow(obj).to receive(:to).and_return('blah')
|
93
93
|
|
94
|
-
st.
|
94
|
+
expect(st).not_to eq(obj)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -100,7 +100,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
100
100
|
opts = {:from => 'foo', :to => 'bar'}
|
101
101
|
st = AASM::Transition.new(opts)
|
102
102
|
|
103
|
-
st.perform(nil).
|
103
|
+
expect(st.perform(nil)).to be_true
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should call the method on the object if guard is a symbol' do
|
@@ -108,7 +108,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
108
108
|
st = AASM::Transition.new(opts)
|
109
109
|
|
110
110
|
obj = double('object')
|
111
|
-
obj.
|
111
|
+
expect(obj).to receive(:test)
|
112
112
|
|
113
113
|
st.perform(obj)
|
114
114
|
end
|
@@ -118,7 +118,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
118
118
|
st = AASM::Transition.new(opts)
|
119
119
|
|
120
120
|
obj = double('object')
|
121
|
-
obj.
|
121
|
+
expect(obj).to receive(:test)
|
122
122
|
|
123
123
|
st.perform(obj)
|
124
124
|
end
|
@@ -128,7 +128,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
128
128
|
st = AASM::Transition.new(opts)
|
129
129
|
|
130
130
|
obj = double('object')
|
131
|
-
obj.
|
131
|
+
expect(obj).to receive(:test)
|
132
132
|
|
133
133
|
st.perform(obj)
|
134
134
|
end
|
@@ -139,9 +139,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|
139
139
|
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}}
|
140
140
|
st = AASM::Transition.new(opts)
|
141
141
|
args = {:arg1 => '1', :arg2 => '2'}
|
142
|
-
obj = double('object')
|
142
|
+
obj = double('object', :aasm => 'aasm')
|
143
143
|
|
144
|
-
opts[:on_transition].
|
144
|
+
expect(opts[:on_transition]).to receive(:call).with(any_args)
|
145
145
|
|
146
146
|
st.execute(obj, args)
|
147
147
|
end
|
@@ -150,9 +150,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|
150
150
|
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}}
|
151
151
|
st = AASM::Transition.new(opts)
|
152
152
|
args = {:arg1 => '1', :arg2 => '2'}
|
153
|
-
obj = double('object')
|
153
|
+
obj = double('object', :aasm => 'aasm')
|
154
154
|
|
155
|
-
opts[:on_transition].
|
155
|
+
expect(opts[:on_transition]).to receive(:call).with(no_args)
|
156
156
|
|
157
157
|
st.execute(obj, args)
|
158
158
|
end
|
@@ -163,9 +163,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
163
163
|
opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'}
|
164
164
|
st = AASM::Transition.new(opts)
|
165
165
|
args = {:arg1 => '1', :arg2 => '2'}
|
166
|
-
obj = double('object')
|
166
|
+
obj = double('object', :aasm => 'aasm')
|
167
167
|
|
168
|
-
obj.
|
168
|
+
expect(obj).to receive(:test)
|
169
169
|
|
170
170
|
st.execute(obj, args)
|
171
171
|
end
|
@@ -174,9 +174,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
174
174
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
175
175
|
st = AASM::Transition.new(opts)
|
176
176
|
args = {:arg1 => '1', :arg2 => '2'}
|
177
|
-
obj = double('object')
|
177
|
+
obj = double('object', :aasm => 'aasm')
|
178
178
|
|
179
|
-
obj.
|
179
|
+
expect(obj).to receive(:test)
|
180
180
|
|
181
181
|
st.execute(obj, args)
|
182
182
|
end
|
@@ -185,7 +185,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
185
185
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
186
186
|
st = AASM::Transition.new(opts)
|
187
187
|
args = {:arg1 => '1', :arg2 => '2'}
|
188
|
-
obj = double('object')
|
188
|
+
obj = double('object', :aasm => 'aasm')
|
189
189
|
|
190
190
|
def obj.test(args)
|
191
191
|
"arg1: #{args[:arg1]} arg2: #{args[:arg2]}"
|
@@ -193,14 +193,14 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
193
193
|
|
194
194
|
return_value = st.execute(obj, args)
|
195
195
|
|
196
|
-
return_value.
|
196
|
+
expect(return_value).to eq('arg1: 1 arg2: 2')
|
197
197
|
end
|
198
198
|
|
199
199
|
it 'should NOT pass args if the target method does NOT accept them' do
|
200
200
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
201
201
|
st = AASM::Transition.new(opts)
|
202
202
|
args = {:arg1 => '1', :arg2 => '2'}
|
203
|
-
obj = double('object')
|
203
|
+
obj = double('object', :aasm => 'aasm')
|
204
204
|
|
205
205
|
def obj.test
|
206
206
|
'success'
|
@@ -208,7 +208,22 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
208
208
|
|
209
209
|
return_value = st.execute(obj, args)
|
210
210
|
|
211
|
-
return_value.
|
211
|
+
expect(return_value).to eq('success')
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should allow accessing the from_state and the to_state' do
|
215
|
+
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
216
|
+
st = AASM::Transition.new(opts)
|
217
|
+
args = {:arg1 => '1', :arg2 => '2'}
|
218
|
+
obj = double('object', :aasm => AASM::InstanceBase.new('object'))
|
219
|
+
|
220
|
+
def obj.test(args)
|
221
|
+
"from: #{aasm.from_state} to: #{aasm.to_state}"
|
222
|
+
end
|
223
|
+
|
224
|
+
return_value = st.execute(obj, args)
|
225
|
+
|
226
|
+
expect(return_value).to eq('from: foo to: bar')
|
212
227
|
end
|
213
228
|
|
214
229
|
end
|