aasm 5.0.1 → 5.0.6

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.travis.yml +41 -13
  5. data/Appraisals +18 -13
  6. data/CHANGELOG.md +37 -0
  7. data/Gemfile +1 -1
  8. data/README.md +132 -92
  9. data/aasm.gemspec +2 -0
  10. data/gemfiles/norails.gemfile +10 -0
  11. data/gemfiles/rails_3.2.gemfile +2 -1
  12. data/gemfiles/rails_4.2.gemfile +1 -1
  13. data/gemfiles/rails_4.2_mongoid_5.gemfile +1 -1
  14. data/gemfiles/rails_4.2_nobrainer.gemfile +1 -1
  15. data/gemfiles/rails_5.0.gemfile +2 -2
  16. data/gemfiles/rails_5.0_nobrainer.gemfile +1 -1
  17. data/gemfiles/rails_5.1.gemfile +2 -2
  18. data/gemfiles/rails_5.2.gemfile +13 -0
  19. data/lib/aasm/aasm.rb +29 -27
  20. data/lib/aasm/base.rb +25 -7
  21. data/lib/aasm/core/event.rb +9 -4
  22. data/lib/aasm/errors.rb +2 -1
  23. data/lib/aasm/instance_base.rb +4 -3
  24. data/lib/aasm/persistence/active_record_persistence.rb +2 -1
  25. data/lib/aasm/persistence/base.rb +1 -1
  26. data/lib/aasm/persistence/core_data_query_persistence.rb +2 -1
  27. data/lib/aasm/persistence/dynamoid_persistence.rb +1 -1
  28. data/lib/aasm/persistence/mongoid_persistence.rb +1 -1
  29. data/lib/aasm/persistence/no_brainer_persistence.rb +1 -1
  30. data/lib/aasm/persistence/redis_persistence.rb +1 -1
  31. data/lib/aasm/version.rb +1 -1
  32. data/lib/generators/aasm/orm_helpers.rb +6 -0
  33. data/lib/generators/active_record/aasm_generator.rb +3 -1
  34. data/spec/database.rb +12 -0
  35. data/spec/generators/active_record_generator_spec.rb +6 -0
  36. data/spec/models/active_record/instance_level_skip_validation_example.rb +19 -0
  37. data/spec/models/active_record/person.rb +23 -0
  38. data/spec/models/active_record/work.rb +3 -0
  39. data/spec/models/callbacks/with_state_arg.rb +5 -1
  40. data/spec/models/callbacks/with_state_arg_multiple.rb +4 -1
  41. data/spec/spec_helper.rb +10 -0
  42. data/spec/unit/abstract_class_spec.rb +27 -0
  43. data/spec/unit/callback_multiple_spec.rb +4 -0
  44. data/spec/unit/callbacks_spec.rb +30 -0
  45. data/spec/unit/complex_example_spec.rb +0 -1
  46. data/spec/unit/event_spec.rb +13 -0
  47. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +4 -4
  48. data/spec/unit/persistence/active_record_persistence_spec.rb +26 -4
  49. metadata +42 -3
  50. data/gemfiles/rails_4.0.gemfile +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea455b8d666bb3c526bec4b9be0736719a3b38a5
4
- data.tar.gz: 3987011c8c53b930f369f76399b37194966bd170
3
+ metadata.gz: 51dfd1ad2a78034c409ddc556625e765260dd067
4
+ data.tar.gz: f934e43d4a35fc75a06d161190a8794e36066c02
5
5
  SHA512:
6
- metadata.gz: b35a314d950405db70775b44f8cb06617d5b4987d1f07e586069e19dcab525e761d71551019c53340b622733a8600de5ce238a44cf685854801696203cdda4d0
7
- data.tar.gz: 3852368590562313ea46427efb3c41d1f414c9a379e522880d7af472807014350a109ab65c2ebe445dbbd6132cee531375e20bb0fd36a83eea425d4cf054d377
6
+ metadata.gz: 983b08a4a0977c37dd73b77c5d80d014a05025d7f2841c26788518c82a8e738825ab9fa5fc8a36577e9c6a23fd33cf341c6fefc954630836e213ab40ee12c909
7
+ data.tar.gz: b091bca286362fb33a31f1b9705840f664ebd0a948c6b2dffbaa2436144c5931a04950080b18e16c1a7d9e4e1b8f517b7ea6c2c133259a3860905928fda32b90
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Additional context**
27
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -2,27 +2,37 @@ sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
4
 
5
+ jdk:
6
+ - openjdk8
7
+
8
+ before_install:
9
+ - rvm list
10
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
11
+ - gem install bundler -v '1.16.1'
12
+ - bundle _1.16.1_ install
13
+
5
14
  rvm:
6
- - 2.2.6
7
- - 2.3.3
15
+ - 2.3.0
16
+ - 2.5.0
8
17
  - jruby-9.1.12.0
9
18
 
10
19
  services:
