aasm 4.12.2 → 4.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/Gemfile.lock_old +151 -0
- data/LICENSE +1 -1
- data/README.md +117 -5
- data/lib/aasm/base.rb +3 -0
- data/lib/aasm/configuration.rb +3 -0
- data/lib/aasm/instance_base.rb +8 -0
- data/lib/aasm/persistence/orm.rb +9 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/database.rb +1 -1
- data/spec/models/active_record/transactor.rb +25 -0
- data/spec/unit/complex_example_spec.rb +10 -0
- data/spec/unit/complex_multiple_example_spec.rb +17 -1
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +1 -1
- data/spec/unit/persistence/active_record_persistence_spec.rb +15 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 485dd737c1e66c6abf9ad6beec5b88610e282cf5
|
4
|
+
data.tar.gz: dc4e4de44fbb182924bc28b13aff6708766f2cfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8211acf5c307b6c04b04ff0aad09aecece63d8df1fc6dbe3de14e363ab415a1e0291510b2d4783cf9cd22391415a25e4ac72d7f43f35ea612b60f939ab6def2a
|
7
|
+
data.tar.gz: a95bd160171a94dfc8ac1a4de0594372c336cf546f38727cacc95ca73af43369419bc6b3637634faa02b7eae6b8c668d29c5b74a5eb930aba4a03af190f8364a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
3
|
## unreleased
|
4
|
+
## 4.12.3
|
5
|
+
|
6
|
+
* Add to AASM fire(event) and fire!(event) methods [#494](https://github.com/aasm/aasm/pull/494), thanks to [slayer](https://github.com/slayer)
|
7
|
+
* Add `use_transactions` flag to persist changes to the database even when some error occurs. [#493](https://github.com/aasm/aasm/pull/493), thanks to Peter Lampesberger.
|
8
|
+
|
4
9
|
## 4.12.2
|
5
10
|
|
6
11
|
* Fix guards parameter [#484](https://github.com/aasm/aasm/pull/484), thanks to [teohm](https://github.com/teohm)
|
data/Gemfile
CHANGED
data/Gemfile.lock_old
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aasm (4.11.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (4.2.7.1)
|
10
|
+
actionpack (= 4.2.7.1)
|
11
|
+
actionview (= 4.2.7.1)
|
12
|
+
activejob (= 4.2.7.1)
|
13
|
+
mail (~> 2.5, >= 2.5.4)
|
14
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
15
|
+
actionpack (4.2.7.1)
|
16
|
+
actionview (= 4.2.7.1)
|
17
|
+
activesupport (= 4.2.7.1)
|
18
|
+
rack (~> 1.6)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
22
|
+
actionview (4.2.7.1)
|
23
|
+
activesupport (= 4.2.7.1)
|
24
|
+
builder (~> 3.1)
|
25
|
+
erubis (~> 2.7.0)
|
26
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
activejob (4.2.7.1)
|
29
|
+
activesupport (= 4.2.7.1)
|
30
|
+
globalid (>= 0.3.0)
|
31
|
+
activemodel (4.2.7.1)
|
32
|
+
activesupport (= 4.2.7.1)
|
33
|
+
builder (~> 3.1)
|
34
|
+
activerecord (4.2.7.1)
|
35
|
+
activemodel (= 4.2.7.1)
|
36
|
+
activesupport (= 4.2.7.1)
|
37
|
+
arel (~> 6.0)
|
38
|
+
activesupport (4.2.7.1)
|
39
|
+
i18n (~> 0.7)
|
40
|
+
json (~> 1.7, >= 1.7.7)
|
41
|
+
minitest (~> 5.1)
|
42
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
43
|
+
tzinfo (~> 1.1)
|
44
|
+
appraisal (2.1.0)
|
45
|
+
bundler
|
46
|
+
rake
|
47
|
+
thor (>= 0.14.0)
|
48
|
+
arel (6.0.4)
|
49
|
+
builder (3.2.3)
|
50
|
+
coderay (1.1.1)
|
51
|
+
concurrent-ruby (1.0.5)
|
52
|
+
diff-lcs (1.3)
|
53
|
+
erubis (2.7.0)
|
54
|
+
generator_spec (0.9.3)
|
55
|
+
activesupport (>= 3.0.0)
|
56
|
+
railties (>= 3.0.0)
|
57
|
+
globalid (0.3.7)
|
58
|
+
activesupport (>= 4.1.0)
|
59
|
+
i18n (0.8.1)
|
60
|
+
json (1.8.6)
|
61
|
+
loofah (2.0.3)
|
62
|
+
nokogiri (>= 1.5.9)
|
63
|
+
mail (2.6.4)
|
64
|
+
mime-types (>= 1.16, < 4)
|
65
|
+
method_source (0.8.2)
|
66
|
+
mime-types (3.1)
|
67
|
+
mime-types-data (~> 3.2015)
|
68
|
+
mime-types-data (3.2016.0521)
|
69
|
+
mini_portile2 (2.1.0)
|
70
|
+
minitest (5.10.1)
|
71
|
+
nokogiri (1.7.0.1)
|
72
|
+
mini_portile2 (~> 2.1.0)
|
73
|
+
pry (0.10.4)
|
74
|
+
coderay (~> 1.1.0)
|
75
|
+
method_source (~> 0.8.1)
|
76
|
+
slop (~> 3.4)
|
77
|
+
rack (1.6.5)
|
78
|
+
rack-test (0.6.3)
|
79
|
+
rack (>= 1.0)
|
80
|
+
rails (4.2.7.1)
|
81
|
+
actionmailer (= 4.2.7.1)
|
82
|
+
actionpack (= 4.2.7.1)
|
83
|
+
actionview (= 4.2.7.1)
|
84
|
+
activejob (= 4.2.7.1)
|
85
|
+
activemodel (= 4.2.7.1)
|
86
|
+
activerecord (= 4.2.7.1)
|
87
|
+
activesupport (= 4.2.7.1)
|
88
|
+
bundler (>= 1.3.0, < 2.0)
|
89
|
+
railties (= 4.2.7.1)
|
90
|
+
sprockets-rails
|
91
|
+
rails-deprecated_sanitizer (1.0.3)
|
92
|
+
activesupport (>= 4.2.0.alpha)
|
93
|
+
rails-dom-testing (1.0.8)
|
94
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
95
|
+
nokogiri (~> 1.6)
|
96
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
97
|
+
rails-html-sanitizer (1.0.3)
|
98
|
+
loofah (~> 2.0)
|
99
|
+
railties (4.2.7.1)
|
100
|
+
actionpack (= 4.2.7.1)
|
101
|
+
activesupport (= 4.2.7.1)
|
102
|
+
rake (>= 0.8.7)
|
103
|
+
thor (>= 0.18.1, < 2.0)
|
104
|
+
rake (12.0.0)
|
105
|
+
rdoc (4.3.0)
|
106
|
+
rspec (3.5.0)
|
107
|
+
rspec-core (~> 3.5.0)
|
108
|
+
rspec-expectations (~> 3.5.0)
|
109
|
+
rspec-mocks (~> 3.5.0)
|
110
|
+
rspec-core (3.5.4)
|
111
|
+
rspec-support (~> 3.5.0)
|
112
|
+
rspec-expectations (3.5.0)
|
113
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
114
|
+
rspec-support (~> 3.5.0)
|
115
|
+
rspec-mocks (3.5.0)
|
116
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
117
|
+
rspec-support (~> 3.5.0)
|
118
|
+
rspec-support (3.5.0)
|
119
|
+
sdoc (0.4.2)
|
120
|
+
json (~> 1.7, >= 1.7.7)
|
121
|
+
rdoc (~> 4.0)
|
122
|
+
slop (3.6.0)
|
123
|
+
sprockets (3.7.1)
|
124
|
+
concurrent-ruby (~> 1.0)
|
125
|
+
rack (> 1, < 3)
|
126
|
+
sprockets-rails (3.2.0)
|
127
|
+
actionpack (>= 4.0)
|
128
|
+
activesupport (>= 4.0)
|
129
|
+
sprockets (>= 3.0.0)
|
130
|
+
sqlite3 (1.3.13)
|
131
|
+
thor (0.19.4)
|
132
|
+
thread_safe (0.3.6)
|
133
|
+
tzinfo (1.2.2)
|
134
|
+
thread_safe (~> 0.1)
|
135
|
+
|
136
|
+
PLATFORMS
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
aasm!
|
141
|
+
appraisal
|
142
|
+
generator_spec
|
143
|
+
pry
|
144
|
+
rails (= 4.2.7.1)
|
145
|
+
rake
|
146
|
+
rspec (>= 3)
|
147
|
+
sdoc
|
148
|
+
sqlite3
|
149
|
+
|
150
|
+
BUNDLED WITH
|
151
|
+
1.12.4
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,50 @@
|
|
5
5
|
[![Dependency Status](https://gemnasium.com/aasm/aasm.svg)](https://gemnasium.com/aasm/aasm)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm)
|
7
7
|
|
8
|
+
## Index
|
9
|
+
- [Upgrade from version 3 to 4](#upgrade-from-version-3-to-4)
|
10
|
+
- [Usage](#usage)
|
11
|
+
- [Callbacks](#callbacks)
|
12
|
+
- [Lifecycle](#lifecycle)
|
13
|
+
- [The current event triggered](#the-current-event-triggered)
|
14
|
+
- [Guards](#guards)
|
15
|
+
- [Transitions](#transitions)
|
16
|
+
- [Multiple state machines per class](#multiple-state-machines-per-class)
|
17
|
+
- [Handling naming conflicts between multiple state machines](#handling-naming-conflicts-between-multiple-state-machines)
|
18
|
+
- [Binding event](#binding-event)
|
19
|
+
- [Auto-generated Status Constants](#auto-generated-status-constants)
|
20
|
+
- [Extending AASM](#extending-aasm)
|
21
|
+
- [ActiveRecord](#activerecord)
|
22
|
+
- [Bang events](#bang-events)
|
23
|
+
- [ActiveRecord enums](#activerecord-enums)
|
24
|
+
- [Sequel](#sequel)
|
25
|
+
- [Dynamoid](#dynamoid)
|
26
|
+
- [Mongoid](#mongoid)
|
27
|
+
- [Redis](#redis)
|
28
|
+
- [Automatic Scopes](#automatic-scopes)
|
29
|
+
- [Transaction support](#transaction-support)
|
30
|
+
- [Pessimistic Locking](#pessimistic-locking)
|
31
|
+
- [Column name & migration](#column-name--migration)
|
32
|
+
- [Inspection](#inspection)
|
33
|
+
- [Warning output](#warning-output)
|
34
|
+
- [RubyMotion support](#rubymotion-support)
|
35
|
+
- [Testing](#testing)
|
36
|
+
- [RSpec](#rspec)
|
37
|
+
- [Minitest](#minitest)
|
38
|
+
- [Assertions](#assertions)
|
39
|
+
- [Expectations](#expectations)
|
40
|
+
- [Installation](#installation)
|
41
|
+
- [Manually from RubyGems.org](#manually-from-rubygemsorg)
|
42
|
+
- [Bundler](#or-if-you-are-using-bundler)
|
43
|
+
- [Building your own gems](#building-your-own-gems)
|
44
|
+
- [Generators](#generators)
|
45
|
+
- [Latest changes](#latest-changes)
|
46
|
+
- [Questions?](#questions)
|
47
|
+
- [Maintainers](#maintainers)
|
48
|
+
- [Contributing](CONTRIBUTING.md)
|
49
|
+
- [Warranty](#warranty)
|
50
|
+
- [License](#license)
|
51
|
+
|
8
52
|
This package contains AASM, a library for adding finite state machines to Ruby classes.
|
9
53
|
|
10
54
|
AASM started as the *acts_as_state_machine* plugin but has evolved into a more generic library
|
@@ -282,7 +326,7 @@ class Cleaner
|
|
282
326
|
end
|
283
327
|
transitions :from => :idle, :to => :idle
|
284
328
|
end
|
285
|
-
|
329
|
+
|
286
330
|
event :clean_if_dirty do
|
287
331
|
transitions :from => :idle, :to => :cleaning, :guard => :if_dirty?
|
288
332
|
end
|
@@ -291,7 +335,7 @@ class Cleaner
|
|
291
335
|
def cleaning_needed?
|
292
336
|
false
|
293
337
|
end
|
294
|
-
|
338
|
+
|
295
339
|
def if_dirty?(status)
|
296
340
|
status == :dirty
|
297
341
|
end
|
@@ -425,10 +469,56 @@ simple.aasm(:work).current
|
|
425
469
|
|
426
470
|
```
|
427
471
|
|
428
|
-
|
429
|
-
|
472
|
+
#### Handling naming conflicts between multiple state machines
|
473
|
+
|
474
|
+
_AASM_ doesn't prohibit to define the same event in more than one state
|
475
|
+
machine. If no namespace is provided, the latest definition "wins" and
|
476
|
+
overrides previous definitions. Nonetheless, a warning is issued:
|
430
477
|
`SimpleMultipleExample: overriding method 'run'!`.
|
431
478
|
|
479
|
+
Alternatively, you can provide a namespace for each state machine:
|
480
|
+
|
481
|
+
```ruby
|
482
|
+
class NamespacedMultipleExample
|
483
|
+
include AASM
|
484
|
+
aasm(:status) do
|
485
|
+
state :unapproved, :initial => true
|
486
|
+
state :approved
|
487
|
+
|
488
|
+
event :approve do
|
489
|
+
transitions :from => :unapproved, :to => :approved
|
490
|
+
end
|
491
|
+
|
492
|
+
event :unapprove do
|
493
|
+
transitions :from => :approved, :to => :unapproved
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
aasm(:review_status, namespace: :review) do
|
498
|
+
state :unapproved, :initial => true
|
499
|
+
state :approved
|
500
|
+
|
501
|
+
event :approve do
|
502
|
+
transitions :from => :unapproved, :to => :approved
|
503
|
+
end
|
504
|
+
|
505
|
+
event :unapprove do
|
506
|
+
transitions :from => :approved, :to => :unapproved
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
namespaced = NamespacedMultipleExample.new
|
512
|
+
|
513
|
+
namespaced.aasm(:status).current_state
|
514
|
+
# => :unapproved
|
515
|
+
namespaced.aasm(:review_status).current_state
|
516
|
+
# => :unapproved
|
517
|
+
namespaced.approve_review
|
518
|
+
namespaced.aasm(:review_status).current_state
|
519
|
+
# => :approved
|
520
|
+
```
|
521
|
+
|
432
522
|
All _AASM_ class- and instance-level `aasm` methods accept a state machine selector.
|
433
523
|
So, for example, to use inspection on a class level, you have to use
|
434
524
|
|
@@ -599,6 +689,10 @@ You can tell AASM to auto-save the object or leave it unsaved
|
|
599
689
|
job = Job.new
|
600
690
|
job.run # not saved
|
601
691
|
job.run! # saved
|
692
|
+
|
693
|
+
# or
|
694
|
+
job.aasm.fire(:run) # not saved
|
695
|
+
job.aasm.fire!(:run) # saved
|
602
696
|
```
|
603
697
|
|
604
698
|
Saving includes running all validations on the `Job` class. If
|
@@ -867,6 +961,24 @@ end
|
|
867
961
|
|
868
962
|
which then leads to `transaction(:requires_new => false)`, the Rails default.
|
869
963
|
|
964
|
+
Additionally, if you do not want any of your active record actions to be
|
965
|
+
wrapped in a transaction, you can specify the `use_transactions` flag. This can
|
966
|
+
be useful if you want want to persist things to the database that happen as a
|
967
|
+
result of a transaction or callback, even when some error occurs. The
|
968
|
+
`use_transactions` flag is true by default.
|
969
|
+
|
970
|
+
```ruby
|
971
|
+
class Job < ActiveRecord::Base
|
972
|
+
include AASM
|
973
|
+
|
974
|
+
aasm :use_transactions => false do
|
975
|
+
...
|
976
|
+
end
|
977
|
+
|
978
|
+
...
|
979
|
+
end
|
980
|
+
```
|
981
|
+
|
870
982
|
### Pessimistic Locking
|
871
983
|
|
872
984
|
AASM supports [Active Record pessimistic locking via `with_lock`](http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html#method-i-with_lock) for database persistence layers.
|
@@ -1231,7 +1343,7 @@ purpose.
|
|
1231
1343
|
|
1232
1344
|
## License ##
|
1233
1345
|
|
1234
|
-
Copyright (c) 2006-
|
1346
|
+
Copyright (c) 2006-2017 Scott Barron
|
1235
1347
|
|
1236
1348
|
Permission is hereby granted, free of charge, to any person obtaining
|
1237
1349
|
a copy of this software and associated documentation files (the
|
data/lib/aasm/base.rb
CHANGED
@@ -26,6 +26,9 @@ module AASM
|
|
26
26
|
# raise if the model is invalid (in ActiveRecord)
|
27
27
|
configure :whiny_persistence, false
|
28
28
|
|
29
|
+
# Use transactions (in ActiveRecord)
|
30
|
+
configure :use_transactions, true
|
31
|
+
|
29
32
|
# use requires_new for nested transactions (in ActiveRecord)
|
30
33
|
configure :requires_new_transaction, true
|
31
34
|
|
data/lib/aasm/configuration.rb
CHANGED
@@ -15,6 +15,9 @@ module AASM
|
|
15
15
|
# for ActiveRecord: store the new state even if the model is invalid and return true
|
16
16
|
attr_accessor :skip_validation_on_save
|
17
17
|
|
18
|
+
# for ActiveRecord: use transactions
|
19
|
+
attr_accessor :use_transactions
|
20
|
+
|
18
21
|
# for ActiveRecord: use requires_new for nested transactions?
|
19
22
|
attr_accessor :requires_new_transaction
|
20
23
|
|
data/lib/aasm/instance_base.rb
CHANGED
@@ -103,6 +103,14 @@ module AASM
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
def fire(event_name, *args, &block)
|
107
|
+
@instance.send(:aasm_fire_event, @name, event_name, {persist: false}, *args, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
def fire!(event_name, *args, &block)
|
111
|
+
@instance.send(:aasm_fire_event, @name, event_name, {persist: true}, *args, &block)
|
112
|
+
end
|
113
|
+
|
106
114
|
def set_current_state_with_persistence(state)
|
107
115
|
save_success = @instance.aasm_write_state(state, @name)
|
108
116
|
self.current_state = state if save_success
|
data/lib/aasm/persistence/orm.rb
CHANGED
@@ -102,6 +102,10 @@ module AASM
|
|
102
102
|
AASM::StateMachineStore.fetch(self.class, true).machine(state_machine_name).config.skip_validation_on_save
|
103
103
|
end
|
104
104
|
|
105
|
+
def use_transactions?(state_machine_name)
|
106
|
+
AASM::StateMachineStore.fetch(self.class, true).machine(state_machine_name).config.use_transactions
|
107
|
+
end
|
108
|
+
|
105
109
|
def requires_new?(state_machine_name)
|
106
110
|
AASM::StateMachineStore.fetch(self.class, true).machine(state_machine_name).config.requires_new_transaction
|
107
111
|
end
|
@@ -118,7 +122,11 @@ module AASM
|
|
118
122
|
event.fire_global_callbacks(:before_all_transactions, self, *args)
|
119
123
|
|
120
124
|
begin
|
121
|
-
success =
|
125
|
+
success = if options[:persist] && use_transactions?(state_machine_name)
|
126
|
+
aasm_transaction(requires_new?(state_machine_name), requires_lock?(state_machine_name)) do
|
127
|
+
super
|
128
|
+
end
|
129
|
+
else
|
122
130
|
super
|
123
131
|
end
|
124
132
|
|
data/lib/aasm/version.rb
CHANGED
data/spec/database.rb
CHANGED
@@ -24,7 +24,7 @@ ActiveRecord::Migration.suppress_messages do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
%w(transactors no_lock_transactors lock_transactors lock_no_wait_transactors multiple_transactors).each do |table_name|
|
27
|
+
%w(transactors no_lock_transactors lock_transactors lock_no_wait_transactors no_transactors multiple_transactors).each do |table_name|
|
28
28
|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
29
29
|
t.string "name"
|
30
30
|
t.string "status"
|
@@ -72,6 +72,31 @@ class LockNoWaitTransactor < ActiveRecord::Base
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
class NoTransactor < ActiveRecord::Base
|
76
|
+
|
77
|
+
belongs_to :worker
|
78
|
+
|
79
|
+
include AASM
|
80
|
+
aasm :column => :status, use_transactions: false do
|
81
|
+
state :sleeping, :initial => true
|
82
|
+
state :running, :before_enter => :start_worker, :after_enter => :fail
|
83
|
+
|
84
|
+
event :run do
|
85
|
+
transitions :to => :running, :from => :sleeping
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def start_worker
|
92
|
+
worker.update_attribute(:status, 'running')
|
93
|
+
end
|
94
|
+
|
95
|
+
def fail
|
96
|
+
raise StandardError.new('failed on purpose')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
75
100
|
class MultipleTransactor < ActiveRecord::Base
|
76
101
|
|
77
102
|
belongs_to :worker
|
@@ -77,6 +77,16 @@ describe 'when being unsuspended' do
|
|
77
77
|
expect(auth.aasm.may_fire_event?(:activate)).to be true
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should be able to fire event by name" do
|
81
|
+
expect(auth.aasm.fire(:activate)).to be true
|
82
|
+
expect(auth.aasm.current_state).to eq(:active)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be able to fire! event by name" do
|
86
|
+
expect(auth.aasm.fire!(:activate)).to be true
|
87
|
+
expect(auth.aasm.current_state).to eq(:active)
|
88
|
+
end
|
89
|
+
|
80
90
|
it "should not be able to fire unknown events" do
|
81
91
|
expect(auth.aasm.may_fire_event?(:unknown)).to be false
|
82
92
|
end
|
@@ -91,9 +91,25 @@ describe 'when being unsuspended' do
|
|
91
91
|
expect(auth.aasm(:right).may_fire_event?(:right_activate)).to be true
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it 'should not be able to fire unknown events' do
|
95
95
|
expect(auth.aasm(:left).may_fire_event?(:unknown)).to be false
|
96
96
|
expect(auth.aasm(:right).may_fire_event?(:unknown)).to be false
|
97
97
|
end
|
98
98
|
|
99
|
+
it 'should be able to fire event by name' do
|
100
|
+
expect(auth.aasm(:left).fire(:left_activate)).to be true
|
101
|
+
expect(auth.aasm(:left).current_state).to eq(:active)
|
102
|
+
|
103
|
+
expect(auth.aasm(:right).fire(:right_activate)).to be true
|
104
|
+
expect(auth.aasm(:right).current_state).to eq(:active)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should be able to fire! event by name' do
|
108
|
+
expect(auth.aasm(:left).fire!(:left_activate)).to be true
|
109
|
+
expect(auth.aasm(:left).current_state).to eq(:active)
|
110
|
+
|
111
|
+
expect(auth.aasm(:right).fire!(:right_activate)).to be true
|
112
|
+
expect(auth.aasm(:right).current_state).to eq(:active)
|
113
|
+
end
|
114
|
+
|
99
115
|
end
|
@@ -123,7 +123,7 @@ if defined?(ActiveRecord)
|
|
123
123
|
let(:multiple_with_enum_without_column) {MultipleWithEnumWithoutColumn.new}
|
124
124
|
|
125
125
|
it "should raise NoMethodError for transitions" do
|
126
|
-
expect{multiple_with_enum_without_column.send(:view, :left)}.to raise_error(NoMethodError,
|
126
|
+
expect{multiple_with_enum_without_column.send(:view, :left)}.to raise_error(NoMethodError, /undefined method .status./)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -123,7 +123,7 @@ if defined?(ActiveRecord)
|
|
123
123
|
let(:with_enum_without_column) {WithEnumWithoutColumn.new}
|
124
124
|
|
125
125
|
it "should raise NoMethodError for transitions" do
|
126
|
-
expect{with_enum_without_column.send(:view)}.to raise_error(NoMethodError,
|
126
|
+
expect{with_enum_without_column.send(:view)}.to raise_error(NoMethodError, /undefined method .status./)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -506,6 +506,20 @@ if defined?(ActiveRecord)
|
|
506
506
|
end
|
507
507
|
end
|
508
508
|
|
509
|
+
describe 'without transactions' do
|
510
|
+
let(:worker) { Worker.create!(:name => 'worker', :status => 'sleeping') }
|
511
|
+
let(:no_transactor) { NoTransactor.create!(:name => 'transactor', :worker => worker) }
|
512
|
+
|
513
|
+
it 'should not rollback all changes' do
|
514
|
+
expect(no_transactor).to be_sleeping
|
515
|
+
expect(worker.status).to eq('sleeping')
|
516
|
+
|
517
|
+
expect {no_transactor.run!}.to raise_error(StandardError, 'failed on purpose')
|
518
|
+
expect(no_transactor).to be_running
|
519
|
+
expect(worker.reload.status).to eq('running')
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
509
523
|
describe 'transactions' do
|
510
524
|
let(:worker) { Worker.create!(:name => 'worker', :status => 'sleeping') }
|
511
525
|
let(:transactor) { Transactor.create!(:name => 'transactor', :worker => worker) }
|
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.12.
|
4
|
+
version: 4.12.3
|
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: 2017-
|
12
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- CODE_OF_CONDUCT.md
|
126
126
|
- CONTRIBUTING.md
|
127
127
|
- Gemfile
|
128
|
+
- Gemfile.lock_old
|
128
129
|
- HOWTO
|
129
130
|
- LICENSE
|
130
131
|
- PLANNED_CHANGES.md
|