aasm 4.5.0 → 4.5.1
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +13 -1
- data/lib/aasm/aasm.rb +14 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/models/silencer.rb +5 -0
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +13 -0
- data/spec/unit/persistence/active_record_persistence_spec.rb +12 -0
- data/spec/unit/transition_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0308a8cef74abb6ac913b1dd31bc8673951a837
|
|
4
|
+
data.tar.gz: aef81a4c7f1f4045cd9e5202e65e7fd3562a1db2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9d0dcf0e16ccf7ecf050163cdee8f6f8e993f17890a73508e64f48e519970810d3df30fef5bec877bb5cd6dd311570c6cf6ccd77b779c4f0220ceee660a8ebf
|
|
7
|
+
data.tar.gz: 852dd93351612a60d03472b8ff4a043ffe488d89e620fedc498c5d9895c6260b83aaf182d5b50a9bdd4929a09ba68f704a152aa4cd3134d904e3c4b1e5f061b6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 4.5.1
|
|
4
|
+
|
|
5
|
+
* make sure to use override configuration options if state machine is defined more than once (see [issue #287](https://github.com/aasm/aasm/issues/287) for details)
|
|
6
|
+
|
|
3
7
|
## 4.5.0
|
|
4
8
|
|
|
5
9
|
* add RSpec matchers `have_state`, `allow_event` and `allow_transition_to` (see [issue #147](https://github.com/aasm/aasm/issues/147) for details)
|
data/README.md
CHANGED
|
@@ -615,7 +615,7 @@ callback or the state update fails, all changes to any database record are rolle
|
|
|
615
615
|
Mongodb does not support transactions.
|
|
616
616
|
|
|
617
617
|
If you want to make sure a depending action happens only after the transaction is committed,
|
|
618
|
-
use the `after_commit` callback, like this:
|
|
618
|
+
use the `after_commit` callback along with the auto-save (bang) methods, like this:
|
|
619
619
|
|
|
620
620
|
```ruby
|
|
621
621
|
class Job < ActiveRecord::Base
|
|
@@ -634,6 +634,18 @@ class Job < ActiveRecord::Base
|
|
|
634
634
|
...
|
|
635
635
|
end
|
|
636
636
|
end
|
|
637
|
+
|
|
638
|
+
job = Job.where(state: 'sleeping').first!
|
|
639
|
+
job.run! # Saves the model and triggers the after_commit callback
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
Note that the following will not run the `after_commit` callbacks because
|
|
643
|
+
the auto-save method is not used:
|
|
644
|
+
|
|
645
|
+
```ruby
|
|
646
|
+
job = Job.where(state: 'sleeping').first!
|
|
647
|
+
job.run
|
|
648
|
+
job.save! #notify_about_running_job is not run
|
|
637
649
|
```
|
|
638
650
|
|
|
639
651
|
If you want to encapsulate state changes within an own transaction, the behavior
|
data/lib/aasm/aasm.rb
CHANGED
|
@@ -39,7 +39,20 @@ module AASM
|
|
|
39
39
|
AASM::StateMachine[self][state_machine_name] ||= AASM::StateMachine.new(state_machine_name)
|
|
40
40
|
|
|
41
41
|
@aasm ||= {}
|
|
42
|
-
@aasm[state_machine_name]
|
|
42
|
+
if @aasm[state_machine_name]
|
|
43
|
+
# make sure to use provided options
|
|
44
|
+
options.each do |key, value|
|
|
45
|
+
@aasm[state_machine_name].state_machine.config.send("#{key}=", value)
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
# create a new base
|
|
49
|
+
@aasm[state_machine_name] = AASM::Base.new(
|
|
50
|
+
self,
|
|
51
|
+
state_machine_name,
|
|
52
|
+
AASM::StateMachine[self][state_machine_name],
|
|
53
|
+
options
|
|
54
|
+
)
|
|
55
|
+
end
|
|
43
56
|
@aasm[state_machine_name].instance_eval(&block) if block # new DSL
|
|
44
57
|
@aasm[state_machine_name]
|
|
45
58
|
end
|
data/lib/aasm/version.rb
CHANGED
data/spec/models/silencer.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
class Silencer
|
|
2
2
|
include AASM
|
|
3
3
|
|
|
4
|
+
# yes, this line is here on purpose
|
|
5
|
+
# by this, we test if overriding configuration options works if
|
|
6
|
+
# the state machine is "re-opened"
|
|
7
|
+
aasm :whiny_transitions => true
|
|
8
|
+
|
|
4
9
|
aasm :whiny_transitions => false do
|
|
5
10
|
state :silent, :initial => true
|
|
6
11
|
state :crying
|
|
@@ -298,6 +298,19 @@ describe "named scopes with the new DSL" do
|
|
|
298
298
|
it "does not create scopes if requested" do
|
|
299
299
|
expect(MultipleNoScope).not_to respond_to(:pending)
|
|
300
300
|
end
|
|
301
|
+
|
|
302
|
+
context "result of scope" do
|
|
303
|
+
let!(:dsl1) { MultipleSimpleNewDsl.create!(status: :new) }
|
|
304
|
+
let!(:dsl2) { MultipleSimpleNewDsl.create!(status: :unknown_scope) }
|
|
305
|
+
|
|
306
|
+
after do
|
|
307
|
+
MultipleSimpleNewDsl.destroy_all
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it "created scope works as where(name: :scope_name)" do
|
|
311
|
+
expect(MultipleSimpleNewDsl.unknown_scope).to contain_exactly(dsl2)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
301
314
|
end # scopes
|
|
302
315
|
|
|
303
316
|
describe "direct assignment" do
|
|
@@ -299,6 +299,18 @@ describe "named scopes with the new DSL" do
|
|
|
299
299
|
expect(NoScope).not_to respond_to(:pending)
|
|
300
300
|
end
|
|
301
301
|
|
|
302
|
+
context "result of scope" do
|
|
303
|
+
let!(:dsl1) { SimpleNewDsl.create!(status: :new) }
|
|
304
|
+
let!(:dsl2) { SimpleNewDsl.create!(status: :unknown_scope) }
|
|
305
|
+
|
|
306
|
+
after do
|
|
307
|
+
SimpleNewDsl.destroy_all
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it "created scope works as where(name: :scope_name)" do
|
|
311
|
+
expect(SimpleNewDsl.unknown_scope).to contain_exactly(dsl2)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
302
314
|
end # scopes
|
|
303
315
|
|
|
304
316
|
describe "direct assignment" do
|
|
@@ -31,7 +31,7 @@ describe 'transitions' do
|
|
|
31
31
|
expect(silencer).to be_smiling
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
it 'should call the block
|
|
34
|
+
it 'should call the block on success' do
|
|
35
35
|
silencer = Silencer.new
|
|
36
36
|
success = false
|
|
37
37
|
expect {
|
|
@@ -41,7 +41,7 @@ describe 'transitions' do
|
|
|
41
41
|
}.to change { success }.to(true)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
it 'should not call the block
|
|
44
|
+
it 'should not call the block on failure' do
|
|
45
45
|
silencer = Silencer.new
|
|
46
46
|
success = false
|
|
47
47
|
expect {
|
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: 4.5.
|
|
4
|
+
version: 4.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott Barron
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2015-
|
|
13
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rake
|
|
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
256
256
|
version: '0'
|
|
257
257
|
requirements: []
|
|
258
258
|
rubyforge_project:
|
|
259
|
-
rubygems_version: 2.
|
|
259
|
+
rubygems_version: 2.4.5
|
|
260
260
|
signing_key:
|
|
261
261
|
specification_version: 4
|
|
262
262
|
summary: State machine mixin for Ruby objects
|