aasm 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -5
- data/README.md +0 -10
- data/lib/aasm/core/event.rb +1 -0
- data/lib/aasm/persistence/active_record_persistence.rb +5 -4
- data/lib/aasm/version.rb +1 -1
- data/spec/database.rb +3 -0
- data/spec/models/active_record/simple_new_dsl.rb +15 -0
- data/spec/unit/callback_multiple_spec.rb +3 -3
- data/spec/unit/persistence/active_record_persistence_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea455b8d666bb3c526bec4b9be0736719a3b38a5
|
4
|
+
data.tar.gz: 3987011c8c53b930f369f76399b37194966bd170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35a314d950405db70775b44f8cb06617d5b4987d1f07e586069e19dcab525e761d71551019c53340b622733a8600de5ce238a44cf685854801696203cdda4d0
|
7
|
+
data.tar.gz: 3852368590562313ea46427efb3c41d1f414c9a379e522880d7af472807014350a109ab65c2ebe445dbbd6132cee531375e20bb0fd36a83eea425d4cf054d377
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## unreleased
|
4
|
+
|
5
|
+
## 5.0.1
|
6
|
+
|
7
|
+
* Fix failures array in transition not being reset [#383](https://github.com/aasm/aasm/issues/383)
|
8
|
+
* Enable AASM scopes to be defined on abstract classes.
|
9
|
+
|
3
10
|
## 5.0.0
|
4
11
|
|
5
12
|
* Chore(invokers): Refactor callback invokers, add class-callbacks support [#541](https://github.com/aasm/aasm/pull/541), thanks to [pandomic](https://github.com/pandomic)
|
6
13
|
* Add docker setup to readme
|
7
|
-
* Add support for Nobrainer (RethinkDB) [#522](https://github.com/aasm/aasm/pull/522), thanks to [zedtux]
|
14
|
+
* Add support for Nobrainer (RethinkDB) [#522](https://github.com/aasm/aasm/pull/522), thanks to [zedtux](https://github.com/zedtux)
|
8
15
|
* Patch `allow_event` to accept event with custom arguments [#419](https://github.com/aasm/aasm/pull/419), thanks to [czhc](https://github.com/czhc)
|
9
16
|
|
10
|
-
|
11
17
|
## 4.12.3
|
12
18
|
|
13
19
|
* Add to AASM fire(event) and fire!(event) methods [#494](https://github.com/aasm/aasm/pull/494), thanks to [slayer](https://github.com/slayer)
|
@@ -21,9 +27,9 @@
|
|
21
27
|
|
22
28
|
## 4.12.1
|
23
29
|
|
24
|
-
* DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking [#475](https://github.com/aasm/aasm/pull/475), thanks to [@Aryk]
|
25
|
-
* Add aliases for event methods [#476](https://github.com/aasm/aasm/pull/476), thanks to [@Aryk]
|
26
|
-
* Support Minitest spec expectations [#387](https://github.com/aasm/aasm/pull/387), thanks to [@faragorn]
|
30
|
+
* DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking [#475](https://github.com/aasm/aasm/pull/475), thanks to [@Aryk](https://github.com/Aryk)
|
31
|
+
* Add aliases for event methods [#476](https://github.com/aasm/aasm/pull/476), thanks to [@Aryk](https://github.com/Aryk)
|
32
|
+
* Support Minitest spec expectations [#387](https://github.com/aasm/aasm/pull/387), thanks to [@faragorn](https://github.com/faragorn)
|
27
33
|
## 4.12.0
|
28
34
|
|
29
35
|
* Fix thread safe issue with concurrent-ruby gem [see [pull-request #422](https://github.com/aasm/aasm/pull/442), thanks to [@reidmorrison](https://github.com/reidmorrison)
|
data/README.md
CHANGED
@@ -134,16 +134,6 @@ You can define a number of callbacks for your events, transitions and states. Th
|
|
134
134
|
called when certain criteria are met, like entering a particular state:
|
135
135
|
|
136
136
|
```ruby
|
137
|
-
class LogRunTime
|
138
|
-
def initialize(resource)
|
139
|
-
@resource = resource
|
140
|
-
end
|
141
|
-
|
142
|
-
def call
|
143
|
-
# Do whatever you want with @resource
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
137
|
class Job
|
148
138
|
include AASM
|
149
139
|
|
data/lib/aasm/core/event.rb
CHANGED
@@ -139,6 +139,7 @@ module AASM::Core
|
|
139
139
|
end
|
140
140
|
|
141
141
|
transitions.each do |transition|
|
142
|
+
transition.failures.clear #https://github.com/aasm/aasm/issues/383
|
142
143
|
next if to_state and !Array(transition.to).include?(to_state)
|
143
144
|
if (options.key?(:may_fire) && transition.eql?(options[:may_fire])) ||
|
144
145
|
(!options.key?(:may_fire) && transition.allowed?(obj, *args))
|
@@ -41,14 +41,15 @@ module AASM
|
|
41
41
|
|
42
42
|
module ClassMethods
|
43
43
|
def aasm_create_scope(state_machine_name, scope_name)
|
44
|
-
conditions = {
|
45
|
-
table_name => { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
46
|
-
}
|
47
44
|
if ActiveRecord::VERSION::MAJOR >= 3
|
45
|
+
conditions = { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
48
46
|
class_eval do
|
49
|
-
scope scope_name, lambda { where(conditions) }
|
47
|
+
scope scope_name, lambda { where(table_name => conditions) }
|
50
48
|
end
|
51
49
|
else
|
50
|
+
conditions = {
|
51
|
+
table_name => { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
52
|
+
}
|
52
53
|
class_eval do
|
53
54
|
named_scope scope_name, :conditions => conditions
|
54
55
|
end
|
data/lib/aasm/version.rb
CHANGED
data/spec/database.rb
CHANGED
@@ -11,6 +11,9 @@ ActiveRecord::Migration.suppress_messages do
|
|
11
11
|
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
|
12
12
|
t.string "status"
|
13
13
|
end
|
14
|
+
ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
|
15
|
+
t.string "status"
|
16
|
+
end
|
14
17
|
|
15
18
|
ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
|
16
19
|
t.string "left"
|
@@ -15,3 +15,18 @@ class MultipleSimpleNewDsl < ActiveRecord::Base
|
|
15
15
|
state :new
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
class AbstractClassDsl < ActiveRecord::Base
|
20
|
+
include AASM
|
21
|
+
|
22
|
+
self.abstract_class = true
|
23
|
+
|
24
|
+
aasm :column => :status
|
25
|
+
aasm do
|
26
|
+
state :unknown_scope, :another_unknown_scope
|
27
|
+
state :new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ImplementedAbstractClassDsl < AbstractClassDsl
|
32
|
+
end
|
@@ -49,7 +49,7 @@ describe 'callbacks for the new DSL' do
|
|
49
49
|
|
50
50
|
expect {
|
51
51
|
callback.left_close!
|
52
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:
|
52
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:event_guard].")
|
53
53
|
|
54
54
|
end
|
55
55
|
|
@@ -88,7 +88,7 @@ describe 'callbacks for the new DSL' do
|
|
88
88
|
|
89
89
|
expect {
|
90
90
|
callback.left_close!
|
91
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:
|
91
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'left_close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "does not run transition_guard twice for multiple permitted transitions" do
|
@@ -287,7 +287,7 @@ describe 'event callbacks' do
|
|
287
287
|
expect(@foo).to receive(:aasm_event_failed).with(:null, :open)
|
288
288
|
expect{
|
289
289
|
@foo.null
|
290
|
-
}.to raise_error(AASM::InvalidTransition, "Event 'null' cannot transition from 'open'. Failed callback(s): [:always_false
|
290
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'null' cannot transition from 'open'. Failed callback(s): [:always_false].")
|
291
291
|
end
|
292
292
|
|
293
293
|
it 'should not call it if persist fails for bang fire' do
|
@@ -333,6 +333,22 @@ if defined?(ActiveRecord)
|
|
333
333
|
end
|
334
334
|
end
|
335
335
|
|
336
|
+
# Scopes on abstract classes didn't work until Rails 5.
|
337
|
+
#
|
338
|
+
# Reference:
|
339
|
+
# https://github.com/rails/rails/issues/10658
|
340
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
341
|
+
context "For a descendant of an abstract model" do
|
342
|
+
it "should add the scope without the table_name" do
|
343
|
+
expect(ImplementedAbstractClassDsl).to respond_to(:unknown_scope)
|
344
|
+
expect(ImplementedAbstractClassDsl).to respond_to(:another_unknown_scope)
|
345
|
+
|
346
|
+
expect(ImplementedAbstractClassDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
|
347
|
+
expect(ImplementedAbstractClassDsl.another_unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
336
352
|
it "does not create scopes if requested" do
|
337
353
|
expect(NoScope).not_to respond_to(:pending)
|
338
354
|
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: 5.0.
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Boettger
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-07
|
12
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|