aasm 3.0.13 → 3.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -6
- data/README.md +217 -109
- data/aasm.gemspec +1 -0
- data/lib/aasm/persistence.rb +2 -0
- data/lib/aasm/persistence/active_record_persistence.rb +2 -71
- data/lib/aasm/persistence/base.rb +46 -0
- data/lib/aasm/persistence/mongoid_persistence.rb +3 -92
- data/lib/aasm/persistence/read_state.rb +40 -0
- data/lib/aasm/supporting_classes/event.rb +6 -2
- data/lib/aasm/supporting_classes/localizer.rb +15 -13
- data/lib/aasm/supporting_classes/state.rb +8 -0
- data/lib/aasm/version.rb +1 -1
- data/spec/models/auth_machine.rb +84 -0
- data/spec/models/callback_new_dsl.rb +38 -0
- data/spec/models/callback_old_dsl.rb +36 -0
- data/spec/models/persistence.rb +71 -0
- data/spec/spec_helpers/models_spec_helper.rb +0 -85
- data/spec/unit/aasm_spec.rb +1 -1
- data/spec/unit/callbacks_new_dsl_spec.rb +33 -0
- data/spec/unit/callbacks_old_dsl_spec.rb +33 -0
- data/spec/unit/complex_example_spec.rb +75 -0
- data/spec/unit/event_spec.rb +31 -12
- data/spec/unit/inspection_spec.rb +7 -0
- data/spec/unit/persistence/active_record_persistence_spec.rb +228 -0
- metadata +41 -29
- data/spec/unit/active_record_persistence_spec.rb +0 -334
- data/spec/unit/auth_machine_spec.rb +0 -83
- data/spec/unit/before_after_callbacks_spec.rb +0 -79
- data/spec/unit/conversation_spec.rb +0 -7
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.14
|
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-11-06 00:00:00.000000000Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
19
|
-
requirement: &
|
19
|
+
requirement: &70345873130760 !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: *70345873130760
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
|
-
requirement: &
|
30
|
+
requirement: &70345873130340 !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: *70345873130340
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: sdoc
|
41
|
-
requirement: &
|
41
|
+
requirement: &70345873129920 !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: *70345873129920
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rspec
|
52
|
-
requirement: &
|
52
|
+
requirement: &70345873129420 !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: *70345873129420
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rr
|
63
|
-
requirement: &
|
63
|
+
requirement: &70345873129000 !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: *70345873129000
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: shoulda
|
74
|
-
requirement: &
|
74
|
+
requirement: &70345873128540 !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: *70345873128540
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
|
-
requirement: &
|
85
|
+
requirement: &70345873128120 !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: *70345873128120
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: minitest
|
96
|
-
requirement: &
|
96
|
+
requirement: &70345873127700 !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: *70345873127700
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-debug-completion
|
107
|
-
requirement: &
|
107
|
+
requirement: &70345873143660 !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: *70345873143660
|
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
|
@@ -136,7 +136,9 @@ files:
|
|
136
136
|
- lib/aasm/errors.rb
|
137
137
|
- lib/aasm/persistence.rb
|
138
138
|
- lib/aasm/persistence/active_record_persistence.rb
|
139
|
+
- lib/aasm/persistence/base.rb
|
139
140
|
- lib/aasm/persistence/mongoid_persistence.rb
|
141
|
+
- lib/aasm/persistence/read_state.rb
|
140
142
|
- lib/aasm/state_machine.rb
|
141
143
|
- lib/aasm/supporting_classes/event.rb
|
142
144
|
- lib/aasm/supporting_classes/localizer.rb
|
@@ -146,9 +148,13 @@ files:
|
|
146
148
|
- spec/database.yml
|
147
149
|
- spec/en.yml
|
148
150
|
- spec/en_deprecated_style.yml
|
151
|
+
- spec/models/auth_machine.rb
|
152
|
+
- spec/models/callback_new_dsl.rb
|
153
|
+
- spec/models/callback_old_dsl.rb
|
149
154
|
- spec/models/conversation.rb
|
150
155
|
- spec/models/invalid_persistor.rb
|
151
156
|
- spec/models/not_auto_loaded/process.rb
|
157
|
+
- spec/models/persistence.rb
|
152
158
|
- spec/models/process_with_new_dsl.rb
|
153
159
|
- spec/models/silencer.rb
|
154
160
|
- spec/models/sub_classing.rb
|
@@ -159,14 +165,15 @@ files:
|
|
159
165
|
- spec/spec_helper.rb
|
160
166
|
- spec/spec_helpers/models_spec_helper.rb
|
161
167
|
- spec/unit/aasm_spec.rb
|
162
|
-
- spec/unit/
|
163
|
-
- spec/unit/
|
164
|
-
- spec/unit/
|
165
|
-
- spec/unit/conversation_spec.rb
|
168
|
+
- spec/unit/callbacks_new_dsl_spec.rb
|
169
|
+
- spec/unit/callbacks_old_dsl_spec.rb
|
170
|
+
- spec/unit/complex_example_spec.rb
|
166
171
|
- spec/unit/event_spec.rb
|
172
|
+
- spec/unit/inspection_spec.rb
|
167
173
|
- spec/unit/localizer_spec.rb
|
168
174
|
- spec/unit/memory_leak_spec.rb
|
169
175
|
- spec/unit/new_dsl_spec.rb
|
176
|
+
- spec/unit/persistence/active_record_persistence_spec.rb
|
170
177
|
- spec/unit/state_spec.rb
|
171
178
|
- spec/unit/state_transition_spec.rb
|
172
179
|
homepage: https://github.com/aasm/aasm
|
@@ -190,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
197
|
version: '0'
|
191
198
|
requirements: []
|
192
199
|
rubyforge_project:
|
193
|
-
rubygems_version: 1.8.
|
200
|
+
rubygems_version: 1.8.15
|
194
201
|
signing_key:
|
195
202
|
specification_version: 3
|
196
203
|
summary: State machine mixin for Ruby objects
|
@@ -198,9 +205,13 @@ test_files:
|
|
198
205
|
- spec/database.yml
|
199
206
|
- spec/en.yml
|
200
207
|
- spec/en_deprecated_style.yml
|
208
|
+
- spec/models/auth_machine.rb
|
209
|
+
- spec/models/callback_new_dsl.rb
|
210
|
+
- spec/models/callback_old_dsl.rb
|
201
211
|
- spec/models/conversation.rb
|
202
212
|
- spec/models/invalid_persistor.rb
|
203
213
|
- spec/models/not_auto_loaded/process.rb
|
214
|
+
- spec/models/persistence.rb
|
204
215
|
- spec/models/process_with_new_dsl.rb
|
205
216
|
- spec/models/silencer.rb
|
206
217
|
- spec/models/sub_classing.rb
|
@@ -211,13 +222,14 @@ test_files:
|
|
211
222
|
- spec/spec_helper.rb
|
212
223
|
- spec/spec_helpers/models_spec_helper.rb
|
213
224
|
- spec/unit/aasm_spec.rb
|
214
|
-
- spec/unit/
|
215
|
-
- spec/unit/
|
216
|
-
- spec/unit/
|
217
|
-
- spec/unit/conversation_spec.rb
|
225
|
+
- spec/unit/callbacks_new_dsl_spec.rb
|
226
|
+
- spec/unit/callbacks_old_dsl_spec.rb
|
227
|
+
- spec/unit/complex_example_spec.rb
|
218
228
|
- spec/unit/event_spec.rb
|
229
|
+
- spec/unit/inspection_spec.rb
|
219
230
|
- spec/unit/localizer_spec.rb
|
220
231
|
- spec/unit/memory_leak_spec.rb
|
221
232
|
- spec/unit/new_dsl_spec.rb
|
233
|
+
- spec/unit/persistence/active_record_persistence_spec.rb
|
222
234
|
- spec/unit/state_spec.rb
|
223
235
|
- spec/unit/state_transition_spec.rb
|
@@ -1,334 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_record'
|
3
|
-
require 'logger'
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
load_schema
|
7
|
-
|
8
|
-
# if you want to see the statements while running the spec enable the following line
|
9
|
-
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
10
|
-
|
11
|
-
class Gate < ActiveRecord::Base
|
12
|
-
include AASM
|
13
|
-
|
14
|
-
# Fake this column for testing purposes
|
15
|
-
attr_accessor :aasm_state
|
16
|
-
|
17
|
-
aasm do
|
18
|
-
state :opened
|
19
|
-
state :closed
|
20
|
-
|
21
|
-
event :view do
|
22
|
-
transitions :to => :read, :from => [:needs_attention]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Reader < ActiveRecord::Base
|
28
|
-
def aasm_read_state
|
29
|
-
"fi"
|
30
|
-
end
|
31
|
-
include AASM
|
32
|
-
end
|
33
|
-
|
34
|
-
class Writer < ActiveRecord::Base
|
35
|
-
def aasm_write_state(state)
|
36
|
-
"fo"
|
37
|
-
end
|
38
|
-
include AASM
|
39
|
-
end
|
40
|
-
|
41
|
-
class Transient < ActiveRecord::Base
|
42
|
-
def aasm_write_state_without_persistence(state)
|
43
|
-
"fum"
|
44
|
-
end
|
45
|
-
include AASM
|
46
|
-
end
|
47
|
-
|
48
|
-
class Simple < ActiveRecord::Base
|
49
|
-
include AASM
|
50
|
-
aasm_column :status
|
51
|
-
aasm_state :unknown_scope
|
52
|
-
aasm_state :new
|
53
|
-
end
|
54
|
-
|
55
|
-
class SimpleNewDsl < ActiveRecord::Base
|
56
|
-
include AASM
|
57
|
-
aasm :column => :status
|
58
|
-
aasm do
|
59
|
-
state :unknown_scope
|
60
|
-
state :new
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class Derivate < Simple
|
65
|
-
end
|
66
|
-
|
67
|
-
class DerivateNewDsl < SimpleNewDsl
|
68
|
-
end
|
69
|
-
|
70
|
-
class Thief < ActiveRecord::Base
|
71
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
72
|
-
self.table_name = 'thieves'
|
73
|
-
else
|
74
|
-
set_table_name "thieves"
|
75
|
-
end
|
76
|
-
include AASM
|
77
|
-
aasm_initial_state Proc.new { |thief| thief.skilled ? :rich : :jailed }
|
78
|
-
aasm_state :rich
|
79
|
-
aasm_state :jailed
|
80
|
-
attr_accessor :skilled, :aasm_state
|
81
|
-
end
|
82
|
-
|
83
|
-
shared_examples_for "aasm model" do
|
84
|
-
it "should include AASM::Persistence::ActiveRecordPersistence" do
|
85
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
|
86
|
-
end
|
87
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::InstanceMethods" do
|
88
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe Gate, "class methods" do
|
93
|
-
before(:each) do
|
94
|
-
@klass = Gate
|
95
|
-
end
|
96
|
-
it_should_behave_like "aasm model"
|
97
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
98
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
99
|
-
end
|
100
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
101
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
102
|
-
end
|
103
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
104
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe Reader, "class methods" do
|
109
|
-
before(:each) do
|
110
|
-
@klass = Reader
|
111
|
-
end
|
112
|
-
it_should_behave_like "aasm model"
|
113
|
-
it "should not include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
114
|
-
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
115
|
-
end
|
116
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
117
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
118
|
-
end
|
119
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
120
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe Writer, "class methods" do
|
125
|
-
before(:each) do
|
126
|
-
@klass = Writer
|
127
|
-
end
|
128
|
-
it_should_behave_like "aasm model"
|
129
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
130
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
131
|
-
end
|
132
|
-
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
133
|
-
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
134
|
-
end
|
135
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
136
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe Transient, "class methods" do
|
141
|
-
before(:each) do
|
142
|
-
@klass = Transient
|
143
|
-
end
|
144
|
-
it_should_behave_like "aasm model"
|
145
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
146
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
147
|
-
end
|
148
|
-
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
149
|
-
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
150
|
-
end
|
151
|
-
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
152
|
-
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe Gate, "instance methods" do
|
157
|
-
|
158
|
-
before do
|
159
|
-
@gate = Gate.new
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should respond to aasm read state when not previously defined" do
|
163
|
-
@gate.should respond_to(:aasm_read_state)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should respond to aasm write state when not previously defined" do
|
167
|
-
@gate.should respond_to(:aasm_write_state)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should respond to aasm write state without persistence when not previously defined" do
|
171
|
-
@gate.should respond_to(:aasm_write_state_without_persistence)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should return the initial state when new and the aasm field is nil" do
|
175
|
-
@gate.aasm_current_state.should == :opened
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should return the aasm column when new and the aasm field is not nil" do
|
179
|
-
@gate.aasm_state = "closed"
|
180
|
-
@gate.aasm_current_state.should == :closed
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should return the aasm column when not new and the aasm_column is not nil" do
|
184
|
-
@gate.stub!(:new_record?).and_return(false)
|
185
|
-
@gate.aasm_state = "state"
|
186
|
-
@gate.aasm_current_state.should == :state
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should allow a nil state" do
|
190
|
-
@gate.stub!(:new_record?).and_return(false)
|
191
|
-
@gate.aasm_state = nil
|
192
|
-
@gate.aasm_current_state.should be_nil
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should have aasm_ensure_initial_state" do
|
196
|
-
@gate.send :aasm_ensure_initial_state
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should call aasm_ensure_initial_state on validation before create" do
|
200
|
-
@gate.should_receive(:aasm_ensure_initial_state).and_return(true)
|
201
|
-
@gate.valid?
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should call aasm_ensure_initial_state on validation before create" do
|
205
|
-
@gate.stub!(:new_record?).and_return(false)
|
206
|
-
@gate.should_not_receive(:aasm_ensure_initial_state)
|
207
|
-
@gate.valid?
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
describe 'Derivates' do
|
213
|
-
it "should have the same states as its parent" do
|
214
|
-
Derivate.aasm_states.should == Simple.aasm_states
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should have the same events as its parent" do
|
218
|
-
Derivate.aasm_events.should == Simple.aasm_events
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should have the same column as its parent" do
|
222
|
-
Derivate.aasm_column.should == :status
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should have the same column as its parent even for the new dsl" do
|
226
|
-
SimpleNewDsl.aasm_column.should == :status
|
227
|
-
DerivateNewDsl.aasm_column.should == :status
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods" do
|
232
|
-
|
233
|
-
context "Old DSL Does not already respond_to? the scope name" do
|
234
|
-
it "should add a scope" do
|
235
|
-
Simple.should respond_to(:unknown_scope)
|
236
|
-
Simple.unknown_scope.class.should == ActiveRecord::Relation
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context "Old DSL Already respond_to? the scope name" do
|
241
|
-
it "should not add a scope" do
|
242
|
-
Simple.should respond_to(:new)
|
243
|
-
Simple.new.class.should == Simple
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "New DSL Does not already respond_to? the scope name" do
|
248
|
-
it "should add a scope" do
|
249
|
-
SimpleNewDsl.should respond_to(:unknown_scope)
|
250
|
-
SimpleNewDsl.unknown_scope.class.should == ActiveRecord::Relation
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
context "New DSL Already respond_to? the scope name" do
|
255
|
-
it "should not add a scope" do
|
256
|
-
SimpleNewDsl.should respond_to(:new)
|
257
|
-
SimpleNewDsl.new.class.should == SimpleNewDsl
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
describe 'Thieves' do
|
264
|
-
|
265
|
-
it 'should be rich if they\'re skilled' do
|
266
|
-
Thief.new(:skilled => true).aasm_current_state.should == :rich
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'should be jailed if they\'re unskilled' do
|
270
|
-
Thief.new(:skilled => false).aasm_current_state.should == :jailed
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe 'transitions with persistence' do
|
275
|
-
|
276
|
-
it 'should not store states for invalid models' do
|
277
|
-
validator = Validator.create(:name => 'name')
|
278
|
-
validator.should be_valid
|
279
|
-
validator.should be_sleeping
|
280
|
-
|
281
|
-
validator.name = nil
|
282
|
-
validator.should_not be_valid
|
283
|
-
validator.run!.should be_false
|
284
|
-
validator.should be_sleeping
|
285
|
-
|
286
|
-
validator.reload
|
287
|
-
validator.should_not be_running
|
288
|
-
validator.should be_sleeping
|
289
|
-
|
290
|
-
validator.name = 'another name'
|
291
|
-
validator.should be_valid
|
292
|
-
validator.run!.should be_true
|
293
|
-
validator.should be_running
|
294
|
-
|
295
|
-
validator.reload
|
296
|
-
validator.should be_running
|
297
|
-
validator.should_not be_sleeping
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'should store states for invalid models if configured' do
|
301
|
-
persistor = InvalidPersistor.create(:name => 'name')
|
302
|
-
persistor.should be_valid
|
303
|
-
persistor.should be_sleeping
|
304
|
-
|
305
|
-
persistor.name = nil
|
306
|
-
persistor.should_not be_valid
|
307
|
-
persistor.run!.should be_true
|
308
|
-
persistor.should be_running
|
309
|
-
|
310
|
-
persistor = InvalidPersistor.find(persistor.id)
|
311
|
-
persistor.valid?
|
312
|
-
persistor.should be_valid
|
313
|
-
persistor.should be_running
|
314
|
-
persistor.should_not be_sleeping
|
315
|
-
|
316
|
-
persistor.reload
|
317
|
-
persistor.should be_running
|
318
|
-
persistor.should_not be_sleeping
|
319
|
-
end
|
320
|
-
|
321
|
-
describe 'transactions' do
|
322
|
-
it 'should rollback all changes' do
|
323
|
-
worker = Worker.create!(:name => 'worker', :status => 'sleeping')
|
324
|
-
transactor = Transactor.create!(:name => 'transactor', :worker => worker)
|
325
|
-
transactor.should be_sleeping
|
326
|
-
worker.status.should == 'sleeping'
|
327
|
-
|
328
|
-
lambda {transactor.run!}.should raise_error(StandardError, 'failed on purpose')
|
329
|
-
transactor.should be_running
|
330
|
-
worker.reload.status.should == 'sleeping'
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
end
|