aasm 3.0.14 → 3.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/aasm/aasm.rb +9 -8
- data/lib/aasm/base.rb +6 -1
- data/lib/aasm/state_machine.rb +8 -3
- data/lib/aasm/supporting_classes/localizer.rb +6 -7
- data/lib/aasm/supporting_classes/state.rb +17 -2
- data/lib/aasm/version.rb +1 -1
- data/spec/en.yml +1 -1
- data/spec/en_deprecated_style.yml +1 -1
- data/spec/models/argument.rb +11 -0
- data/spec/models/callback_new_dsl.rb +5 -0
- data/spec/models/callback_old_dsl.rb +11 -6
- data/spec/models/parametrised_event.rb +29 -0
- data/spec/spec_helpers/models_spec_helper.rb +0 -55
- data/spec/unit/callbacks_spec.rb +116 -0
- data/spec/unit/complex_example_spec.rb +2 -2
- data/spec/unit/initial_state_spec.rb +28 -0
- data/spec/unit/inspection_spec.rb +75 -3
- data/spec/unit/memory_leak_spec.rb +32 -28
- data/spec/unit/new_dsl_spec.rb +2 -18
- data/spec/unit/persistence/active_record_persistence_spec.rb +2 -7
- data/spec/unit/simple_example_spec.rb +53 -0
- data/spec/unit/subclassing_spec.rb +19 -0
- data/spec/unit/{event_spec.rb → supporting_classes/event_spec.rb} +77 -24
- data/spec/unit/{localizer_spec.rb → supporting_classes/localizer_spec.rb} +25 -3
- data/spec/unit/{state_spec.rb → supporting_classes/state_spec.rb} +2 -2
- data/spec/unit/{state_transition_spec.rb → supporting_classes/state_transition_spec.rb} +2 -2
- metadata +40 -34
- data/spec/unit/aasm_spec.rb +0 -301
- data/spec/unit/callbacks_new_dsl_spec.rb +0 -33
- data/spec/unit/callbacks_old_dsl_spec.rb +0 -33
@@ -3,12 +3,14 @@ require 'active_record'
|
|
3
3
|
require 'logger'
|
4
4
|
require 'i18n'
|
5
5
|
|
6
|
+
load_schema
|
7
|
+
|
6
8
|
class LocalizerTestModel < ActiveRecord::Base
|
7
9
|
include AASM
|
8
10
|
|
9
11
|
attr_accessor :aasm_state
|
10
12
|
|
11
|
-
aasm_initial_state :
|
13
|
+
aasm_initial_state :opened
|
12
14
|
aasm_state :opened
|
13
15
|
aasm_state :closed
|
14
16
|
|
@@ -16,6 +18,26 @@ class LocalizerTestModel < ActiveRecord::Base
|
|
16
18
|
aasm_event :open
|
17
19
|
end
|
18
20
|
|
21
|
+
describe 'localized state names' do
|
22
|
+
before(:all) do
|
23
|
+
I18n.load_path << 'spec/en.yml'
|
24
|
+
I18n.default_locale = :en
|
25
|
+
I18n.reload!
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:all) do
|
29
|
+
I18n.load_path.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should localize' do
|
33
|
+
LocalizerTestModel.aasm.states.detect {|s| s == :opened}.localized_name.should == "It's open now!"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should use fallback' do
|
37
|
+
LocalizerTestModel.aasm.states.detect {|s| s == :closed}.localized_name.should == 'Closed'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
19
41
|
describe AASM::SupportingClasses::Localizer, "new style" do
|
20
42
|
before(:all) do
|
21
43
|
I18n.load_path << 'spec/en.yml'
|
@@ -32,7 +54,7 @@ describe AASM::SupportingClasses::Localizer, "new style" do
|
|
32
54
|
|
33
55
|
context 'aasm_human_state' do
|
34
56
|
it 'should return translated state value' do
|
35
|
-
foo_opened.aasm_human_state.should == "It's
|
57
|
+
foo_opened.aasm_human_state.should == "It's open now!"
|
36
58
|
end
|
37
59
|
|
38
60
|
it 'should return humanized value if not localized' do
|
@@ -67,7 +89,7 @@ describe AASM::SupportingClasses::Localizer, "deprecated style" do
|
|
67
89
|
|
68
90
|
context 'aasm_human_state' do
|
69
91
|
it 'should return translated state value' do
|
70
|
-
foo_opened.aasm_human_state.should == "It's
|
92
|
+
foo_opened.aasm_human_state.should == "It's open now!"
|
71
93
|
end
|
72
94
|
|
73
95
|
it 'should return humanized value if not localized' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AASM::SupportingClasses::State do
|
4
4
|
before(:each) do
|
@@ -7,7 +7,7 @@ describe AASM::SupportingClasses::State do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def new_state(options={})
|
10
|
-
AASM::SupportingClasses::State.new(@name, @options.merge(options))
|
10
|
+
AASM::SupportingClasses::State.new(@name, Conversation, @options.merge(options))
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should set the name' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'transitions' do
|
4
4
|
|
@@ -25,7 +25,7 @@ describe 'transitions' do
|
|
25
25
|
silencer.smile_any!.should be_true
|
26
26
|
silencer.should be_smiling
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
end
|
30
30
|
|
31
31
|
describe AASM::SupportingClasses::StateTransition 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: 3.0.
|
4
|
+
version: 3.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-12-27 00:00:00.000000000Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
19
|
-
requirement: &
|
19
|
+
requirement: &70247621982320 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '0'
|
25
25
|
type: :development
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70247621982320
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
|
-
requirement: &
|
30
|
+
requirement: &70247621981900 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70247621981900
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: sdoc
|
41
|
-
requirement: &
|
41
|
+
requirement: &70247621981480 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: '0'
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *70247621981480
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rspec
|
52
|
-
requirement: &
|
52
|
+
requirement: &70247621980980 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '2.0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *70247621980980
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rr
|
63
|
-
requirement: &
|
63
|
+
requirement: &70247621980560 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
@@ -68,10 +68,10 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *70247621980560
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: shoulda
|
74
|
-
requirement: &
|
74
|
+
requirement: &70247621980100 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ! '>='
|
@@ -79,10 +79,10 @@ dependencies:
|
|
79
79
|
version: '0'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
|
-
version_requirements: *
|
82
|
+
version_requirements: *70247621980100
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
|
-
requirement: &
|
85
|
+
requirement: &70247621979680 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ! '>='
|
@@ -90,10 +90,10 @@ dependencies:
|
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
|
-
version_requirements: *
|
93
|
+
version_requirements: *70247621979680
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: minitest
|
96
|
-
requirement: &
|
96
|
+
requirement: &70247621979260 !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
@@ -101,10 +101,10 @@ dependencies:
|
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
|
-
version_requirements: *
|
104
|
+
version_requirements: *70247621979260
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-debug-completion
|
107
|
-
requirement: &
|
107
|
+
requirement: &70247622010320 !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|
110
110
|
- - ! '>='
|
@@ -112,7 +112,7 @@ dependencies:
|
|
112
112
|
version: '0'
|
113
113
|
type: :development
|
114
114
|
prerelease: false
|
115
|
-
version_requirements: *
|
115
|
+
version_requirements: *70247622010320
|
116
116
|
description: AASM is a continuation of the acts as state machine rails plugin, built
|
117
117
|
for plain Ruby objects.
|
118
118
|
email: scott@elitists.net, ttilley@gmail.com, aasm@mt7.de
|
@@ -148,12 +148,14 @@ files:
|
|
148
148
|
- spec/database.yml
|
149
149
|
- spec/en.yml
|
150
150
|
- spec/en_deprecated_style.yml
|
151
|
+
- spec/models/argument.rb
|
151
152
|
- spec/models/auth_machine.rb
|
152
153
|
- spec/models/callback_new_dsl.rb
|
153
154
|
- spec/models/callback_old_dsl.rb
|
154
155
|
- spec/models/conversation.rb
|
155
156
|
- spec/models/invalid_persistor.rb
|
156
157
|
- spec/models/not_auto_loaded/process.rb
|
158
|
+
- spec/models/parametrised_event.rb
|
157
159
|
- spec/models/persistence.rb
|
158
160
|
- spec/models/process_with_new_dsl.rb
|
159
161
|
- spec/models/silencer.rb
|
@@ -164,18 +166,19 @@ files:
|
|
164
166
|
- spec/schema.rb
|
165
167
|
- spec/spec_helper.rb
|
166
168
|
- spec/spec_helpers/models_spec_helper.rb
|
167
|
-
- spec/unit/
|
168
|
-
- spec/unit/callbacks_new_dsl_spec.rb
|
169
|
-
- spec/unit/callbacks_old_dsl_spec.rb
|
169
|
+
- spec/unit/callbacks_spec.rb
|
170
170
|
- spec/unit/complex_example_spec.rb
|
171
|
-
- spec/unit/
|
171
|
+
- spec/unit/initial_state_spec.rb
|
172
172
|
- spec/unit/inspection_spec.rb
|
173
|
-
- spec/unit/localizer_spec.rb
|
174
173
|
- spec/unit/memory_leak_spec.rb
|
175
174
|
- spec/unit/new_dsl_spec.rb
|
176
175
|
- spec/unit/persistence/active_record_persistence_spec.rb
|
177
|
-
- spec/unit/
|
178
|
-
- spec/unit/
|
176
|
+
- spec/unit/simple_example_spec.rb
|
177
|
+
- spec/unit/subclassing_spec.rb
|
178
|
+
- spec/unit/supporting_classes/event_spec.rb
|
179
|
+
- spec/unit/supporting_classes/localizer_spec.rb
|
180
|
+
- spec/unit/supporting_classes/state_spec.rb
|
181
|
+
- spec/unit/supporting_classes/state_transition_spec.rb
|
179
182
|
homepage: https://github.com/aasm/aasm
|
180
183
|
licenses:
|
181
184
|
- MIT
|
@@ -205,12 +208,14 @@ test_files:
|
|
205
208
|
- spec/database.yml
|
206
209
|
- spec/en.yml
|
207
210
|
- spec/en_deprecated_style.yml
|
211
|
+
- spec/models/argument.rb
|
208
212
|
- spec/models/auth_machine.rb
|
209
213
|
- spec/models/callback_new_dsl.rb
|
210
214
|
- spec/models/callback_old_dsl.rb
|
211
215
|
- spec/models/conversation.rb
|
212
216
|
- spec/models/invalid_persistor.rb
|
213
217
|
- spec/models/not_auto_loaded/process.rb
|
218
|
+
- spec/models/parametrised_event.rb
|
214
219
|
- spec/models/persistence.rb
|
215
220
|
- spec/models/process_with_new_dsl.rb
|
216
221
|
- spec/models/silencer.rb
|
@@ -221,15 +226,16 @@ test_files:
|
|
221
226
|
- spec/schema.rb
|
222
227
|
- spec/spec_helper.rb
|
223
228
|
- spec/spec_helpers/models_spec_helper.rb
|
224
|
-
- spec/unit/
|
225
|
-
- spec/unit/callbacks_new_dsl_spec.rb
|
226
|
-
- spec/unit/callbacks_old_dsl_spec.rb
|
229
|
+
- spec/unit/callbacks_spec.rb
|
227
230
|
- spec/unit/complex_example_spec.rb
|
228
|
-
- spec/unit/
|
231
|
+
- spec/unit/initial_state_spec.rb
|
229
232
|
- spec/unit/inspection_spec.rb
|
230
|
-
- spec/unit/localizer_spec.rb
|
231
233
|
- spec/unit/memory_leak_spec.rb
|
232
234
|
- spec/unit/new_dsl_spec.rb
|
233
235
|
- spec/unit/persistence/active_record_persistence_spec.rb
|
234
|
-
- spec/unit/
|
235
|
-
- spec/unit/
|
236
|
+
- spec/unit/simple_example_spec.rb
|
237
|
+
- spec/unit/subclassing_spec.rb
|
238
|
+
- spec/unit/supporting_classes/event_spec.rb
|
239
|
+
- spec/unit/supporting_classes/localizer_spec.rb
|
240
|
+
- spec/unit/supporting_classes/state_spec.rb
|
241
|
+
- spec/unit/supporting_classes/state_transition_spec.rb
|
data/spec/unit/aasm_spec.rb
DELETED
@@ -1,301 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe AASM, '- class level definitions' do
|
4
|
-
it 'should define a class level methods on its including class' do
|
5
|
-
Foo.should respond_to(:aasm_initial_state)
|
6
|
-
Foo.should respond_to(:aasm_state)
|
7
|
-
Foo.should respond_to(:aasm_event)
|
8
|
-
Foo.should respond_to(:aasm_states)
|
9
|
-
Foo.should respond_to(:aasm_states_for_select)
|
10
|
-
Foo.should respond_to(:aasm_events)
|
11
|
-
Foo.should respond_to(:aasm_from_states_for_state)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "naming" do
|
16
|
-
it "work for valid" do
|
17
|
-
Argument.aasm_states.should include(:invalid)
|
18
|
-
Argument.aasm_states.should include(:valid)
|
19
|
-
|
20
|
-
argument = Argument.new
|
21
|
-
argument.invalid?.should be_true
|
22
|
-
argument.aasm_current_state.should == :invalid
|
23
|
-
|
24
|
-
argument.valid!
|
25
|
-
argument.valid?.should be_true
|
26
|
-
argument.aasm_current_state.should == :valid
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe AASM, '- subclassing' do
|
31
|
-
it 'should have the parent states' do
|
32
|
-
Foo.aasm_states.each do |state|
|
33
|
-
FooTwo.aasm_states.should include(state)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should not add the child states to the parent machine' do
|
38
|
-
Foo.aasm_states.should_not include(:foo)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
describe AASM, '- aasm_states_for_select' do
|
44
|
-
it "should return a select friendly array of states" do
|
45
|
-
Foo.aasm_states_for_select.should == [['Open', 'open'], ['Closed', 'closed']]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "aasm_from_states_for_state" do
|
50
|
-
it "should return all from states for a state" do
|
51
|
-
froms = AuthMachine.aasm_from_states_for_state(:active)
|
52
|
-
[:pending, :passive, :suspended].each {|from| froms.should include(from)}
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should return from states for a state for a particular transition only" do
|
56
|
-
froms = AuthMachine.aasm_from_states_for_state(:active, :transition => :unsuspend)
|
57
|
-
[:suspended].each {|from| froms.should include(from)}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe AASM, '- instance level definitions' do
|
62
|
-
before(:each) do
|
63
|
-
@foo = Foo.new
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should define a state querying instance method on including class' do
|
67
|
-
@foo.should respond_to(:open?)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should define an event! inance method' do
|
71
|
-
@foo.should respond_to(:close!)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe AASM, '- initial states' do
|
76
|
-
before(:each) do
|
77
|
-
@foo = Foo.new
|
78
|
-
@bar = Bar.new
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should set the initial state' do
|
82
|
-
@foo.aasm_current_state.should == :open
|
83
|
-
end
|
84
|
-
|
85
|
-
it '#open? should be initially true' do
|
86
|
-
@foo.open?.should be_true
|
87
|
-
end
|
88
|
-
|
89
|
-
it '#closed? should be initially false' do
|
90
|
-
@foo.closed?.should be_false
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should use the first state defined if no initial state is given' do
|
94
|
-
@bar.aasm_current_state.should == :read
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should determine initial state from the Proc results' do
|
98
|
-
Banker.new(Banker::RICH - 1).aasm_current_state.should == :selling_bad_mortgages
|
99
|
-
Banker.new(Banker::RICH + 1).aasm_current_state.should == :retired
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe AASM, 'success callbacks' do
|
104
|
-
it 'should call the success callback if one was provided' do
|
105
|
-
foo = Foo.new
|
106
|
-
foo.should_receive(:success_callback)
|
107
|
-
foo.close!
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
describe AASM, '- event firing without persistence' do
|
113
|
-
it 'should attempt to persist if aasm_write_state is defined' do
|
114
|
-
foo = Foo.new
|
115
|
-
|
116
|
-
def foo.aasm_write_state
|
117
|
-
end
|
118
|
-
|
119
|
-
foo.should_receive(:aasm_write_state_without_persistence).twice
|
120
|
-
|
121
|
-
foo.close
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe AASM, '- getting events for a state' do
|
126
|
-
it '#aasm_events_for_current_state should use current state' do
|
127
|
-
foo = Foo.new
|
128
|
-
foo.should_receive(:aasm_current_state)
|
129
|
-
foo.aasm_events_for_current_state
|
130
|
-
end
|
131
|
-
|
132
|
-
it '#aasm_events_for_current_state should use aasm_events_for_state' do
|
133
|
-
foo = Foo.new
|
134
|
-
foo.stub!(:aasm_current_state).and_return(:foo)
|
135
|
-
foo.should_receive(:aasm_events_for_state).with(:foo)
|
136
|
-
foo.aasm_events_for_current_state
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe AASM, '- event callbacks' do
|
141
|
-
describe "with an error callback defined" do
|
142
|
-
before do
|
143
|
-
class Foo
|
144
|
-
aasm_event :safe_close, :success => :success_callback, :error => :error_callback do
|
145
|
-
transitions :to => :closed, :from => [:open]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
@foo = Foo.new
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should run error_callback if an exception is raised and error_callback defined" do
|
153
|
-
def @foo.error_callback(e)
|
154
|
-
end
|
155
|
-
@foo.stub!(:enter).and_raise(e=StandardError.new)
|
156
|
-
@foo.should_receive(:error_callback).with(e)
|
157
|
-
@foo.safe_close!
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should raise NoMethodError if exceptionis raised and error_callback is declared but not defined" do
|
161
|
-
@foo.stub!(:enter).and_raise(StandardError)
|
162
|
-
lambda{@foo.safe_close!}.should raise_error(NoMethodError)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should propagate an error if no error callback is declared" do
|
166
|
-
@foo.stub!(:enter).and_raise("Cannot enter safe")
|
167
|
-
lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe")
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe "with aasm_event_fired defined" do
|
172
|
-
before do
|
173
|
-
@foo = Foo.new
|
174
|
-
def @foo.aasm_event_fired(event, from, to)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should call it for successful bang fire' do
|
179
|
-
@foo.should_receive(:aasm_event_fired).with(:close, :open, :closed)
|
180
|
-
@foo.close!
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should call it for successful non-bang fire' do
|
184
|
-
@foo.should_receive(:aasm_event_fired)
|
185
|
-
@foo.close
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should not call it for failing bang fire' do
|
189
|
-
@foo.stub!(:aasm_set_current_state_with_persistence).and_return(false)
|
190
|
-
@foo.should_not_receive(:aasm_event_fired)
|
191
|
-
@foo.close!
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "with aasm_event_failed defined" do
|
196
|
-
before do
|
197
|
-
@foo = Foo.new
|
198
|
-
def @foo.aasm_event_failed(event, from)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'should call it when transition failed for bang fire' do
|
203
|
-
@foo.should_receive(:aasm_event_failed).with(:null, :open)
|
204
|
-
lambda {@foo.null!}.should raise_error(AASM::InvalidTransition)
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'should call it when transition failed for non-bang fire' do
|
208
|
-
@foo.should_receive(:aasm_event_failed).with(:null, :open)
|
209
|
-
lambda {@foo.null}.should raise_error(AASM::InvalidTransition)
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'should not call it if persist fails for bang fire' do
|
213
|
-
@foo.stub!(:aasm_set_current_state_with_persistence).and_return(false)
|
214
|
-
@foo.should_receive(:aasm_event_failed)
|
215
|
-
@foo.close!
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe AASM, '- state actions' do
|
221
|
-
it "should call enter when entering state" do
|
222
|
-
foo = Foo.new
|
223
|
-
foo.should_receive(:enter)
|
224
|
-
|
225
|
-
foo.close
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should call exit when exiting state" do
|
229
|
-
foo = Foo.new
|
230
|
-
foo.should_receive(:exit)
|
231
|
-
|
232
|
-
foo.close
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
describe Baz do
|
238
|
-
it "should have the same states as it's parent" do
|
239
|
-
Baz.aasm_states.should == Bar.aasm_states
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should have the same events as it's parent" do
|
243
|
-
Baz.aasm_events.should == Bar.aasm_events
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
describe ChetanPatil do
|
250
|
-
it 'should transition to specified next state (sleeping to showering)' do
|
251
|
-
cp = ChetanPatil.new
|
252
|
-
cp.wakeup! :showering
|
253
|
-
|
254
|
-
cp.aasm_current_state.should == :showering
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should transition to specified next state (sleeping to working)' do
|
258
|
-
cp = ChetanPatil.new
|
259
|
-
cp.wakeup! :working
|
260
|
-
|
261
|
-
cp.aasm_current_state.should == :working
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'should transition to default (first or showering) state' do
|
265
|
-
cp = ChetanPatil.new
|
266
|
-
cp.wakeup!
|
267
|
-
|
268
|
-
cp.aasm_current_state.should == :showering
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'should transition to default state when on_transition invoked' do
|
272
|
-
cp = ChetanPatil.new
|
273
|
-
cp.dress!(nil, 'purple', 'dressy')
|
274
|
-
|
275
|
-
cp.aasm_current_state.should == :working
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'should call on_transition method with args' do
|
279
|
-
cp = ChetanPatil.new
|
280
|
-
cp.wakeup! :showering
|
281
|
-
|
282
|
-
cp.should_receive(:wear_clothes).with('blue', 'jeans')
|
283
|
-
cp.dress! :working, 'blue', 'jeans'
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'should call on_transition proc' do
|
287
|
-
cp = ChetanPatil.new
|
288
|
-
cp.wakeup! :showering
|
289
|
-
|
290
|
-
cp.should_receive(:wear_clothes).with('purple', 'slacks')
|
291
|
-
cp.dress!(:dating, 'purple', 'slacks')
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'should call on_transition with an array of methods' do
|
295
|
-
cp = ChetanPatil.new
|
296
|
-
cp.wakeup! :showering
|
297
|
-
cp.should_receive(:condition_hair)
|
298
|
-
cp.should_receive(:fix_hair)
|
299
|
-
cp.dress!(:prettying_up)
|
300
|
-
end
|
301
|
-
end
|