aasm 2.3.1 → 2.4.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.
- data/.gitignore +1 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE +1 -1
- data/README.md +40 -13
- data/Rakefile +2 -2
- data/lib/aasm/aasm.rb +19 -31
- data/lib/aasm/base.rb +56 -0
- data/lib/aasm/supporting_classes.rb +1 -0
- data/lib/aasm/version.rb +1 -1
- data/spec/{functional → models}/conversation.rb +0 -2
- data/{test/models → spec/models/not_auto_loaded}/process.rb +1 -0
- data/spec/models/process_with_new_dsl.rb +31 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/spec_helpers/models_spec_helper.rb +184 -0
- data/spec/unit/aasm_spec.rb +16 -89
- data/spec/unit/active_record_persistence_spec.rb +195 -191
- data/spec/unit/auth_machine_spec.rb +66 -0
- data/spec/{functional → unit}/conversation_spec.rb +2 -3
- data/spec/unit/event_spec.rb +0 -9
- data/spec/unit/memory_leak_spec.rb +34 -0
- data/spec/unit/new_dsl_spec.rb +28 -0
- data/spec/unit/state_spec.rb +13 -11
- metadata +23 -25
- data/test/functional/auth_machine_test.rb +0 -148
- data/test/test_helper.rb +0 -43
- data/test/unit/aasm_test.rb +0 -0
- data/test/unit/event_test.rb +0 -54
- data/test/unit/state_machine_test.rb +0 -37
- data/test/unit/state_test.rb +0 -69
- data/test/unit/state_transition_test.rb +0 -75
data/spec/unit/aasm_spec.rb
CHANGED
@@ -1,63 +1,5 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
-
class Foo
|
4
|
-
include AASM
|
5
|
-
aasm_initial_state :open
|
6
|
-
aasm_state :open, :exit => :exit
|
7
|
-
aasm_state :closed, :enter => :enter
|
8
|
-
|
9
|
-
aasm_event :close, :success => :success_callback do
|
10
|
-
transitions :to => :closed, :from => [:open]
|
11
|
-
end
|
12
|
-
|
13
|
-
aasm_event :null do
|
14
|
-
transitions :to => :closed, :from => [:open], :guard => :always_false
|
15
|
-
end
|
16
|
-
|
17
|
-
def always_false
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
def success_callback
|
22
|
-
end
|
23
|
-
|
24
|
-
def enter
|
25
|
-
end
|
26
|
-
def exit
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class FooTwo < Foo
|
31
|
-
include AASM
|
32
|
-
aasm_state :foo
|
33
|
-
end
|
34
|
-
|
35
|
-
class Bar
|
36
|
-
include AASM
|
37
|
-
|
38
|
-
aasm_state :read
|
39
|
-
aasm_state :ended
|
40
|
-
|
41
|
-
aasm_event :foo do
|
42
|
-
transitions :to => :ended, :from => [:read]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Baz < Bar
|
47
|
-
end
|
48
|
-
|
49
|
-
class Banker
|
50
|
-
include AASM
|
51
|
-
aasm_initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
|
52
|
-
aasm_state :retired
|
53
|
-
aasm_state :selling_bad_mortgages
|
54
|
-
RICH = 1_000_000
|
55
|
-
attr_accessor :balance
|
56
|
-
def initialize(balance = 0); self.balance = balance; end
|
57
|
-
def rich?; self.balance >= RICH; end
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
3
|
describe AASM, '- class level definitions' do
|
62
4
|
it 'should define a class level aasm_initial_state() method on its including class' do
|
63
5
|
Foo.should respond_to(:aasm_initial_state)
|
@@ -85,6 +27,20 @@ describe AASM, '- class level definitions' do
|
|
85
27
|
|
86
28
|
end
|
87
29
|
|
30
|
+
describe "naming" do
|
31
|
+
it "work for valid" do
|
32
|
+
Argument.aasm_states.should include(:invalid)
|
33
|
+
Argument.aasm_states.should include(:valid)
|
34
|
+
|
35
|
+
argument = Argument.new
|
36
|
+
argument.invalid?.should be_true
|
37
|
+
argument.aasm_current_state.should == :invalid
|
38
|
+
|
39
|
+
argument.valid!
|
40
|
+
argument.valid?.should be_true
|
41
|
+
argument.aasm_current_state.should == :valid
|
42
|
+
end
|
43
|
+
end
|
88
44
|
|
89
45
|
describe AASM, '- subclassing' do
|
90
46
|
it 'should have the parent states' do
|
@@ -293,10 +249,10 @@ describe AASM, '- event callbacks' do
|
|
293
249
|
@foo.stub!(:enter).and_raise(StandardError)
|
294
250
|
lambda{@foo.safe_close!}.should raise_error(NoMethodError)
|
295
251
|
end
|
296
|
-
|
252
|
+
|
297
253
|
it "should propagate an error if no error callback is declared" do
|
298
254
|
@foo.stub!(:enter).and_raise("Cannot enter safe")
|
299
|
-
lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe")
|
255
|
+
lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe")
|
300
256
|
end
|
301
257
|
end
|
302
258
|
|
@@ -377,35 +333,6 @@ describe Baz do
|
|
377
333
|
end
|
378
334
|
|
379
335
|
|
380
|
-
class ChetanPatil
|
381
|
-
include AASM
|
382
|
-
aasm_initial_state :sleeping
|
383
|
-
aasm_state :sleeping
|
384
|
-
aasm_state :showering
|
385
|
-
aasm_state :working
|
386
|
-
aasm_state :dating
|
387
|
-
aasm_state :prettying_up
|
388
|
-
|
389
|
-
aasm_event :wakeup do
|
390
|
-
transitions :from => :sleeping, :to => [:showering, :working]
|
391
|
-
end
|
392
|
-
|
393
|
-
aasm_event :dress do
|
394
|
-
transitions :from => :sleeping, :to => :working, :on_transition => :wear_clothes
|
395
|
-
transitions :from => :showering, :to => [:working, :dating], :on_transition => Proc.new { |obj, *args| obj.wear_clothes(*args) }
|
396
|
-
transitions :from => :showering, :to => :prettying_up, :on_transition => [:condition_hair, :fix_hair]
|
397
|
-
end
|
398
|
-
|
399
|
-
def wear_clothes(shirt_color, trouser_type)
|
400
|
-
end
|
401
|
-
|
402
|
-
def condition_hair
|
403
|
-
end
|
404
|
-
|
405
|
-
def fix_hair
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
336
|
|
410
337
|
describe ChetanPatil do
|
411
338
|
it 'should transition to specified next state (sleeping to showering)' do
|
@@ -1,246 +1,250 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'logger'
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require 'logger'
|
5
4
|
|
6
|
-
|
5
|
+
load_schema
|
7
6
|
|
8
|
-
|
7
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
class Gate < ActiveRecord::Base
|
10
|
+
include AASM
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
# Fake this column for testing purposes
|
13
|
+
attr_accessor :aasm_state
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
aasm_state :opened
|
16
|
+
aasm_state :closed
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
aasm_event :view do
|
19
|
+
transitions :to => :read, :from => [:needs_attention]
|
22
20
|
end
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
include AASM
|
23
|
+
class Reader < ActiveRecord::Base
|
24
|
+
def aasm_read_state
|
25
|
+
"fi"
|
29
26
|
end
|
27
|
+
include AASM
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
include AASM
|
30
|
+
class Writer < ActiveRecord::Base
|
31
|
+
def aasm_write_state(state)
|
32
|
+
"fo"
|
36
33
|
end
|
34
|
+
include AASM
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
include AASM
|
37
|
+
class Transient < ActiveRecord::Base
|
38
|
+
def aasm_write_state_without_persistence(state)
|
39
|
+
"fum"
|
43
40
|
end
|
41
|
+
include AASM
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
class Simple < ActiveRecord::Base
|
45
|
+
include AASM
|
46
|
+
aasm_column :status
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
class SimpleNewDsl < ActiveRecord::Base
|
50
|
+
include AASM
|
51
|
+
aasm :column => :status
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
include AASM
|
56
|
-
aasm_initial_state Proc.new { |thief| thief.skilled ? :rich : :jailed }
|
57
|
-
aasm_state :rich
|
58
|
-
aasm_state :jailed
|
59
|
-
attr_accessor :skilled, :aasm_state
|
60
|
-
end
|
54
|
+
class Derivate < Simple
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
|
65
|
-
end
|
66
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::InstanceMethods" do
|
67
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
68
|
-
end
|
69
|
-
end
|
57
|
+
class DerivateNewDsl < SimpleNewDsl
|
58
|
+
end
|
70
59
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
80
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
81
|
-
end
|
82
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
83
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
84
|
-
end
|
85
|
-
end
|
60
|
+
class Thief < ActiveRecord::Base
|
61
|
+
set_table_name "thieves"
|
62
|
+
include AASM
|
63
|
+
aasm_initial_state Proc.new { |thief| thief.skilled ? :rich : :jailed }
|
64
|
+
aasm_state :rich
|
65
|
+
aasm_state :jailed
|
66
|
+
attr_accessor :skilled, :aasm_state
|
67
|
+
end
|
86
68
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
94
|
-
end
|
95
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
96
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
97
|
-
end
|
98
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
99
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
100
|
-
end
|
69
|
+
shared_examples_for "aasm model" do
|
70
|
+
it "should include AASM::Persistence::ActiveRecordPersistence" do
|
71
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
|
72
|
+
end
|
73
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::InstanceMethods" do
|
74
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
101
75
|
end
|
76
|
+
end
|
102
77
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
it_should_behave_like "aasm model"
|
108
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
109
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
110
|
-
end
|
111
|
-
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
112
|
-
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
113
|
-
end
|
114
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
115
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
116
|
-
end
|
78
|
+
describe Gate, "class methods" do
|
79
|
+
before(:each) do
|
80
|
+
@klass = Gate
|
117
81
|
end
|
82
|
+
it_should_behave_like "aasm model"
|
83
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
84
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
85
|
+
end
|
86
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
87
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
88
|
+
end
|
89
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
90
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
91
|
+
end
|
92
|
+
end
|
118
93
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
94
|
+
describe Reader, "class methods" do
|
95
|
+
before(:each) do
|
96
|
+
@klass = Reader
|
97
|
+
end
|
98
|
+
it_should_behave_like "aasm model"
|
99
|
+
it "should not include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
100
|
+
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
101
|
+
end
|
102
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
103
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
104
|
+
end
|
105
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
106
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
133
107
|
end
|
108
|
+
end
|
134
109
|
|
135
|
-
|
110
|
+
describe Writer, "class methods" do
|
111
|
+
before(:each) do
|
112
|
+
@klass = Writer
|
113
|
+
end
|
114
|
+
it_should_behave_like "aasm model"
|
115
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
116
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
117
|
+
end
|
118
|
+
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
119
|
+
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
120
|
+
end
|
121
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
122
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
123
|
+
end
|
124
|
+
end
|
136
125
|
|
137
|
-
|
138
|
-
|
139
|
-
|
126
|
+
describe Transient, "class methods" do
|
127
|
+
before(:each) do
|
128
|
+
@klass = Transient
|
129
|
+
end
|
130
|
+
it_should_behave_like "aasm model"
|
131
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
132
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
133
|
+
end
|
134
|
+
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
135
|
+
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
136
|
+
end
|
137
|
+
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
138
|
+
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
139
|
+
end
|
140
|
+
end
|
140
141
|
|
141
|
-
|
142
|
-
Gate.new.should respond_to(:aasm_write_state)
|
143
|
-
end
|
142
|
+
describe Gate, "instance methods" do
|
144
143
|
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
it "should respond to aasm read state when not previously defined" do
|
145
|
+
Gate.new.should respond_to(:aasm_read_state)
|
146
|
+
end
|
148
147
|
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
it "should respond to aasm write state when not previously defined" do
|
149
|
+
Gate.new.should respond_to(:aasm_write_state)
|
150
|
+
end
|
152
151
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
foo.aasm_current_state.should == :closed
|
157
|
-
end
|
152
|
+
it "should respond to aasm write state without persistence when not previously defined" do
|
153
|
+
Gate.new.should respond_to(:aasm_write_state_without_persistence)
|
154
|
+
end
|
158
155
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
foo.aasm_state = "state"
|
163
|
-
foo.aasm_current_state.should == :state
|
164
|
-
end
|
156
|
+
it "should return the initial state when new and the aasm field is nil" do
|
157
|
+
Gate.new.aasm_current_state.should == :opened
|
158
|
+
end
|
165
159
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
160
|
+
it "should return the aasm column when new and the aasm field is not nil" do
|
161
|
+
foo = Gate.new
|
162
|
+
foo.aasm_state = "closed"
|
163
|
+
foo.aasm_current_state.should == :closed
|
164
|
+
end
|
172
165
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
166
|
+
it "should return the aasm column when not new and the aasm_column is not nil" do
|
167
|
+
foo = Gate.new
|
168
|
+
foo.stub!(:new_record?).and_return(false)
|
169
|
+
foo.aasm_state = "state"
|
170
|
+
foo.aasm_current_state.should == :state
|
171
|
+
end
|
177
172
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
173
|
+
it "should allow a nil state" do
|
174
|
+
foo = Gate.new
|
175
|
+
foo.stub!(:new_record?).and_return(false)
|
176
|
+
foo.aasm_state = nil
|
177
|
+
foo.aasm_current_state.should be_nil
|
178
|
+
end
|
183
179
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
foo.valid?
|
189
|
-
end
|
180
|
+
it "should have aasm_ensure_initial_state" do
|
181
|
+
foo = Gate.new
|
182
|
+
foo.send :aasm_ensure_initial_state
|
183
|
+
end
|
190
184
|
|
185
|
+
it "should call aasm_ensure_initial_state on validation before create" do
|
186
|
+
foo = Gate.new
|
187
|
+
foo.should_receive(:aasm_ensure_initial_state).and_return(true)
|
188
|
+
foo.valid?
|
191
189
|
end
|
192
190
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
191
|
+
it "should call aasm_ensure_initial_state on validation before create" do
|
192
|
+
foo = Gate.new
|
193
|
+
foo.stub!(:new_record?).and_return(false)
|
194
|
+
foo.should_not_receive(:aasm_ensure_initial_state)
|
195
|
+
foo.valid?
|
196
|
+
end
|
197
197
|
|
198
|
-
|
199
|
-
Derivate.aasm_events.should == Simple.aasm_events
|
200
|
-
end
|
198
|
+
end
|
201
199
|
|
202
|
-
|
203
|
-
|
204
|
-
|
200
|
+
describe 'Derivates' do
|
201
|
+
it "should have the same states as its parent" do
|
202
|
+
Derivate.aasm_states.should == Simple.aasm_states
|
205
203
|
end
|
206
204
|
|
207
|
-
|
205
|
+
it "should have the same events as its parent" do
|
206
|
+
Derivate.aasm_events.should == Simple.aasm_events
|
207
|
+
end
|
208
208
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
Simple.aasm_state :unknown_scope
|
213
|
-
Simple.should respond_to(:unknown_scope)
|
214
|
-
Simple.unknown_scope.class.should == ActiveRecord::Relation
|
215
|
-
end
|
216
|
-
end
|
209
|
+
it "should have the same column as its parent" do
|
210
|
+
Derivate.aasm_column.should == :status
|
211
|
+
end
|
217
212
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
Simple.should respond_to(:new)
|
222
|
-
Simple.new.class.should == Simple
|
223
|
-
end
|
224
|
-
end
|
213
|
+
it "should have the same column as its parent even for the new dsl" do
|
214
|
+
SimpleNewDsl.aasm_column.should == :status
|
215
|
+
DerivateNewDsl.aasm_column.should == :status
|
225
216
|
end
|
217
|
+
end
|
226
218
|
|
227
|
-
|
219
|
+
describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do
|
228
220
|
|
229
|
-
|
230
|
-
|
221
|
+
context "Does not already respond_to? the scope name" do
|
222
|
+
it "should add a scope" do
|
223
|
+
Simple.should_not respond_to(:unknown_scope)
|
224
|
+
Simple.aasm_state :unknown_scope
|
225
|
+
Simple.should respond_to(:unknown_scope)
|
226
|
+
Simple.unknown_scope.class.should == ActiveRecord::Relation
|
231
227
|
end
|
228
|
+
end
|
232
229
|
|
233
|
-
|
234
|
-
|
230
|
+
context "Already respond_to? the scope name" do
|
231
|
+
it "should not add a scope" do
|
232
|
+
Simple.aasm_state :new
|
233
|
+
Simple.should respond_to(:new)
|
234
|
+
Simple.new.class.should == Simple
|
235
235
|
end
|
236
236
|
end
|
237
|
+
end
|
237
238
|
|
238
|
-
|
239
|
+
describe 'Thieves' do
|
239
240
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
241
|
+
it 'should be rich if they\'re skilled' do
|
242
|
+
Thief.new(:skilled => true).aasm_current_state.should == :rich
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should be jailed if they\'re unskilled' do
|
246
|
+
Thief.new(:skilled => false).aasm_current_state.should == :jailed
|
245
247
|
end
|
246
248
|
end
|
249
|
+
|
250
|
+
# TODO: figure out how to test ActiveRecord reload! without a database
|