aasm 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -2
- data/lib/aasm/aasm.rb +4 -4
- data/lib/aasm/persistence/active_record_persistence.rb +2 -4
- data/lib/aasm/persistence/sequel_persistence.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/unit/event_naming_spec.rb +24 -0
- data/spec/unit/persistence/active_record_persistence_spec.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83a1f3168fccb10e8b1514ced2d81ec931c5c53a
|
4
|
+
data.tar.gz: 216b3cdd8404f5b2cd963c99a975946848a06e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea1641220521468b48b11ce9e8fb868a85d1e34d44ddc8256cb2a26ccc055f2cddcf3b557358a651239d2d6cc5d3bedf6f53e9baaf9122b6329c5d3cdd2ed25e
|
7
|
+
data.tar.gz: 2f4e51a87d973d04a16cd64692d0fbcf48df87ab7ee8d412411ca7cb742005b68f7a7ee2ae3d953b0ab01bd8f7956ffd98dd95ba6eda0e3e9b7a6b3533eaa0ea
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
|
5
5
|
* deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
|
6
6
|
|
7
|
+
## 3.3.2
|
8
|
+
|
9
|
+
* bugfix: avoid conflicts with `failed` and `fired` event names (see [issue #157](https://github.com/aasm/aasm/issues/157)), thanks to [@MichaelXavier](https://github.com/MichaelXavier)
|
10
|
+
* bugfix: not using transactions unless saving to the database (see [issue #162](https://github.com/aasm/aasm/issues/162) and [issue #164](https://github.com/aasm/aasm/issues/164)), thanks to [@roberthoner](https://github.com/roberthoner)
|
11
|
+
* bugfix: `after_commit` should only run if saving to the database (see [issue #151](https://github.com/aasm/aasm/issues/151)), thanks to [@ivantsepp](https://github.com/ivantsepp)
|
12
|
+
|
7
13
|
## 3.3.1
|
8
14
|
|
9
15
|
* bugfix: permissible events will respect given `guards` (see [issue #150](https://github.com/aasm/aasm/issues/150))
|
data/README.md
CHANGED
@@ -147,7 +147,9 @@ Also, you can pass parameters to events:
|
|
147
147
|
job.run(:running, :defragmentation)
|
148
148
|
```
|
149
149
|
|
150
|
-
In this case the `set_process` would be called with `:
|
150
|
+
In this case the `set_process` would be called with `:defragmentation` argument.
|
151
|
+
|
152
|
+
Note that when passing arguments to a state transition, the first argument must be the desired end state. In the above example, we wish to transition to `:running` state and run the callback with `:defragmentation` argument. You can also pass in `nil` as the desired end state, and AASM will try to transition to the first end state defined for that event.
|
151
153
|
|
152
154
|
In case of an error during the event processing the error is rescued and passed to `:error`
|
153
155
|
callback, which can handle it or re-raise it for further propagation.
|
@@ -212,7 +214,7 @@ You can even provide a number of guards, which all have to succeed to proceed
|
|
212
214
|
end
|
213
215
|
```
|
214
216
|
|
215
|
-
If you want to provide guards for all transitions
|
217
|
+
If you want to provide guards for all transitions within an event, you can use event guards
|
216
218
|
|
217
219
|
```ruby
|
218
220
|
event :sleep, :guards => [:walked_the_dog?] do
|
data/lib/aasm/aasm.rb
CHANGED
@@ -155,16 +155,16 @@ private
|
|
155
155
|
event.fire_callbacks(:before, self)
|
156
156
|
|
157
157
|
if new_state_name = event.fire(self, *args)
|
158
|
-
|
158
|
+
aasm_fired(event, old_state, new_state_name, options, &block)
|
159
159
|
else
|
160
|
-
|
160
|
+
aasm_failed(event_name, old_state)
|
161
161
|
end
|
162
162
|
rescue StandardError => e
|
163
163
|
event.fire_callbacks(:error, self, e) || raise(e)
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
def
|
167
|
+
def aasm_fired(event, old_state, new_state_name, options)
|
168
168
|
persist = options[:persist]
|
169
169
|
|
170
170
|
new_state = aasm.state_object_for_name(new_state_name)
|
@@ -200,7 +200,7 @@ private
|
|
200
200
|
persist_successful
|
201
201
|
end
|
202
202
|
|
203
|
-
def
|
203
|
+
def aasm_failed(event_name, old_state)
|
204
204
|
if self.respond_to?(:aasm_event_failed)
|
205
205
|
self.aasm_event_failed(event_name, old_state.name)
|
206
206
|
end
|
@@ -171,11 +171,9 @@ module AASM
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def aasm_fire_event(name, options, *args, &block)
|
174
|
-
success = self.class.transaction(:requires_new => requires_new?)
|
175
|
-
super
|
176
|
-
end
|
174
|
+
success = options[:persist] ? self.class.transaction(:requires_new => requires_new?) { super } : super
|
177
175
|
|
178
|
-
if success
|
176
|
+
if success && options[:persist]
|
179
177
|
new_state = aasm.state_object_for_name(aasm.current_state)
|
180
178
|
new_state.fire_callbacks(:after_commit, self)
|
181
179
|
end
|
@@ -84,7 +84,7 @@ module AASM
|
|
84
84
|
# NOTE: intended to be called from an event
|
85
85
|
def aasm_write_state state
|
86
86
|
aasm_column = self.class.aasm_column
|
87
|
-
|
87
|
+
update_only({aasm_column => state.to_s}, aasm_column)
|
88
88
|
end
|
89
89
|
|
90
90
|
# Writes <tt>state</tt> to the state column, but does not persist it to the database
|
data/lib/aasm/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SimpleStateMachine
|
4
|
+
include AASM
|
5
|
+
|
6
|
+
aasm do
|
7
|
+
state :init, :initial => true
|
8
|
+
state :failed
|
9
|
+
|
10
|
+
event :failed do
|
11
|
+
transitions :from => :init, :to => :failed
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "event naming" do
|
17
|
+
let(:state_machine) { SimpleStateMachine.new }
|
18
|
+
|
19
|
+
it "allows an event of failed without blowing the stack" do
|
20
|
+
state_machine.failed
|
21
|
+
|
22
|
+
expect { state_machine.failed }.to raise_error(AASM::InvalidTransition)
|
23
|
+
end
|
24
|
+
end
|
@@ -438,6 +438,31 @@ describe 'transitions with persistence' do
|
|
438
438
|
expect(validator.name).to eq("name")
|
439
439
|
end
|
440
440
|
|
441
|
+
it "should not fire if not saving" do
|
442
|
+
validator = Validator.create(:name => 'name')
|
443
|
+
expect(validator).to be_sleeping
|
444
|
+
validator.run
|
445
|
+
expect(validator).to be_running
|
446
|
+
expect(validator.name).to eq("name")
|
447
|
+
end
|
448
|
+
|
449
|
+
end
|
450
|
+
|
451
|
+
context "when not persisting" do
|
452
|
+
it 'should not rollback all changes' do
|
453
|
+
expect(transactor).to be_sleeping
|
454
|
+
expect(worker.status).to eq('sleeping')
|
455
|
+
|
456
|
+
# Notice here we're calling "run" and not "run!" with a bang.
|
457
|
+
expect {transactor.run}.to raise_error(StandardError, 'failed on purpose')
|
458
|
+
expect(transactor).to be_running
|
459
|
+
expect(worker.reload.status).to eq('running')
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'should not create a database transaction' do
|
463
|
+
expect(transactor.class).not_to receive(:transaction)
|
464
|
+
expect {transactor.run}.to raise_error(StandardError, 'failed on purpose')
|
465
|
+
end
|
441
466
|
end
|
442
467
|
end
|
443
468
|
end
|
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.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Barron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- spec/unit/api_spec.rb
|
167
167
|
- spec/unit/callbacks_spec.rb
|
168
168
|
- spec/unit/complex_example_spec.rb
|
169
|
+
- spec/unit/event_naming_spec.rb
|
169
170
|
- spec/unit/event_spec.rb
|
170
171
|
- spec/unit/guard_spec.rb
|
171
172
|
- spec/unit/initial_state_spec.rb
|
@@ -237,6 +238,7 @@ test_files:
|
|
237
238
|
- spec/unit/api_spec.rb
|
238
239
|
- spec/unit/callbacks_spec.rb
|
239
240
|
- spec/unit/complex_example_spec.rb
|
241
|
+
- spec/unit/event_naming_spec.rb
|
240
242
|
- spec/unit/event_spec.rb
|
241
243
|
- spec/unit/guard_spec.rb
|
242
244
|
- spec/unit/initial_state_spec.rb
|