11
20
  - mongodb
12
21
  - redis-server
13
22
 
14
- addons:
15
- rethinkdb: '2.3.6'
23
+ #addons:
24
+ # rethinkdb: '2.3.4'
16
25
 
17
26
  gemfile:
27
+ - gemfiles/norails.gemfile
18
28
  - gemfiles/rails_3.2.gemfile
19
- - gemfiles/rails_4.0.gemfile
20
29
  - gemfiles/rails_4.2.gemfile
21
30
  - gemfiles/rails_4.2_mongoid_5.gemfile
22
- - gemfiles/rails_4.2_nobrainer.gemfile
31
+ # - gemfiles/rails_4.2_nobrainer.gemfile
23
32
  - gemfiles/rails_5.0.gemfile
24
- - gemfiles/rails_5.0_nobrainer.gemfile
33
+ # - gemfiles/rails_5.0_nobrainer.gemfile
25
34
  - gemfiles/rails_5.1.gemfile
35
+ - gemfiles/rails_5.2.gemfile
26
36
 
27
37
  before_script:
28
38
  - mkdir /tmp/dynamodb
@@ -36,18 +46,36 @@ script:
36
46
 
37
47
  matrix:
38
48
  exclude:
39
- - rvm: 2.2.6
40
- gemfile: gemfiles/rails_3.2.gemfile
41
- - rvm: 2.3.3
49
+ - rvm: 2.3.0
50
+ gemfile: gemfiles/norails.gemfile
51
+ - rvm: 2.3.0
52
+ gemfile: gemfiles/rails_5.0.gemfile
53
+ # - rvm: 2.3.0
54
+ # gemfile: gemfiles/rails_5.0_nobrainer.gemfile
55
+ - rvm: 2.3.0
56
+ gemfile: gemfiles/rails_5.1.gemfile
57
+ - rvm: 2.3.0
58
+ gemfile: gemfiles/rails_5.2.gemfile
59
+ - rvm: 2.5.0
42
60
  gemfile: gemfiles/rails_3.2.gemfile
61
+ - rvm: 2.5.0
62
+ gemfile: gemfiles/rails_4.2.gemfile
63
+ - rvm: 2.5.0
64
+ gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
65
+ # - rvm: 2.5.0
66
+ # gemfile: gemfiles/rails_4.2_nobrainer.gemfile
67
+ - rvm: jruby-9.1.12.0
68
+ gemfile: gemfiles/norails.gemfile
43
69
  - rvm: jruby-9.1.12.0
44
70
  gemfile: gemfiles/rails_5.0.gemfile
45
71
  - rvm: jruby-9.1.12.0
46
72
  gemfile: gemfiles/rails_5.1.gemfile
47
73
  - rvm: jruby-9.1.12.0
48
- gemfile: gemfiles/rails_4.2_nobrainer.gemfile
49
- - rvm: jruby-9.1.12.0
50
- gemfile: gemfiles/rails_5.0_nobrainer.gemfile
74
+ gemfile: gemfiles/rails_5.2.gemfile
75
+ # - rvm: jruby-9.1.12.0
76
+ # gemfile: gemfiles/rails_4.2_nobrainer.gemfile
77
+ # - rvm: jruby-9.1.12.0
78
+ # gemfile: gemfiles/rails_5.0_nobrainer.gemfile
51
79
 
52
80
  notifications:
53
81
  slack:
data/Appraisals CHANGED
@@ -4,17 +4,7 @@ appraise 'rails_3.2' do
4
4
  gem 'sequel'
5
5
  gem 'bson_ext', platforms: :ruby
6
6
  gem 'test-unit', '~> 3.0'
7
- gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
8
- end
9
-
10
- appraise 'rails_4.0' do
11
- gem 'mime-types', '~> 2', platforms: %i[ruby_19 jruby]
12
- gem 'rails', '4.0.13'
13
- gem 'mongoid', '~> 4.0'
14
- gem 'sequel'
15
- gem 'dynamoid', '~> 1', platforms: :ruby
16
- gem 'aws-sdk', '~> 2', platforms: :ruby
17
- gem 'redis-objects'
7
+ gem 'minitest'
18
8
  gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
19
9
  end
20
10
 
@@ -46,7 +36,7 @@ appraise 'rails_5.0' do
46
36
  gem 'rails', '5.0.0'
47
37
  gem 'mongoid', '~> 6.0'
48
38
  gem 'sequel'
49
- gem 'dynamoid', '~> 1', platforms: :ruby
39
+ gem 'dynamoid', '~> 1.3', platforms: :ruby
50
40
  gem 'aws-sdk', '~> 2', platforms: :ruby
51
41
  gem 'redis-objects'
52
42
  end
@@ -60,7 +50,22 @@ appraise 'rails_5.1' do
60
50
  gem 'rails', '5.1'
61
51
  gem 'mongoid', '~>6.0'
62
52
  gem 'sequel'
