aasm 5.0.8 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -7
- data/Appraisals +6 -10
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +18 -5
- data/aasm.gemspec +1 -1
- data/gemfiles/rails_4.2.gemfile +1 -0
- data/gemfiles/rails_4.2_mongoid_5.gemfile +1 -0
- data/gemfiles/rails_5.0.gemfile +1 -0
- data/gemfiles/rails_5.1.gemfile +1 -0
- data/gemfiles/rails_5.2.gemfile +1 -0
- data/lib/aasm/persistence/active_record_persistence.rb +13 -0
- data/lib/aasm/persistence/orm.rb +23 -19
- data/lib/aasm/version.rb +1 -1
- data/spec/database.rb +1 -1
- data/spec/models/active_record/active_record_callback.rb +93 -0
- data/spec/unit/persistence/active_record_persistence_spec.rb +67 -0
- metadata +16 -10
- data/callbacks.txt +0 -51
- data/gemfiles/rails_3.2.gemfile +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be8ee23b312066a6b90211161857cb2c461f20e9b1e3e93f955d6b8caeb6f497
|
4
|
+
data.tar.gz: 47c63523fc92f0fdc823024f632f27cab4453c4c2c9c7e277c45dea0f170250f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 258182cd645528de747eff39a70bcd697b5f965e49890ce369804aba0fb4c08739ff5259efef9cdde405b819765becb451ba4a6994f74dc89f0581c387d84ef1
|
7
|
+
data.tar.gz: 9408e99df7783505a8a67d4d54b0d5f3660b991790db7bad46598734ed33d1d7f1b5e463f67d435c0de15d0d1ef020023f8900781a72a40bcc85c35d76c8cf22
|
data/.travis.yml
CHANGED
@@ -27,7 +27,6 @@ services:
|
|
27
27
|
|
28
28
|
gemfile:
|
29
29
|
- gemfiles/norails.gemfile
|
30
|
-
- gemfiles/rails_3.2.gemfile
|
31
30
|
- gemfiles/rails_4.2.gemfile
|
32
31
|
- gemfiles/rails_4.2_mongoid_5.gemfile
|
33
32
|
# - gemfiles/rails_4.2_nobrainer.gemfile
|
@@ -62,12 +61,6 @@ matrix:
|
|
62
61
|
gemfile: gemfiles/rails_5.2.gemfile
|
63
62
|
- rvm: 2.6.5
|
64
63
|
gemfile: gemfiles/rails_5.2.gemfile
|
65
|
-
- rvm: 2.5.0
|
66
|
-
gemfile: gemfiles/rails_3.2.gemfile
|
67
|
-
- rvm: 2.6.5
|
68
|
-
gemfile: gemfiles/rails_3.2.gemfile
|
69
|
-
- rvm: 2.7.0
|
70
|
-
gemfile: gemfiles/rails_3.2.gemfile
|
71
64
|
- rvm: 2.5.0
|
72
65
|
gemfile: gemfiles/rails_4.2.gemfile
|
73
66
|
- rvm: 2.6.5
|
data/Appraisals
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
appraise 'rails_3.2' do
|
2
|
-
gem 'rails', '~> 3.2.22'
|
3
|
-
gem 'mongoid', '~> 3.1'
|
4
|
-
gem 'sequel'
|
5
|
-
gem 'bson_ext', platforms: :ruby
|
6
|
-
gem 'test-unit', '~> 3.0'
|
7
|
-
gem 'minitest'
|
8
|
-
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
9
|
-
end
|
10
|
-
|
11
1
|
appraise 'rails_4.2' do
|
12
2
|
gem 'nokogiri', '1.6.8.1', platforms: %i[ruby_19]
|
13
3
|
gem 'mime-types', '~> 2', platforms: %i[ruby_19 jruby]
|
@@ -18,6 +8,7 @@ appraise 'rails_4.2' do
|
|
18
8
|
gem 'aws-sdk', '~> 2', platforms: :ruby
|
19
9
|
gem 'redis-objects'
|
20
10
|
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
11
|
+
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
21
12
|
end
|
22
13
|
|
23
14
|
appraise 'rails_4.2_nobrainer' do
|
@@ -30,6 +21,7 @@ appraise 'rails_4.2_mongoid_5' do
|
|
30
21
|
gem 'rails', '4.2.5'
|
31
22
|
gem 'mongoid', '~> 5.0'
|
32
23
|
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
24
|
+
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
33
25
|
end
|
34
26
|
|
35
27
|
appraise 'rails_5.0' do
|
@@ -39,6 +31,7 @@ appraise 'rails_5.0' do
|
|
39
31
|
gem 'dynamoid', '~> 1.3', platforms: :ruby
|
40
32
|
gem 'aws-sdk', '~> 2', platforms: :ruby
|
41
33
|
gem 'redis-objects'
|
34
|
+
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
42
35
|
end
|
43
36
|
|
44
37
|
appraise 'rails_5.0_nobrainer' do
|
@@ -53,6 +46,7 @@ appraise 'rails_5.1' do
|
|
53
46
|
gem 'dynamoid', '~> 1.3', platforms: :ruby
|
54
47
|
gem 'aws-sdk', '~>2', platforms: :ruby
|
55
48
|
gem 'redis-objects'
|
49
|
+
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
56
50
|
end
|
57
51
|
|
58
52
|
appraise 'rails_5.2' do
|
@@ -62,9 +56,11 @@ appraise 'rails_5.2' do
|
|
62
56
|
gem 'dynamoid', '~>2.2', platforms: :ruby
|
63
57
|
gem 'aws-sdk', '~>2', platforms: :ruby
|
64
58
|
gem 'redis-objects'
|
59
|
+
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
65
60
|
end
|
66
61
|
|
67
62
|
appraise 'norails' do
|
63
|
+
gem 'sqlite3', '~> 1.3', '>= 1.3.5', platforms: :ruby
|
68
64
|
gem 'rails', install_if: false
|
69
65
|
gem 'sequel'
|
70
66
|
gem 'redis-objects'
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## unreleased
|
4
4
|
|
5
|
+
## 5.1.0
|
6
|
+
|
7
|
+
* Fix after_commit in nested transactions [#536](https://github.com/aasm/aasm/issues/536) without explicit AR dependency in PR [#668](https://github.com/aasm/aasm/pull/668), thanks to [stokarenko](https://github.com/stokarenko)
|
8
|
+
* Remove support for Rails 3.2
|
9
|
+
|
5
10
|
## 5.0.8
|
6
11
|
|
7
12
|
* Revert Fix for :after_commit within nested transaction because it adds after_commit_action dependency which is dependent on many gems.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -260,8 +260,8 @@ begin
|
|
260
260
|
new_state enter
|
261
261
|
...update state...
|
262
262
|
event before_success # if persist successful
|
263
|
-
transition success # if persist successful
|
264
|
-
event success # if persist successful
|
263
|
+
transition success # if persist successful, database update not guaranteed
|
264
|
+
event success # if persist successful, database update not guaranteed
|
265
265
|
old_state after_exit
|
266
266
|
new_state after_enter
|
267
267
|
event after
|
@@ -275,6 +275,8 @@ ensure
|
|
275
275
|
end
|
276
276
|
```
|
277
277
|
|
278
|
+
Use event's `after_commit` callback if it should be fired after database update.
|
279
|
+
|
278
280
|
#### The current event triggered
|
279
281
|
|
280
282
|
While running the callbacks you can easily retrieve the name of the event triggered
|
@@ -436,7 +438,7 @@ job.aasm.current_state # stage3
|
|
436
438
|
### Multiple state machines per class
|
437
439
|
|
438
440
|
Multiple state machines per class are supported. Be aware though that _AASM_ has been
|
439
|
-
built with one state machine per class in mind. Nonetheless, here's how to do it (see below). Please note that you will need to specify database columns for where your pertinent states will be stored - we have specified two columns `move_state` and `work_state` in the example below. See the [Column name & migration](https://github.com/aasm/aasm#column-name--migration) section for further info.
|
441
|
+
built with one state machine per class in mind. Nonetheless, here's how to do it (see below). Please note that you will need to specify database columns for where your pertinent states will be stored - we have specified two columns `move_state` and `work_state` in the example below. See the [Column name & migration](https://github.com/aasm/aasm#column-name--migration) section for further info.
|
440
442
|
|
441
443
|
```ruby
|
442
444
|
class SimpleMultipleExample
|
@@ -677,6 +679,8 @@ end
|
|
677
679
|
AASM comes with support for ActiveRecord and allows automatic persisting of the object's
|
678
680
|
state in the database.
|
679
681
|
|
682
|
+
Add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'` to your Gemfile
|
683
|
+
|
680
684
|
```ruby
|
681
685
|
class Job < ActiveRecord::Base
|
682
686
|
include AASM
|
@@ -981,6 +985,12 @@ job.run
|
|
981
985
|
job.save! #notify_about_running_job is not run
|
982
986
|
```
|
983
987
|
|
988
|
+
Please note that `:after_commit` AASM callbacks behaves around custom implementation
|
989
|
+
of transaction pattern rather than a real-life DB transaction. This fact still causes
|
990
|
+
the race conditions and redundant callback calls within nested transaction. In order
|
991
|
+
to fix that it's highly recommended to add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'`
|
992
|
+
to your `Gemfile`.
|
993
|
+
|
984
994
|
If you want to encapsulate state changes within an own transaction, the behavior
|
985
995
|
of this nested transaction might be confusing. Take a look at
|
986
996
|
[ActiveRecord Nested Transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html)
|
@@ -1076,7 +1086,10 @@ end
|
|
1076
1086
|
```
|
1077
1087
|
|
1078
1088
|
Whatever column name is used, make sure to add a migration to provide this column
|
1079
|
-
(of type `string`)
|
1089
|
+
(of type `string`).
|
1090
|
+
Do not add default value for column at the database level. If you add default
|
1091
|
+
value in database then AASM callbacks on the initial state will not be fired upon
|
1092
|
+
instantiation of the model.
|
1080
1093
|
|
1081
1094
|
```ruby
|
1082
1095
|
class AddJobState < ActiveRecord::Migration
|
@@ -1092,7 +1105,7 @@ end
|
|
1092
1105
|
|
1093
1106
|
### Log State Changes
|
1094
1107
|
|
1095
|
-
Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
|
1108
|
+
Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
|
1096
1109
|
|
1097
1110
|
Example of implementation can be found here [https://github.com/nitsujri/aasm-papertrail-example](https://github.com/nitsujri/aasm-papertrail-example)
|
1098
1111
|
|
data/aasm.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'generator_spec'
|
25
25
|
s.add_development_dependency 'appraisal'
|
26
26
|
s.add_development_dependency "simplecov"
|
27
|
-
s.add_development_dependency "codecov", ">= 0.1.
|
27
|
+
s.add_development_dependency "codecov", ">= 0.1.17", '< 0.1.20'
|
28
28
|
|
29
29
|
# debugging
|
30
30
|
# s.add_development_dependency 'debugger'
|
data/gemfiles/rails_4.2.gemfile
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/gemfiles/rails_5.2.gemfile
CHANGED
@@ -28,6 +28,19 @@ module AASM
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
def self.included(base)
|
31
|
+
begin
|
32
|
+
require 'after_commit_everywhere'
|
33
|
+
raise LoadError unless Gem::Version.new(::AfterCommitEverywhere::VERSION) >= Gem::Version.new('0.1.5')
|
34
|
+
|
35
|
+
base.send(:include, ::AfterCommitEverywhere) unless base.include?(::AfterCommitEverywhere)
|
36
|
+
base.send(:alias_method, :aasm_execute_after_commit, :after_commit)
|
37
|
+
rescue LoadError
|
38
|
+
warn <<-MSG
|
39
|
+
[DEPRECATION] :after_commit AASM callback is not safe in terms of race conditions and redundant calls.
|
40
|
+
Please add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'` to your Gemfile in order to fix that.
|
41
|
+
MSG
|
42
|
+
end
|
43
|
+
|
31
44
|
base.send(:include, AASM::Persistence::Base)
|
32
45
|
base.send(:include, AASM::Persistence::ORM)
|
33
46
|
base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
data/lib/aasm/persistence/orm.rb
CHANGED
@@ -81,6 +81,10 @@ module AASM
|
|
81
81
|
true
|
82
82
|
end
|
83
83
|
|
84
|
+
def aasm_execute_after_commit
|
85
|
+
yield
|
86
|
+
end
|
87
|
+
|
84
88
|
def aasm_write_state_attribute(state, name=:default)
|
85
89
|
aasm_write_attribute(self.class.aasm(name).attribute_name, aasm_raw_attribute_value(state, name))
|
86
90
|
end
|
@@ -116,32 +120,32 @@ module AASM
|
|
116
120
|
|
117
121
|
# Returns true if event was fired successfully and transaction completed.
|
118
122
|
def aasm_fire_event(state_machine_name, name, options, *args, &block)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
else
|
123
|
+
return super unless aasm_supports_transactions? && options[:persist]
|
124
|
+
|
125
|
+
event = self.class.aasm(state_machine_name).state_machine.events[name]
|
126
|
+
event.fire_callbacks(:before_transaction, self, *args)
|
127
|
+
event.fire_global_callbacks(:before_all_transactions, self, *args)
|
128
|
+
|
129
|
+
begin
|
130
|
+
success = if options[:persist] && use_transactions?(state_machine_name)
|
131
|
+
aasm_transaction(requires_new?(state_machine_name), requires_lock?(state_machine_name)) do
|
130
132
|
super
|
131
133
|
end
|
134
|
+
else
|
135
|
+
super
|
136
|
+
end
|
132
137
|
|
133
|
-
|
138
|
+
if success
|
139
|
+
aasm_execute_after_commit do
|
134
140
|
event.fire_callbacks(:after_commit, self, *args)
|
135
141
|
event.fire_global_callbacks(:after_all_commits, self, *args)
|
136
142
|
end
|
137
|
-
|
138
|
-
success
|
139
|
-
ensure
|
140
|
-
event.fire_callbacks(:after_transaction, self, *args)
|
141
|
-
event.fire_global_callbacks(:after_all_transactions, self, *args)
|
142
143
|
end
|
143
|
-
|
144
|
-
|
144
|
+
|
145
|
+
success
|
146
|
+
ensure
|
147
|
+
event.fire_callbacks(:after_transaction, self, *args)
|
148
|
+
event.fire_global_callbacks(:after_all_transactions, self, *args)
|
145
149
|
end
|
146
150
|
end
|
147
151
|
|
data/lib/aasm/version.rb
CHANGED
data/spec/database.rb
CHANGED
@@ -27,7 +27,7 @@ ActiveRecord::Migration.suppress_messages do
|
|
27
27
|
t.string "status"
|
28
28
|
end
|
29
29
|
|
30
|
-
%w(validators multiple_validators workers invalid_persistors multiple_invalid_persistors silent_persistors multiple_silent_persistors).each do |table_name|
|
30
|
+
%w(validators multiple_validators workers invalid_persistors multiple_invalid_persistors silent_persistors multiple_silent_persistors active_record_callbacks).each do |table_name|
|
31
31
|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
32
32
|
t.string "name"
|
33
33
|
t.string "status"
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class ActiveRecordCallback < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
def reset_data
|
5
|
+
@data = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def data
|
9
|
+
@data.join(' ')
|
10
|
+
end
|
11
|
+
|
12
|
+
aasm column: :status do
|
13
|
+
before_all_events :before_all_events
|
14
|
+
after_all_events :after_all_events
|
15
|
+
ensure_on_all_events :ensure_on_all_events
|
16
|
+
after_all_transitions :after_all_transitions
|
17
|
+
|
18
|
+
state :open, :initial => true,
|
19
|
+
:before_enter => :before_enter_open,
|
20
|
+
:enter => :enter_open,
|
21
|
+
:after_enter => :after_enter_open,
|
22
|
+
:before_exit => :before_exit_open,
|
23
|
+
:exit => :exit_open,
|
24
|
+
:after_exit => :after_exit_open
|
25
|
+
|
26
|
+
state :closed,
|
27
|
+
:before_enter => :before_enter_closed,
|
28
|
+
:enter => :enter_closed,
|
29
|
+
:after_enter => :after_enter_closed,
|
30
|
+
:before_exit => :before_exit_closed,
|
31
|
+
:exit => :exit_closed,
|
32
|
+
:after_exit => :after_exit_closed
|
33
|
+
|
34
|
+
event :close,
|
35
|
+
:before => :before_event,
|
36
|
+
:after => :after_event,
|
37
|
+
:guard => :event_guard,
|
38
|
+
:before_success => :event_before_success,
|
39
|
+
:after_commit => :event_after_commit,
|
40
|
+
:ensure => :ensure_event do
|
41
|
+
transitions :to => :closed, :from => [:open],
|
42
|
+
:guard => :transition_guard,
|
43
|
+
:after => :after_transition,
|
44
|
+
:success => :success_transition
|
45
|
+
end
|
46
|
+
|
47
|
+
event :open, :before => :before_event, :after => :after_event do
|
48
|
+
transitions :to => :open, :from => :closed
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def log(text)
|
53
|
+
@data ||= []
|
54
|
+
@data << text
|
55
|
+
#puts text
|
56
|
+
end
|
57
|
+
|
58
|
+
def aasm_write_state(*args); log('aasm_write_state'); true; end
|
59
|
+
def before_enter_open; log('before_enter_open'); end
|
60
|
+
def enter_open; log('enter_open'); end
|
61
|
+
def before_exit_open; log('before_exit_open'); end
|
62
|
+
def after_enter_open; log('after_enter_open'); end
|
63
|
+
def exit_open; log('exit_open'); end
|
64
|
+
def after_exit_open; log('after_exit_open'); end
|
65
|
+
|
66
|
+
def before_enter_closed; log('before_enter_closed'); end
|
67
|
+
def enter_closed; log('enter_closed'); end
|
68
|
+
def before_exit_closed; log('before_exit_closed'); end
|
69
|
+
def exit_closed; log('exit_closed'); end
|
70
|
+
def after_enter_closed; log('after_enter_closed'); end
|
71
|
+
def after_exit_closed; log('after_exit_closed'); end
|
72
|
+
|
73
|
+
def event_guard; log('event_guard'); !@fail_event_guard; end
|
74
|
+
def transition_guard; log('transition_guard'); !@fail_transition_guard; end
|
75
|
+
|
76
|
+
def event_before_success; log('event_before_success'); end
|
77
|
+
|
78
|
+
def after_transition; log('after_transition'); end
|
79
|
+
def after_all_transitions; log('after_all_transitions'); end
|
80
|
+
|
81
|
+
def before_all_events; log('before_all_events') end
|
82
|
+
def before_event; log('before_event'); end
|
83
|
+
def after_event; log('after_event'); end
|
84
|
+
def after_all_events; log('after_all_events'); end
|
85
|
+
|
86
|
+
def after_transition; log('after_transition'); end
|
87
|
+
def success_transition; log('transition_success'); end
|
88
|
+
|
89
|
+
def ensure_event; log('ensure'); end
|
90
|
+
def ensure_on_all_events; log('ensure'); end
|
91
|
+
|
92
|
+
def event_after_commit; log('after_commit'); end
|
93
|
+
end
|
@@ -613,6 +613,73 @@ if defined?(ActiveRecord)
|
|
613
613
|
expect(validator).to be_running
|
614
614
|
expect(validator.name).to eq("name")
|
615
615
|
end
|
616
|
+
|
617
|
+
context "nested transaction" do
|
618
|
+
it "should fire :after_commit if root transaction was successful" do
|
619
|
+
validator = Validator.create(:name => 'name')
|
620
|
+
expect(validator).to be_sleeping
|
621
|
+
|
622
|
+
validator.transaction do
|
623
|
+
validator.run!
|
624
|
+
expect(validator.name).to eq("name")
|
625
|
+
expect(validator).to be_running
|
626
|
+
end
|
627
|
+
|
628
|
+
expect(validator.name).to eq("name changed")
|
629
|
+
expect(validator.reload).to be_running
|
630
|
+
end
|
631
|
+
|
632
|
+
it "should not fire :after_commit if root transaction failed" do
|
633
|
+
validator = Validator.create(:name => 'name')
|
634
|
+
expect(validator).to be_sleeping
|
635
|
+
|
636
|
+
validator.transaction do
|
637
|
+
validator.run!
|
638
|
+
expect(validator.name).to eq("name")
|
639
|
+
expect(validator).to be_running
|
640
|
+
|
641
|
+
raise ActiveRecord::Rollback, "failed on purpose"
|
642
|
+
end
|
643
|
+
|
644
|
+
expect(validator.name).to eq("name")
|
645
|
+
expect(validator.reload).to be_sleeping
|
646
|
+
end
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
describe 'callbacks for the new DSL' do
|
651
|
+
|
652
|
+
it "be called in order" do
|
653
|
+
show_debug_log = false
|
654
|
+
|
655
|
+
callback = ActiveRecordCallback.create
|
656
|
+
callback.aasm.current_state
|
657
|
+
|
658
|
+
unless show_debug_log
|
659
|
+
expect(callback).to receive(:before_all_events).once.ordered
|
660
|
+
expect(callback).to receive(:before_event).once.ordered
|
661
|
+
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
662
|
+
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
663
|
+
expect(callback).to receive(:before_exit_open).once.ordered # these should be before the state changes
|
664
|
+
expect(callback).to receive(:exit_open).once.ordered
|
665
|
+
# expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
666
|
+
# expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
667
|
+
expect(callback).to receive(:after_all_transitions).once.ordered
|
668
|
+
expect(callback).to receive(:after_transition).once.ordered
|
669
|
+
expect(callback).to receive(:before_enter_closed).once.ordered
|
670
|
+
expect(callback).to receive(:enter_closed).once.ordered
|
671
|
+
expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
672
|
+
expect(callback).to receive(:after_exit_open).once.ordered # these should be after the state changes
|
673
|
+
expect(callback).to receive(:after_enter_closed).once.ordered
|
674
|
+
expect(callback).to receive(:after_event).once.ordered
|
675
|
+
expect(callback).to receive(:after_all_events).once.ordered
|
676
|
+
expect(callback).to receive(:ensure_event).once.ordered
|
677
|
+
expect(callback).to receive(:ensure_on_all_events).once.ordered
|
678
|
+
expect(callback).to receive(:event_after_commit).once.ordered
|
679
|
+
end
|
680
|
+
|
681
|
+
callback.close!
|
682
|
+
end
|
616
683
|
end
|
617
684
|
|
618
685
|
describe 'before and after transaction callbacks' do
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Boettger
|
8
8
|
- Anil Maurya
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -115,14 +115,20 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.1.
|
118
|
+
version: 0.1.17
|
119
|
+
- - "<"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.1.20
|
119
122
|
type: :development
|
120
123
|
prerelease: false
|
121
124
|
version_requirements: !ruby/object:Gem::Requirement
|
122
125
|
requirements:
|
123
126
|
- - ">="
|
124
127
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.1.
|
128
|
+
version: 0.1.17
|
129
|
+
- - "<"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.20
|
126
132
|
- !ruby/object:Gem::Dependency
|
127
133
|
name: pry
|
128
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,10 +171,8 @@ files:
|
|
165
171
|
- Rakefile
|
166
172
|
- TESTING.md
|
167
173
|
- aasm.gemspec
|
168
|
-
- callbacks.txt
|
169
174
|
- docker-compose.yml
|
170
175
|
- gemfiles/norails.gemfile
|
171
|
-
- gemfiles/rails_3.2.gemfile
|
172
176
|
- gemfiles/rails_4.2.gemfile
|
173
177
|
- gemfiles/rails_4.2_mongoid_5.gemfile
|
174
178
|
- gemfiles/rails_4.2_nobrainer.gemfile
|
@@ -232,6 +236,7 @@ files:
|
|
232
236
|
- spec/generators/active_record_generator_spec.rb
|
233
237
|
- spec/generators/mongoid_generator_spec.rb
|
234
238
|
- spec/generators/no_brainer_generator_spec.rb
|
239
|
+
- spec/models/active_record/active_record_callback.rb
|
235
240
|
- spec/models/active_record/basic_active_record_two_state_machines_example.rb
|
236
241
|
- spec/models/active_record/complex_active_record_example.rb
|
237
242
|
- spec/models/active_record/derivate_new_dsl.rb
|
@@ -408,7 +413,7 @@ homepage: https://github.com/aasm/aasm
|
|
408
413
|
licenses:
|
409
414
|
- MIT
|
410
415
|
metadata: {}
|
411
|
-
post_install_message:
|
416
|
+
post_install_message:
|
412
417
|
rdoc_options: []
|
413
418
|
require_paths:
|
414
419
|
- lib
|
@@ -423,8 +428,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
423
428
|
- !ruby/object:Gem::Version
|
424
429
|
version: '0'
|
425
430
|
requirements: []
|
426
|
-
rubygems_version: 3.
|
427
|
-
signing_key:
|
431
|
+
rubygems_version: 3.0.3
|
432
|
+
signing_key:
|
428
433
|
specification_version: 4
|
429
434
|
summary: State machine mixin for Ruby objects
|
430
435
|
test_files:
|
@@ -435,6 +440,7 @@ test_files:
|
|
435
440
|
- spec/generators/active_record_generator_spec.rb
|
436
441
|
- spec/generators/mongoid_generator_spec.rb
|
437
442
|
- spec/generators/no_brainer_generator_spec.rb
|
443
|
+
- spec/models/active_record/active_record_callback.rb
|
438
444
|
- spec/models/active_record/basic_active_record_two_state_machines_example.rb
|
439
445
|
- spec/models/active_record/complex_active_record_example.rb
|
440
446
|
- spec/models/active_record/derivate_new_dsl.rb
|
data/callbacks.txt
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
callbacks
|
2
|
-
|
3
|
-
AASM 3
|
4
|
-
|
5
|
-
begin
|
6
|
-
old_state exit # old? should be deprecated -> use old_state.before_exit instead
|
7
|
-
event before
|
8
|
-
old_state before_exit
|
9
|
-
new_state before_enter
|
10
|
-
new_state enter # old? should be deprecated -> use new_state.before_enter instead
|
11
|
-
...update state...
|
12
|
-
transition guard
|
13
|
-
event guard
|
14
|
-
transition on_transition
|
15
|
-
event success # if persist successful
|
16
|
-
old_state after_exit
|
17
|
-
new_state after_enter
|
18
|
-
event after
|
19
|
-
rescue
|
20
|
-
event error
|
21
|
-
end
|
22
|
-
|
23
|
-
AASM 4
|
24
|
-
|
25
|
-
todo
|
26
|
-
|
27
|
-
done
|
28
|
-
- move event.before before everything else
|
29
|
-
- move old_state.before_exit before old_state.exit
|
30
|
-
- move event.guard before transition.guard
|
31
|
-
- fire guards before running state callbacks (test run)
|
32
|
-
|
33
|
-
begin
|
34
|
-
event before
|
35
|
-
event guard # test run
|
36
|
-
transition guard # test run
|
37
|
-
old_state before_exit
|
38
|
-
old_state exit
|
39
|
-
new_state before_enter
|
40
|
-
new_state enter
|
41
|
-
event guard
|
42
|
-
transition guard
|
43
|
-
transition on_transition
|
44
|
-
...update state...
|
45
|
-
event success # if persist successful
|
46
|
-
old_state after_exit
|
47
|
-
new_state after_enter
|
48
|
-
event after
|
49
|
-
rescue
|
50
|
-
event error
|
51
|
-
end
|
data/gemfiles/rails_3.2.gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "~> 3.2.22"
|
7
|
-
gem "mongoid", "~> 3.1"
|
8
|
-
gem "sequel"
|
9
|
-
gem "bson_ext", platforms: :ruby
|
10
|
-
gem "test-unit", "~> 3.0"
|
11
|
-
gem "minitest"
|
12
|
-
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
13
|
-
|
14
|
-
gemspec path: "../"
|