63
- gem 'dynamoid', '~> 1', platforms: :ruby
53
+ gem 'dynamoid', '~> 1.3', platforms: :ruby
64
54
  gem 'aws-sdk', '~>2', platforms: :ruby
65
55
  gem 'redis-objects'
66
56
  end
57
+
58
+ appraise 'rails_5.2' do
59
+ gem 'rails', '5.2'
60
+ gem 'mongoid', '~>6.0'
61
+ gem 'sequel'
62
+ gem 'dynamoid', '~>2.2', platforms: :ruby
63
+ gem 'aws-sdk', '~>2', platforms: :ruby
64
+ gem 'redis-objects'
65
+ end
66
+
67
+ appraise 'norails' do
68
+ gem 'rails', install_if: false
69
+ gem 'sequel'
70
+ gem 'redis-objects'
71
+ end
@@ -2,6 +2,43 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## 5.0.6
6
+
7
+ * Fix no_direct_assignment, couldn't be turned off pragmatically [#636](https://github.com/aasm/aasm/issues/636)
8
+ * Add instance level validation skip option [#644](https://github.com/aasm/aasm/pull/644), thanks to [Nitin-Salunke](https://github.com/Nitin-Salunke)
9
+ * Fixed aasm.current_event incorrectly yields nil when calling aasm.fire!(:event) [#551](https://github.com/aasm/aasm/issues/551) in [#638](https://github.com/aasm/aasm/pull/638), thanks to [DoubleJarvis](https://github.com/DoubleJarvis)
10
+ * Code Refactor [#634](https://github.com/aasm/aasm/pull/634) , thanks to [rahulknojha](https://github.com/rahulknojha)
11
+ * Fixed callback argument for :before_success & :success callback, [#630](https://github.com/aasm/aasm/pull/630)
12
+
13
+ ## 5.0.5
14
+
15
+ * Independent of ActiveSupport methods, [#627](https://github.com/aasm/aasm/pull/627),
16
+ thanks to [tristandruyen](https://github.com/tristandruyen). Fixes [#508](https://github.com/aasm/aasm/issues/508)
17
+
18
+ ## 5.0.4
19
+
20
+ * Specify dynamoid version for Rails > 5, [#625](https://github.com/aasm/aasm/pull/625),
21
+ thanks to [waghanza](https://github.com/waghanza)
22
+ * Add travis runner for Rails 5.2, [#624](https://github.com/aasm/aasm/pull/624), thanks
23
+ to [waghanza](https://github.com/waghanza)
24
+ * Cleanup Abstract class issue, [#620](https://github.com/aasm/aasm/pull/620), thanks to
25
+ [dennym](https://github.com/dennym)
26
+
27
+ ## 5.0.3
28
+
29
+ * Fix Abstract class issue, [#619](https://github.com/aasm/aasm/pull/619)
30
+
31
+ ## 5.0.2
32
+
33
+ * Clear failed callbacks, [#600](https://github.com/aasm/aasm/pull/600), thanks to
34
+ [nedgar](https://github.com/nedgar)
35
+ * README improvements, [#594](https://github.com/aasm/aasm/pull/594),
36
+ [#589](https://github.com/aasm/aasm/pull/589), [#587](https://github.com/aasm/aasm/pull/587),
37
+ [#597](https://github.com/aasm/aasm/pull/597), thanks to [jackscotti](https://github.com/jackscotti), [krmbzds](https://github.com/krmbzds),
38
+ [zegomesjf](https://github.com/zegomesjf), [BKSpurgeon](https://github.com/BKSpurgeon)
39
+ * Update InvalidTransition to include state_machine_name [#592](https://github.com/aasm/aasm/pull/592), thanks to [a14m](https://github.com/a14m)
40
+ * Do not add migration if model and column already exists [#586](https://github.com/aasm/aasm/pull/586), thanks to [KiranJosh](https://github.com/KiranJosh)
41
+
5
42
  ## 5.0.1
6
43
 
7
44
  * Fix failures array in transition not being reset [#383](https://github.com/aasm/aasm/issues/383)
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'sqlite3', :platforms => :ruby
5
+ gem 'sqlite3', '~> 1.3.5', :platforms => :ruby
6
6
  gem 'rails', '5.1.4'
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/aasm.svg)](http://badge.fury.io/rb/aasm)
4
4
  [![Build Status](https://travis-ci.org/aasm/aasm.svg?branch=master)](https://travis-ci.org/aasm/aasm)
5
- [![Dependency Status](https://gemnasium.com/aasm/aasm.svg)](https://gemnasium.com/aasm/aasm)
6
5
  [![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm)
6
+ [![codecov](https://codecov.io/gh/aasm/aasm/branch/master/graph/badge.svg)](https://codecov.io/gh/aasm/aasm)
7
7
 
8
8
  ## Index
9
9
  - [Upgrade from version 3 to 4](#upgrade-from-version-3-to-4)
@@ -30,6 +30,7 @@
30
30
  - [Transaction support](#transaction-support)
31
31
  - [Pessimistic Locking](#pessimistic-locking)
32
32
  - [Column name & migration](#column-name--migration)
33
+ - [Log State Changes](#log-state-changes)
33
34
  - [Inspection](#inspection)
34
35
  - [Warning output](#warning-output)
35
36
  - [RubyMotion support](#rubymotion-support)
@@ -71,19 +72,19 @@ class Job
71
72
  include AASM
72
73
 
73
74
  aasm do
74
- state :sleeping, :initial => true
75
+ state :sleeping, initial: true
75
76
  state :running, :cleaning
76
77
 
77
78
  event :run do
78
- transitions :from => :sleeping, :to => :running
79
+ transitions from: :sleeping, to: :running
79
80
  end
80
81
 
81
82
  event :clean do
82
- transitions :from => :running, :to => :cleaning
83
+ transitions from: :running, to: :cleaning
83
84
  end
84
85
 
85
86
  event :sleep do
86
- transitions :from => [:running, :cleaning], :to => :sleeping
87
+ transitions from: [:running, :cleaning], to: :sleeping
87
88
  end
88
89
  end
89
90
 
@@ -109,7 +110,7 @@ AASM not to be *whiny*:
109
110
  ```ruby
110
111
  class Job
111
112
  ...
112
- aasm :whiny_transitions => false do
113
+ aasm whiny_transitions: false do
113
114
  ...
114
115
  end
115
116
  end
@@ -138,19 +139,19 @@ class Job
138
139
  include AASM
139
140
 
140
141
  aasm do
141
- state :sleeping, :initial => true, :before_enter => :do_something
142
+ state :sleeping, initial: true, before_enter: :do_something
142
143
  state :running, before_enter: Proc.new { do_something && notify_somebody }
143
144
  state :finished
144
145
 
145
146
  after_all_transitions :log_status_change
146
147
 
147
- event :run, :after => :notify_somebody do
148
+ event :run, after: :notify_somebody do
148
149
  before do
149
150
  log('Preparing to run')
150
151
  end
151
152
 
152
- transitions :from => :sleeping, :to => :running, :after => Proc.new {|*args| set_process(*args) }
153
- transitions :from => :running, :to => :finished, :after => LogRunTime
153
+ transitions from: :sleeping, to: :running, after: Proc.new {|*args| set_process(*args) }
154
+ transitions from: :running, to: :finished, after: LogRunTime
154
155
  end
155
156
 
156
157
  event :sleep do
@@ -160,7 +161,7 @@ class Job
160
161
  error do |e|
161
162
  ...
162
163
  end
163
- transitions :from => :running, :to => :sleeping
164
+ transitions from: :running, to: :sleeping
164
165
  end
165
166
  end
166
167
 
@@ -215,13 +216,11 @@ Also, you can pass parameters to events:
215
216
 
216
217
  ```ruby
217
218
  job = Job.new
218
- job.run(:running, :defragmentation)
219
+ job.run(:defragmentation)
219
220
  ```
220
221
 
221
222
  In this case the `set_process` would be called with `:defragmentation` argument.
222
223
 
223
- 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.
224
-
225
224
  In case of an error during the event processing the error is rescued and passed to `:error`
226
225
  callback, which can handle it or re-raise it for further propagation.
227
226
 
@@ -313,24 +312,24 @@ class Cleaner
313
312
  include AASM
314
313
 
315
314
  aasm do
316
- state :idle, :initial => true
315
+ state :idle, initial: true
317
316
  state :cleaning
318
317
 
319
318
  event :clean do
320
- transitions :from => :idle, :to => :cleaning, :guard => :cleaning_needed?
319
+ transitions from: :idle, to: :cleaning, guard: :cleaning_needed?
321
320
  end
322
321
 
323
322
  event :clean_if_needed do
324
- transitions :from => :idle, :to => :cleaning do
323
+ transitions from: :idle, to: :cleaning do
325
324
  guard do
326
325
  cleaning_needed?
327
326
  end
328
327
  end
329
- transitions :from => :idle, :to => :idle
328
+ transitions from: :idle, to: :idle
330
329
  end
331
330
 
332
331
  event :clean_if_dirty do
333
- transitions :from => :idle, :to => :cleaning, :guard => :if_dirty?
332
+ transitions from: :idle, to: :cleaning, guard: :if_dirty?
334
333
  end
335
334
  end
336
335
 
@@ -359,16 +358,16 @@ You can even provide a number of guards, which all have to succeed to proceed
359
358
  def walked_the_dog?; ...; end
360
359
 
361
360
  event :sleep do
362
- transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?, :walked_the_dog?]
361
+ transitions from: :running, to: :sleeping, guards: [:cleaning_needed?, :walked_the_dog?]
363
362
  end
364
363
  ```
365
364
 
366
365
  If you want to provide guards for all transitions within an event, you can use event guards
367
366
 
368
367
  ```ruby
369
- event :sleep, :guards => [:walked_the_dog?] do
370
- transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?]
371
- transitions :from => :cleaning, :to => :sleeping
368
+ event :sleep, guards: [:walked_the_dog?] do
369
+ transitions from: :running, to: :sleeping, guards: [:cleaning_needed?]
370
+ transitions from: :cleaning, to: :sleeping
372
371
  end
373
372
  ```
374
373
 
@@ -376,15 +375,30 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
376
375
 
377
376
  ```ruby
378
377
  event :clean do
379
- transitions :from => :running, :to => :cleaning, :if => :cleaning_needed?
378
+ transitions from: :running, to: :cleaning, if: :cleaning_needed?
380
379
  end
381
380
 
382
381
  event :sleep do
383
- transitions :from => :running, :to => :sleeping, :unless => :cleaning_needed?
382
+ transitions from: :running, to: :sleeping, unless: :cleaning_needed?
384
383
  end
385
384
  end
386
385
  ```
387
386
 
387
+ You can invoke a Class instead a method since this Class responds to `call`
388
+
389
+ ```ruby
390
+ event :sleep do
391
+ transitions from: :running, to: :sleeping, guards: Dog
392
+ end
393
+ ```
394
+ ```ruby
395
+ class Dog
396
+ def call
397
+ cleaning_needed? && walked?
398
+ end
399
+ ...
400
+ end
401
+ ```
388
402
 
389
403
  ### Transitions
390
404
 
@@ -397,7 +411,7 @@ class Job
397
411
  include AASM
398
412
 
399
413
  aasm do
400
- state :stage1, :initial => true
414
+ state :stage1, initial: true
401
415
  state :stage2
402
416
  state :stage3
403
417
  state :completed
@@ -428,30 +442,30 @@ built with one state machine per class in mind. Nonetheless, here's how to do it
428
442
  class SimpleMultipleExample
429
443
  include AASM
430
444
  aasm(:move) do
431
- state :standing, :initial => true
445
+ state :standing, initial: true
432
446
  state :walking
433
447
  state :running
434
448
 
435
449
  event :walk do
436
- transitions :from => :standing, :to => :walking
450
+ transitions from: :standing, to: :walking
437
451
  end
438
452
  event :run do
439
- transitions :from => [:standing, :walking], :to => :running
453
+ transitions from: [:standing, :walking], to: :running
440
454
  end
441
455
  event :hold do
442
- transitions :from => [:walking, :running], :to => :standing
456
+ transitions from: [:walking, :running], to: :standing
443
457
  end
444
458
  end
445
459
 
446
460
  aasm(:work) do
447
- state :sleeping, :initial => true
461
+ state :sleeping, initial: true
448
462
  state :processing
449
463
 
450
464
  event :start do
451
- transitions :from => :sleeping, :to => :processing
465
+ transitions from: :sleeping, to: :processing
452
466
  end
453
467
  event :stop do
454
- transitions :from => :processing, :to => :sleeping
468
+ transitions from: :processing, to: :sleeping
455
469
  end
456
470
  end
457
471
  end
@@ -484,28 +498,28 @@ Alternatively, you can provide a namespace for each state machine:
484
498
  class NamespacedMultipleExample
485
499
  include AASM
486
500
  aasm(:status) do
487
- state :unapproved, :initial => true
501
+ state :unapproved, initial: true
488
502
  state :approved
489
503
 
490
504
  event :approve do
491
- transitions :from => :unapproved, :to => :approved
505
+ transitions from: :unapproved, to: :approved
492
506
  end
493
507
 
494
508
  event :unapprove do
495
- transitions :from => :approved, :to => :unapproved
509
+ transitions from: :approved, to: :unapproved
496
510
  end
497
511
  end
498
512
 
499
513
  aasm(:review_status, namespace: :review) do
500
- state :unapproved, :initial => true
514
+ state :unapproved, initial: true
501
515
  state :approved
502
516
 
503
517
  event :approve do
504
- transitions :from => :unapproved, :to => :approved
518
+ transitions from: :unapproved, to: :approved
505
519
  end
506
520
 
507
521
  event :unapprove do
508
- transitions :from => :approved, :to => :unapproved
522
+ transitions from: :approved, to: :unapproved
509
523
  end
510
524
  end
511
525
  end
@@ -537,26 +551,26 @@ class Example
537
551
  include AASM
538
552
 
539
553
  aasm(:work) do
540
- state :sleeping, :initial => true
554
+ state :sleeping, initial: true
541
555
  state :processing
542
556
 
543
557
  event :start do
544
- transitions :from => :sleeping, :to => :processing
558
+ transitions from: :sleeping, to: :processing
545
559
  end
546
560
  event :stop do
547
- transitions :from => :processing, :to => :sleeping
561
+ transitions from: :processing, to: :sleeping
548
562
  end
549
563
  end
550
564
 
551
565
  aasm(:question) do
552
- state :answered, :initial => true
566
+ state :answered, initial: true
553
567
  state :asked
554
568
 
555
- event :ask, :binding_event => :start do
556
- transitions :from => :answered, :to => :asked
569
+ event :ask, binding_event: :start do
570
+ transitions from: :answered, to: :asked
557
571
  end
558
- event :answer, :binding_event => :stop do
559
- transitions :from => :asked, :to => :answered
572
+ event :answer, binding_event: :stop do
573
+ transitions from: :asked, to: :answered
560
574
  end
561
575
  end
562
576
  end
@@ -602,7 +616,7 @@ class CustomAASMBase < AASM::Base
602
616
  # A custom transiton that we want available across many AASM models.
603
617
  def count_transitions!
604
618
  klass.class_eval do
605
- aasm :with_klass => CustomAASMBase do
619
+ aasm with_klass: CustomAASMBase do
606
620
  after_all_transitions :increment_transition_count
607
621
  end
608
622
  end
@@ -639,19 +653,19 @@ class SimpleCustomExample
639
653
  include AASM
640
654
 
641
655
  # Let's build an AASM state machine with our custom class.
642
- aasm :with_klass => CustomAASMBase do
656
+ aasm with_klass: CustomAASMBase do
643
657
  requires_guards!
644
658
  count_transitions!
645
659
 
646
- state :initialised, :initial => true
660
+ state :initialised, initial: true
647
661
  state :filled_out
648
662
  state :authorised
649
663
 
650
664
  event :fill_out do
651
- transitions :from => :initialised, :to => :filled_out, :guard => :fillable?
665
+ transitions from: :initialised, to: :filled_out, guard: :fillable?
652
666
  end
653
667
  event :authorise do
654
- transitions :from => :filled_out, :to => :authorised, :guard => :authorizable?
668
+ transitions from: :filled_out, to: :authorised, guard: :authorizable?
655
669
  end
656
670
  end
657
671
  end
@@ -668,15 +682,15 @@ class Job < ActiveRecord::Base
668
682
  include AASM
669
683
 
670
684
  aasm do # default column: aasm_state
671
- state :sleeping, :initial => true
685
+ state :sleeping, initial: true
672
686
  state :running
673
687
 
674
688
  event :run do
675
- transitions :from => :sleeping, :to => :running
689
+ transitions from: :sleeping, to: :running
676
690
  end
677
691
 
678
692
  event :sleep do
679
- transitions :from => :running, :to => :sleeping
693
+ transitions from: :running, to: :sleeping
680
694
  end
681
695
  end
682
696
 
@@ -711,22 +725,30 @@ be updated in the database (just like ActiveRecord `update_column` is working).
711
725
  class Job < ActiveRecord::Base
712
726
  include AASM
713
727
 
714
- aasm :skip_validation_on_save => true do
715
- state :sleeping, :initial => true
728
+ aasm skip_validation_on_save: true do
729
+ state :sleeping, initial: true
716
730
  state :running
717
731
 
718
732
  event :run do
719
- transitions :from => :sleeping, :to => :running
733
+ transitions from: :sleeping, to: :running
720
734
  end
721
735
 
722
736
  event :sleep do
723
- transitions :from => :running, :to => :sleeping
737
+ transitions from: :running, to: :sleeping
724
738
  end
725
739
  end
726
740
 
727
741
  end
728
742
  ```
729
743
 
744
+ Also You can skip the validation at instance level with `some_event_name_without_validation!` method.
745
+ With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
746
+ Please note that only state column will be updated as mentioned in the above example.
747
+
748
+ ```ruby
749
+ job.run_without_validation!
750
+ ```
751
+
730
752
  If you want to make sure that the _AASM_ column for storing the state is not directly assigned,
731
753
  configure _AASM_ to not allow direct assignment, like this:
732
754
 
@@ -734,12 +756,12 @@ configure _AASM_ to not allow direct assignment, like this:
734
756
  class Job < ActiveRecord::Base
735
757
  include AASM
736
758
 
737
- aasm :no_direct_assignment => true do
738
- state :sleeping, :initial => true
759
+ aasm no_direct_assignment: true do
760
+ state :sleeping, initial: true
739
761
  state :running
740
762
 
741
763
  event :run do
742
- transitions :from => :sleeping, :to => :running
764
+ transitions from: :sleeping, to: :running
743
765
  end
744
766
  end
745
767
 
@@ -770,8 +792,8 @@ class Job < ActiveRecord::Base
770
792
  running: 99
771
793
  }
772
794
 
773
- aasm :column => :state, :enum => true do
774
- state :sleeping, :initial => true
795
+ aasm column: :state, enum: true do
796
+ state :sleeping, initial: true
775
797
  state :running
776
798
  end
777
799
  end
@@ -870,7 +892,7 @@ class Job < ActiveRecord::Base
870
892
  include AASM
871
893
 
872
894
  aasm do
873
- state :sleeping, :initial => true
895
+ state :sleeping, initial: true
874
896
  state :running
875
897
  state :cleaning
876
898
  end
@@ -899,8 +921,8 @@ defining the `AASM` states, like this:
899
921
  class Job < ActiveRecord::Base
900
922
  include AASM
901
923
 
902
- aasm :create_scopes => false do
903
- state :sleeping, :initial => true
924
+ aasm create_scopes: false do
925
+ state :sleeping, initial: true
904
926
  state :running
905
927
  state :cleaning
906
928
  end
@@ -933,11 +955,11 @@ class Job < ActiveRecord::Base
933
955
  include AASM
934
956
 
935
957
  aasm do
936
- state :sleeping, :initial => true
958
+ state :sleeping, initial: true
937
959
  state :running
938
960
 
939
- event :run, :after_commit => :notify_about_running_job do
940
- transitions :from => :sleeping, :to => :running
961
+ event :run, after_commit: :notify_about_running_job do
962
+ transitions from: :sleeping, to: :running
941
963
  end
942
964
  end
943
965
 
@@ -963,14 +985,14 @@ If you want to encapsulate state changes within an own transaction, the behavior
963
985
  of this nested transaction might be confusing. Take a look at
964
986
  [ActiveRecord Nested Transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html)
965
987
  if you want to know more about this. Nevertheless, AASM by default requires a new transaction
966
- `transaction(:requires_new => true)`. You can override this behavior by changing
988
+ `transaction(requires_new: true)`. You can override this behavior by changing
967
989
  the configuration
968
990
 
969
991
  ```ruby
970
992
  class Job < ActiveRecord::Base
971
993
  include AASM
972
994
 
973
- aasm :requires_new_transaction => false do
995
+ aasm requires_new_transaction: false do
974
996
  ...
975
997
  end
976
998
 
@@ -978,7 +1000,7 @@ class Job < ActiveRecord::Base
978
1000
  end
979
1001
  ```
980
1002
 
981
- which then leads to `transaction(:requires_new => false)`, the Rails default.
1003
+ which then leads to `transaction(requires_new: false)`, the Rails default.
982
1004
 
983
1005
  Additionally, if you do not want any of your active record actions to be
984
1006
  wrapped in a transaction, you can specify the `use_transactions` flag. This can
@@ -990,7 +1012,7 @@ result of a transaction or callback, even when some error occurs. The
990
1012
  class Job < ActiveRecord::Base
991
1013
  include AASM
992
1014
 
993
- aasm :use_transactions => false do
1015
+ aasm use_transactions: false do
994
1016
  ...
995
1017
  end
996
1018
 
@@ -1013,7 +1035,7 @@ AASM supports [Active Record pessimistic locking via `with_lock`](http://api.rub
1013
1035
  class Job < ActiveRecord::Base
1014
1036
  include AASM
1015
1037
 
1016
- aasm :requires_lock => true do
1038
+ aasm requires_lock: true do
1017
1039
  ...
1018
1040
  end
1019
1041
 
@@ -1025,7 +1047,7 @@ end
1025
1047
  class Job < ActiveRecord::Base
1026
1048
  include AASM
1027
1049
 
1028
- aasm :requires_lock => 'FOR UPDATE NOWAIT' do
1050
+ aasm requires_lock: 'FOR UPDATE NOWAIT' do
1029
1051
  ...
1030
1052
  end
1031
1053
 
@@ -1043,7 +1065,7 @@ this by defining your favorite column name, using `:column` like this:
1043
1065
  class Job < ActiveRecord::Base
1044
1066
  include AASM
1045
1067
 
1046
- aasm :column => 'my_state' do
1068
+ aasm column: 'my_state' do
1047
1069
  ...
1048
1070
  end
1049
1071
 
@@ -1068,6 +1090,13 @@ class AddJobState < ActiveRecord::Migration
1068
1090
  end
1069
1091
  ```
1070
1092
 
1093
+ ### Log State Changes
1094
+
1095
+ Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
1096
+
1097
+ Example of implementation can be found here [https://github.com/nitsujri/aasm-papertrail-example](https://github.com/nitsujri/aasm-papertrail-example)
1098
+
1099
+
1071
1100
  ### Inspection
1072
1101
 
1073
1102
  AASM supports query methods for states and events
@@ -1079,19 +1108,19 @@ class Job
1079
1108
  include AASM
1080
1109
 
1081
1110
  aasm do
1082
- state :sleeping, :initial => true
1111
+ state :sleeping, initial: true
1083
1112
  state :running, :cleaning
1084
1113
 
1085
1114
  event :run do
1086
- transitions :from => :sleeping, :to => :running
1115
+ transitions from: :sleeping, to: :running
1087
1116
  end
1088
1117
 
1089
1118
  event :clean do
1090
- transitions :from => :running, :to => :cleaning, :guard => :cleaning_needed?
1119
+ transitions from: :running, to: :cleaning, guard: :cleaning_needed?
1091
1120
  end
1092
1121
 
1093
1122
  event :sleep do
1094
- transitions :from => [:running, :cleaning], :to => :sleeping
1123
+ transitions from: [:running, :cleaning], to: :sleeping
1095
1124
  end
1096
1125
  end
1097
1126
 
@@ -1109,15 +1138,15 @@ Job.aasm.states.map(&:name)
1109
1138
  job = Job.new
1110
1139
 
1111
1140
  # show all permitted states (from initial state)
1112
- job.aasm.states(:permitted => true).map(&:name)
1141
+ job.aasm.states(permitted: true).map(&:name)
1113
1142
  #=> [:running]
1114
1143
 
1115
1144
  job.run
1116
- job.aasm.states(:permitted => true).map(&:name)
1145
+ job.aasm.states(permitted: true).map(&:name)
1117
1146
  #=> [:sleeping]
1118
1147
 
1119
1148
  # show all non permitted states
1120
- job.aasm.states(:permitted => false).map(&:name)
1149
+ job.aasm.states(permitted: false).map(&:name)
1121
1150
  #=> [:cleaning]
1122
1151
 
1123
1152
  # show all possible (triggerable) events from the current state
@@ -1125,23 +1154,23 @@ job.aasm.events.map(&:name)
1125
1154
  #=> [:clean, :sleep]
1126
1155
 
1127
1156
  # show all permitted events
1128
- job.aasm.events(:permitted => true).map(&:name)
1157
+ job.aasm.events(permitted: true).map(&:name)
1129
1158
  #=> [:sleep]
1130
1159
 
1131
1160
  # show all non permitted events
1132
- job.aasm.events(:permitted => false).map(&:name)
1161
+ job.aasm.events(permitted: false).map(&:name)
1133
1162
  #=> [:clean]
1134
1163
 
1135
1164
  # show all possible events except a specific one
1136
- job.aasm.events(:reject => :sleep).map(&:name)
1165
+ job.aasm.events(reject: :sleep).map(&:name)
1137
1166
  #=> [:clean]
1138
1167
 
1139
1168
  # list states for select
1140
1169
  Job.aasm.states_for_select
1141
- => [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
1170
+ #=> [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
1142
1171
 
1143
1172
  # show permitted states with guard parameter
1144
- job.aasm.states({:permitted => true}, guard_parameter).map(&:name)
1173
+ job.aasm.states({permitted: true}, guard_parameter).map(&:name)
1145
1174
  ```
1146
1175
 
1147
1176
 
@@ -1154,7 +1183,7 @@ use
1154
1183
  class Job
1155
1184
  include AASM
1156
1185
 
1157
- aasm :logger => Rails.logger do
1186
+ aasm logger: Rails.logger do
1158
1187
  ...
1159
1188
  end
1160
1189
  end
@@ -1178,7 +1207,15 @@ the 'instance method symbol / string' way whenever possible when defining guardi
1178
1207
 
1179
1208
  #### RSpec
1180
1209
 
1181
- AASM provides some matchers for [RSpec](http://rspec.info): `transition_from`, `have_state`, `allow_event` and `allow_transition_to`. Add `require 'aasm/rspec'` to your `spec_helper.rb` file and use them like this:
1210
+ AASM provides some matchers for [RSpec](http://rspec.info):
1211
+ * `transition_from`,
1212
+ * `have_state`, `allow_event`
1213
+ * and `allow_transition_to`.
1214
+
1215
+ ##### Installation Instructions:
1216
+ * Add `require 'aasm/rspec'` to your `spec_helper.rb` file.
1217
+
1218
+ ##### Examples Of Usage in Rspec:
1182
1219
 
1183
1220
  ```ruby
1184
1221
  # classes with only the default state machine
@@ -1191,7 +1228,7 @@ expect(job).to allow_event :run
1191
1228
  expect(job).to_not allow_event :clean
1192
1229
  expect(job).to allow_transition_to(:running)
1193
1230
  expect(job).to_not allow_transition_to(:cleaning)
1194
- # on_event also accept arguments
1231
+ # on_event also accept multiple arguments
1195
1232
  expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :defragmentation)
1196
1233
 
1197
1234
  # classes with multiple state machine
@@ -1225,6 +1262,9 @@ AASM provides assertions and rspec-like expectations for [Minitest](https://gith
1225
1262
 
1226
1263
  List of supported assertions: `assert_have_state`, `refute_have_state`, `assert_transitions_from`, `refute_transitions_from`, `assert_event_allowed`, `refute_event_allowed`, `assert_transition_to_allowed`, `refute_transition_to_allowed`.
1227
1264
 
1265
+
1266
+ ##### Examples Of Usage (Minitest):
1267
+
1228
1268
  Add `require 'aasm/minitest'` to your `test_helper.rb` file and use them like this:
1229
1269
 
1230
1270
  ```ruby