aasm 4.11.1 → 4.12.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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +19 -16
  3. data/Appraisals +46 -0
  4. data/CHANGELOG.md +19 -0
  5. data/CONTRIBUTING.md +24 -0
  6. data/Gemfile +4 -21
  7. data/README.md +154 -39
  8. data/Rakefile +6 -1
  9. data/TESTING.md +25 -0
  10. data/aasm.gemspec +3 -0
  11. data/gemfiles/rails_3.2.gemfile +13 -0
  12. data/gemfiles/rails_4.0.gemfile +8 -9
  13. data/gemfiles/rails_4.2.gemfile +10 -9
  14. data/gemfiles/rails_4.2_mongoid_5.gemfile +5 -9
  15. data/gemfiles/rails_5.0.gemfile +8 -16
  16. data/lib/aasm/aasm.rb +9 -3
  17. data/lib/aasm/base.rb +11 -1
  18. data/lib/aasm/configuration.rb +4 -0
  19. data/lib/aasm/core/event.rb +18 -4
  20. data/lib/aasm/core/state.rb +7 -0
  21. data/lib/aasm/core/transition.rb +10 -1
  22. data/lib/aasm/instance_base.rb +0 -2
  23. data/lib/aasm/minitest/allow_event.rb +13 -0
  24. data/lib/aasm/minitest/allow_transition_to.rb +13 -0
  25. data/lib/aasm/minitest/have_state.rb +13 -0
  26. data/lib/aasm/minitest/transition_from.rb +21 -0
  27. data/lib/aasm/minitest.rb +5 -0
  28. data/lib/aasm/minitest_spec.rb +15 -0
  29. data/lib/aasm/persistence/active_record_persistence.rb +25 -101
  30. data/lib/aasm/persistence/base.rb +7 -3
  31. data/lib/aasm/persistence/mongoid_persistence.rb +25 -31
  32. data/lib/aasm/persistence/orm.rb +142 -0
  33. data/lib/aasm/persistence/redis_persistence.rb +16 -11
  34. data/lib/aasm/persistence/sequel_persistence.rb +36 -63
  35. data/lib/aasm/persistence.rb +0 -3
  36. data/lib/aasm/state_machine.rb +4 -2
  37. data/lib/aasm/state_machine_store.rb +5 -2
  38. data/lib/aasm/version.rb +1 -1
  39. data/lib/generators/active_record/templates/migration.rb +1 -1
  40. data/lib/generators/active_record/templates/migration_existing.rb +1 -1
  41. data/lib/motion-aasm.rb +2 -1
  42. data/spec/generators/active_record_generator_spec.rb +42 -39
  43. data/spec/generators/mongoid_generator_spec.rb +4 -6
  44. data/spec/models/active_record/complex_active_record_example.rb +5 -1
  45. data/spec/models/{invalid_persistor.rb → active_record/invalid_persistor.rb} +0 -2
  46. data/spec/models/{silent_persistor.rb → active_record/silent_persistor.rb} +0 -2
  47. data/spec/models/{transactor.rb → active_record/transactor.rb} +0 -2
  48. data/spec/models/{validator.rb → active_record/validator.rb} +0 -2
  49. data/spec/models/callbacks/basic.rb +5 -2
  50. data/spec/models/guard_with_params.rb +1 -1
  51. data/spec/models/guardian_without_from_specified.rb +18 -0
  52. data/spec/models/mongoid/invalid_persistor_mongoid.rb +39 -0
  53. data/spec/models/mongoid/silent_persistor_mongoid.rb +39 -0
  54. data/spec/models/mongoid/validator_mongoid.rb +100 -0
  55. data/spec/models/multiple_transitions_that_differ_only_by_guard.rb +31 -0
  56. data/spec/models/namespaced_multiple_example.rb +14 -0
  57. data/spec/models/parametrised_event.rb +7 -0
  58. data/spec/models/{mongo_mapper/complex_mongo_mapper_example.rb → redis/complex_redis_example.rb} +8 -5
  59. data/spec/models/redis/redis_multiple.rb +20 -0
  60. data/spec/models/redis/redis_simple.rb +20 -0
  61. data/spec/models/sequel/complex_sequel_example.rb +4 -3
  62. data/spec/models/sequel/invalid_persistor.rb +52 -0
  63. data/spec/models/sequel/sequel_multiple.rb +13 -13
  64. data/spec/models/sequel/sequel_simple.rb +13 -12
  65. data/spec/models/sequel/silent_persistor.rb +50 -0
  66. data/spec/models/sequel/transactor.rb +112 -0
  67. data/spec/models/sequel/validator.rb +93 -0
  68. data/spec/models/sequel/worker.rb +12 -0
  69. data/spec/models/simple_multiple_example.rb +12 -0
  70. data/spec/models/sub_class.rb +34 -0
  71. data/spec/spec_helper.rb +0 -33
  72. data/spec/spec_helpers/active_record.rb +7 -0
  73. data/spec/spec_helpers/dynamoid.rb +33 -0
  74. data/spec/spec_helpers/mongoid.rb +7 -0
  75. data/spec/spec_helpers/redis.rb +15 -0
  76. data/spec/spec_helpers/remove_warnings.rb +1 -0
  77. data/spec/spec_helpers/sequel.rb +7 -0
  78. data/spec/unit/api_spec.rb +76 -73
  79. data/spec/unit/callbacks_spec.rb +5 -0
  80. data/spec/unit/event_spec.rb +12 -0
  81. data/spec/unit/guard_spec.rb +17 -0
  82. data/spec/unit/guard_with_params_spec.rb +4 -0
  83. data/spec/unit/guard_without_from_specified_spec.rb +10 -0
  84. data/spec/unit/localizer_spec.rb +55 -53
  85. data/spec/unit/multiple_transitions_that_differ_only_by_guard_spec.rb +14 -0
  86. data/spec/unit/namespaced_multiple_example_spec.rb +22 -0
  87. data/spec/unit/override_warning_spec.rb +8 -0
  88. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +453 -449
  89. data/spec/unit/persistence/active_record_persistence_spec.rb +524 -502
  90. data/spec/unit/persistence/dynamoid_persistence_multiple_spec.rb +4 -9
  91. data/spec/unit/persistence/dynamoid_persistence_spec.rb +4 -9
  92. data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +83 -9
  93. data/spec/unit/persistence/mongoid_persistence_spec.rb +85 -9
  94. data/spec/unit/persistence/redis_persistence_multiple_spec.rb +88 -0
  95. data/spec/unit/persistence/redis_persistence_spec.rb +8 -32
  96. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +6 -11
  97. data/spec/unit/persistence/sequel_persistence_spec.rb +278 -10
  98. data/spec/unit/simple_multiple_example_spec.rb +28 -0
  99. data/spec/unit/subclassing_multiple_spec.rb +37 -2
  100. data/spec/unit/subclassing_spec.rb +17 -2
  101. data/test/minitest_helper.rb +57 -0
  102. data/test/unit/minitest_matcher_test.rb +80 -0
  103. metadata +99 -28
  104. data/gemfiles/rails_3.2_stable.gemfile +0 -15
  105. data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -16
  106. data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -17
  107. data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -163
  108. data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
  109. data/spec/models/mongo_mapper/simple_mongo_mapper.rb +0 -23
  110. data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
  111. data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -149
  112. data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -96
  113. /data/spec/models/{worker.rb → active_record/worker.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a57dd3feade6d1aea288f5999b4d93c890b11c60
4
- data.tar.gz: 8e14ba9da4f262ca2f2ba0a40f633af6234e2075
3
+ metadata.gz: 51fca1a6911cbe2585301606192b2d0a467ae7e7
4
+ data.tar.gz: c4bdfee904a029cec8329eb024c608f225a3b746
5
5
  SHA512:
6
- metadata.gz: 08b85c55e73ba7b152e7a8344bf706315aa33016047849fee0e64dff8201f2691132d83d1e2c91b7e603b1e5f8e2a23bb8510573b539f142fa38b718c4aa0191
7
- data.tar.gz: 2cdd0ef93171f881ef36bd2b1fe0d06d71dce2a73fffee570515c12f69fdc52fb18ea02e29a5b4591498de9526e3fb1bf6039aff8d4ed9af0c8a069f278150cc
6
+ metadata.gz: 7ce9707a179a75f5e75c038ae8102956503564bca475151a6c64dfad9862b313382fc6b7f3ddc2c8e928dfbb666667b171be5abc7bf7d569e5e72cd4ee59467e
7
+ data.tar.gz: e2c030b9c239c3ced525745ed32f192712ed946fff5f5ed45c8c2710fe3da2aa8291f41faf351b9241c1eb7e6ecf4bb4ad72aace93aeb6f91e0b8af58d253f73
data/.travis.yml CHANGED
@@ -4,45 +4,48 @@ cache: bundler
4
4
 
5
5
  rvm:
6
6
  - 1.9.3
7
- - 2.2.5
8
- - 2.3.1
7
+ - 2.2.6
8
+ - 2.3.3
9
9
  - jruby-1.7 # JRuby in 1.9 mode
10
10
  - jruby-9.0.5.0
11
- - rbx-2.5.8
12
11
 
13
12
  services:
14
13
  - mongodb
15
14
  - redis-server
16
15
 
17
16
  gemfile:
18
- - gemfiles/rails_3.2_stable.gemfile
17
+ - gemfiles/rails_3.2.gemfile
19
18
  - gemfiles/rails_4.0.gemfile
20
- - gemfiles/rails_4.0_mongo_mapper.gemfile
21
19
  - gemfiles/rails_4.2.gemfile
22
20
  - gemfiles/rails_4.2_mongoid_5.gemfile
23
- - gemfiles/rails_4.2_mongo_mapper.gemfile
24
21
  - gemfiles/rails_5.0.gemfile
25
22
 
26
23
  before_script:
27
24
  - mkdir /tmp/dynamodb
28
- - wget -O - http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest | tar xz --directory /tmp/dynamodb
25
+ - wget -O - https://s3-ap-southeast-1.amazonaws.com/dynamodb-local-singapore/dynamodb_local_latest.tar.gz | tar xz --directory /tmp/dynamodb
29
26
  - java -Djava.library.path=/tmp/dynamodb/DynamoDBLocal_lib -jar /tmp/dynamodb/DynamoDBLocal.jar -inMemory -delayTransientStatuses -port 30180 &
27
+ - mongod --version
28
+
29
+ script:
30
+ - bundle exec rspec spec
31
+ - bundle exec rake test
30
32
 
31
33
  matrix:
32
- allow_failures:
33
- - rvm: jruby-9.0.5.0
34
- gemfile: gemfiles/rails_5.0.gemfile
35
- - rvm: rbx-2.5.8
36
- gemfile: gemfiles/rails_5.0.gemfile
37
34
  exclude:
35
+ - rvm: 1.9.3
36
+ gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
38
37
  - rvm: 1.9.3
39
38
  gemfile: gemfiles/rails_5.0.gemfile
40
- - rvm: 2.2.5
41
- gemfile: gemfiles/rails_3.2_stable.gemfile
42
- - rvm: 2.3.1
43
- gemfile: gemfiles/rails_3.2_stable.gemfile
39
+ - rvm: 2.2.6
40
+ gemfile: gemfiles/rails_3.2.gemfile
41
+ - rvm: 2.3.3
42
+ gemfile: gemfiles/rails_3.2.gemfile
43
+ - rvm: jruby-1.7
44
+ gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
44
45
  - rvm: jruby-1.7
45
46
  gemfile: gemfiles/rails_5.0.gemfile
47
+ - rvm: jruby-9.0.5.0
48
+ gemfile: gemfiles/rails_5.0.gemfile
46
49
 
47
50
  notifications:
48
51
  slack:
data/Appraisals ADDED
@@ -0,0 +1,46 @@
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
+ end
8
+
9
+ appraise 'rails_4.0' do
10
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
11
+ gem 'rails', '4.0.13'
12
+ gem 'mongoid', '~>4.0'
13
+ gem 'sequel'
14
+ gem 'dynamoid', '~> 1', :platforms => :ruby
15
+ gem 'aws-sdk', '~>2', :platforms => :ruby
16
+ gem 'redis-objects'
17
+ end
18
+
19
+ appraise 'rails_4.2' do
20
+ gem 'nokogiri', '1.6.8.1', :platforms => [:ruby_19]
21
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
22
+ gem 'rails', '4.2.5'
23
+ gem 'mongoid', '~>4.0'
24
+ gem 'sequel'
25
+ gem 'dynamoid', '~> 1', :platforms => :ruby
26
+ gem 'aws-sdk', '~>2', :platforms => :ruby
27
+ gem 'redis-objects'
28
+ end
29
+
30
+ appraise 'rails_4.2_mongoid_5' do
31
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
32
+ gem 'rails', '4.2.5'
33
+ gem 'mongoid', '~>5.0'
34
+ end
35
+
36
+ appraise 'rails_5.0' do
37
+ gem 'rails', '5.0.0'
38
+ gem 'mongoid', '~>6.0'
39
+ gem 'sequel'
40
+
41
+ # dynamoid is not yet Rails 5 compatible
42
+ # gem 'dynamoid', '~> 1', :platforms => :ruby
43
+
44
+ gem 'aws-sdk', '~>2', :platforms => :ruby
45
+ gem 'redis-objects'
46
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## unreleased
4
+
5
+ ## 4.12.1
6
+
7
+ * DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking #475, thanks to [@Aryk] (https://github.com/Aryk)
8
+ * Add aliases for event methods #476, thanks to [@Aryk] (https://github.com/Aryk)
9
+ * Support Minitest spec expectations (#387), thanks to [@faragorn] (https://github.com/faragorn)
10
+ ## 4.12.0
11
+
12
+ * 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)
13
+ * Drop Support for Mongo Mapper [see [pull-request #439](https://github.com/aasm/aasm/pull/439)], thanks to [@reidmorrison](https://github.com/reidmorrison)
14
+ * add :binding_event option to event [see [pull-request #438](https://github.com/aasm/aasm/pull/438)], thanks to [@leanhdaovn](https://github.com/leanhdaovn)
15
+ * fix: `skip_validation_on_save: true` for default_scope records, [see [pull-request #433](https://github.com/aasm/aasm/pull/433)], thanks to [@larissa](https://github.com/larissa)
16
+ * Deep clone state machine during inheritance so that state machines in child classes can be modified (see [pull-request #429](https://github.com/aasm/aasm/pull/429)), thanks to [@reidmorrison](https://github.com/reidmorrison) and [@Tybot204](https://github.com/Tybot204)
17
+ * add before_success callback for event (see [pull-request #422](https://github.com/aasm/aasm/pull/422)), thanks to [@timsly ](https://github.com/timsly)
18
+ * fix: multiple transitions in a single event with the same to and from states (see [issue #372](https://github.com/aasm/aasm/issues/372) and [issue #362](https://github.com/aasm/aasm/issues/362) for details, fixed with [pull-request #408](https://github.com/aasm/aasm/pull/408), thanks to [@dathanb](https://github.com/dathanb))
19
+ * fix: passing nil as a argument to callbacks (see [issue #404](https://github.com/aasm/aasm/issues/404) for details, fixed with [pull-request #406](https://github.com/aasm/aasm/pull/406), thanks to [@yogeshjain999](https://github.com/yogeshjain999))
20
+
21
+
3
22
  ## 4.11.1
4
23
 
5
24
  * fix: generator file name when using custom column name instead of
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ ## Contributing ##
2
+
3
+ While not required to contribute, we recommend [RVM](https://rvm.io/) to manage your rubies.
4
+
5
+ 1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
6
+ 2. [Fork it](https://help.github.com/articles/about-forks/)
7
+ 3. Clone the project `git clone git@github.com:[YOUR GITHUB USERNAME]/aasm.git`
8
+ 4. `cd aasm`
9
+ 5. Create your feature branch `git checkout -b my-new-feature`
10
+ 6. Write tests for your changes (feature/bug)
11
+ 7. Write your (feature/bugfix)
12
+ 8. Install the dependencies `appraisal install`
13
+ 9. Run the tests `appraisal rspec`
14
+ 10. Commit your changes `git commit -am 'Added some feature'`
15
+ 11. Push to the branch `git push origin my-new-feature`
16
+ 12. Create new [Pull Request](https://help.github.com/articles/creating-a-pull-request/)
17
+
18
+ There are some option dependencies as well.
19
+
20
+ - [MongoDB server](https://www.mongodb.com/download-center)
21
+ - [Redis](https://redis.io/topics/quickstart)
22
+ - [DynamoDB (local)](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html)
23
+
24
+ If we've missed something please open an [issue](https://github.com/aasm/aasm/issues/new)
data/Gemfile CHANGED
@@ -1,24 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem "jruby-openssl", :platforms => :jruby
6
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
8
- gem "rails", "~>4.2"
9
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
10
- gem 'sequel'
11
-
12
- # testing dynamoid
13
- # gem 'dynamoid', '~> 1'
14
- # gem 'aws-sdk', '~>2'
15
-
16
- # Since mongoid V4 requires incompatible bson V2, cannot have mongoid (V4 or greater)
17
- # and mongo_mapper ( or mongo ) in the same application
18
- # gem 'mongo_mapper', '~> 0.13'
19
- # gem 'bson_ext', :platforms => :ruby
20
-
21
- # uncomment if you want to run specs for Redis persistence
22
- # gem "redis-objects"
23
-
24
3
  gemspec
4
+
5
+ gem 'sqlite3', :platforms => :ruby
6
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
7
+ gem 'rails', '5.0.2'
data/README.md CHANGED
@@ -10,7 +10,7 @@ This package contains AASM, a library for adding finite state machines to Ruby c
10
10
  AASM started as the *acts_as_state_machine* plugin but has evolved into a more generic library
11
11
  that no longer targets only ActiveRecord models. It currently provides adapters for
12
12
  [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html),
13
- [Mongoid](http://mongoid.org/), and [Mongomapper](http://mongomapper.com/) but it can be used for any Ruby class, no matter what
13
+ and [Mongoid](http://mongoid.org/) but it can be used for any Ruby class, no matter what
14
14
  parent class it has (if any).
15
15
 
16
16
  ## Upgrade from version 3 to 4
@@ -180,6 +180,7 @@ begin
180
180
  new_state before_enter
181
181
  new_state enter
182
182
  ...update state...
183
+ event before_success # if persist successful
183
184
  transition success # if persist successful
184
185
  event success # if persist successful
185
186
  old_state after_exit
@@ -209,6 +210,14 @@ Note that when passing arguments to a state transition, the first argument must
209
210
  In case of an error during the event processing the error is rescued and passed to `:error`
210
211
  callback, which can handle it or re-raise it for further propagation.
211
212
 
213
+ Also, you can define a method that will be called if any event fails:
214
+
215
+ ```
216
+ def aasm_event_failed(event_name, old_state_name)
217
+ # use custom exception/messages, report metrics, etc
218
+ end
219
+ ```
220
+
212
221
  During the transition's `:after` callback (and reliably only then, or in the global
213
222
  `after_all_transitions` callback) you can access the originating state (the from-state)
214
223
  and the target state (the to state), like this:
@@ -415,8 +424,45 @@ SimpleMultipleExample.aasm(:work).states
415
424
  # => [:standing, :walking, :running]
416
425
  ```
417
426
 
418
- *Final note*: Support for multiple state machines per class is a pretty new feature
419
- (since version `4.3`), so please bear with us in case it doesn't work as expected.
427
+ ### Binding event
428
+
429
+ Allow an event to be bound to another
430
+ ```ruby
431
+ class Example
432
+ include AASM
433
+
434
+ aasm(:work) do
435
+ state :sleeping, :initial => true
436
+ state :processing
437
+
438
+ event :start do
439
+ transitions :from => :sleeping, :to => :processing
440
+ end
441
+ event :stop do
442
+ transitions :from => :processing, :to => :sleeping
443
+ end
444
+ end
445
+
446
+ aasm(:question) do
447
+ state :answered, :initial => true
448
+ state :asked
449
+
450
+ event :ask, :binding_event => :start do
451
+ transitions :from => :answered, :to => :asked
452
+ end
453
+ event :answer, :binding_event => :stop do
454
+ transitions :from => :asked, :to => :answered
455
+ end
456
+ end
457
+ end
458
+
459
+ example = Example.new
460
+ example.aasm(:work).current_state #=> :sleeping
461
+ example.aasm(:question).current_state #=> :answered
462
+ example.ask
463
+ example.aasm(:work).current_state #=> :processing
464
+ example.aasm(:question).current_state #=> :asked
465
+ ```
420
466
 
421
467
  ### Auto-generated Status Constants
422
468
 
@@ -532,6 +578,8 @@ class Job < ActiveRecord::Base
532
578
  end
533
579
  ```
534
580
 
581
+ ### Bang events
582
+
535
583
  You can tell AASM to auto-save the object or leave it unsaved
536
584
 
537
585
  ```ruby
@@ -540,8 +588,10 @@ job.run # not saved
540
588
  job.run! # saved
541
589
  ```
542
590
 
543
- Saving includes running all validations on the `Job` class, and returns `true` if
544
- successful or `false` if errors occur. Exceptions are not raised.
591
+ Saving includes running all validations on the `Job` class. If
592
+ `whiny_persistence` flag is set to `true`, exception is raised in case of
593
+ failure. If `whiny_persistence` flag is set to false, methods with a bang return
594
+ `true` if the state transition is successful or `false` if an error occurs.
545
595
 
546
596
  If you want make sure the state gets saved without running validations (and
547
597
  thereby maybe persisting an invalid object state), simply tell AASM to skip the
@@ -632,7 +682,7 @@ to ```false```.
632
682
 
633
683
  ### Sequel
634
684
 
635
- AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_, _Mongoid_, and _MongoMapper_.
685
+ AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_, and _Mongoid_.
636
686
 
637
687
  ```ruby
638
688
  class Job < Sequel::Model
@@ -668,27 +718,12 @@ class Job
668
718
  end
669
719
  ```
670
720
 
671
- ### MongoMapper
672
-
673
- AASM also supports persistence to Mongodb if you're using MongoMapper. Make sure
674
- to include MongoMapper::Document before you include AASM.
675
-
676
- ```ruby
677
- class Job
678
- include MongoMapper::Document
679
- include AASM
680
-
681
- key :aasm_state, Symbol
682
- aasm do
683
- ...
684
- end
685
- end
686
- ```
687
-
688
721
  ### Redis
689
722
 
690
- AASM also supports persistence in Redis.
691
- Make sure to include Redis::Objects before you include AASM.
723
+ AASM also supports persistence in Redis via
724
+ [Redis::Objects](https://github.com/nateware/redis-objects).
725
+ Make sure to include Redis::Objects before you include AASM. Note that non-bang
726
+ events will work as bang events, persisting the changes on every call.
692
727
 
693
728
  ```ruby
694
729
  class User
@@ -868,6 +903,9 @@ class Job < ActiveRecord::Base
868
903
  ...
869
904
  end
870
905
 
906
+ aasm :another_state_machine, column: 'second_state' do
907
+ ...
908
+ end
871
909
  end
872
910
  ```
873
911
 
@@ -921,13 +959,13 @@ end
921
959
 
922
960
  ```ruby
923
961
  # show all states
924
- Job.aasm.states.map(&:name)
962
+ Job.aasm.states.map(&:name)
925
963
  #=> [:sleeping, :running, :cleaning]
926
964
 
927
965
  job = Job.new
928
966
 
929
967
  # show all permitted states (from initial state)
930
- job.aasm.states(:permitted => true).map(&:name)
968
+ job.aasm.states(:permitted => true).map(&:name)
931
969
  #=> [:running]
932
970
 
933
971
  job.run
@@ -935,7 +973,7 @@ job.aasm.states(:permitted => true).map(&:name)
935
973
  #=> [:sleeping]
936
974
 
937
975
  # show all non permitted states
938
- job.aasm.states(:permitted => false).map(&:name)
976
+ job.aasm.states(:permitted => false).map(&:name)
939
977
  #=> [:cleaning]
940
978
 
941
979
  # show all possible (triggerable) events from the current state
@@ -978,8 +1016,6 @@ class Job
978
1016
  end
979
1017
  ```
980
1018
 
981
- Be aware though, that this is not yet released. It will be part of _AASM_ version `4.11.0`.
982
-
983
1019
  ### RubyMotion support
984
1020
 
985
1021
  Now supports [CodeDataQuery](https://github.com/infinitered/cdq.git) !
@@ -994,7 +1030,9 @@ the 'instance method symbol / string' way whenever possible when defining guardi
994
1030
 
995
1031
  ### Testing
996
1032
 
997
- 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
1033
+ #### RSpec
1034
+
1035
+ 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:
998
1036
 
999
1037
  ```ruby
1000
1038
  # classes with only the default state machine
@@ -1030,6 +1068,90 @@ expect(multiple).to allow_transition_to(:processing).on(:move)
1030
1068
  expect(multiple).to_not allow_transition_to(:sleeping).on(:move)
1031
1069
  ```
1032
1070
 
1071
+ #### Minitest
1072
+
1073
+ AASM provides assertions and rspec-like expectations for [Minitest](https://github.com/seattlerb/minitest).
1074
+
1075
+ ##### Assertions
1076
+
1077
+ 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`.
1078
+
1079
+ Add `require 'aasm/minitest' to your `test_helper.rb` file and use them like this:
1080
+
1081
+ ```ruby
1082
+ # classes with only the default state machine
1083
+ job = Job.new
1084
+ assert_transitions_from job, :sleeping, to: :running, on_event: :run
1085
+ refute_transitions_from job, :sleeping, to: :cleaning, on_event: :run
1086
+ assert_have_state job, :sleeping
1087
+ refute_have_state job, :running
1088
+ assert_event_allowed job, :run
1089
+ refute_event_allowed job, :clean
1090
+ assert_transition_to_allowed job, :running
1091
+ refute_transition_to_allowed job, :cleaning
1092
+ # on_event also accept arguments
1093
+ assert_transitions_from job, :sleeping, :defragmentation, to: :running, on_event: :run
1094
+
1095
+ # classes with multiple state machine
1096
+ multiple = SimpleMultipleExample.new
1097
+ assert_transitions_from multiple, :standing, to: :walking, on_event: :walk, on: :move
1098
+ refute_transitions_from multiple, :standing, to: :running, on_event: :walk, on: :move
1099
+ assert_have_state multiple, :standing, on: :move
1100
+ refute_have_state multiple, :walking, on: :move
1101
+ assert_event_allowed multiple, :walk, on: :move
1102
+ refute_event_allowed multiple, :hold, on: :move
1103
+ assert_transition_to_allowed multiple, :walking, on: :move
1104
+ refute_transition_to_allowed multiple, :running, on: :move
1105
+ assert_transitions_from multiple, :sleeping, to: :processing, on_event: :start, on: :work
1106
+ refute_transitions_from multiple, :sleeping, to: :sleeping, on_event: :start, on: :work
1107
+ assert_have_state multiple, :sleeping, on: :work
1108
+ refute_have_state multiple, :processing, on: :work
1109
+ assert_event_allowed multiple, :start, on: :move
1110
+ refute_event_allowed multiple, :stop, on: :move
1111
+ assert_transition_to_allowed multiple, :processing, on: :move
1112
+ refute_transition_to_allowed multiple, :sleeping, on: :move
1113
+ ```
1114
+
1115
+ ##### Expectations
1116
+
1117
+ List of supported expectations: `must_transition_from`, `wont_transition_from`, `must_have_state`, `wont_have_state`, `must_allow_event`, `wont_allow_event`, `must_allow_transition_to`, `wont_allow_transition_to`.
1118
+
1119
+ Add `require 'aasm/minitest_spec'` to your `test_helper.rb` file and use them like this:
1120
+
1121
+ ```ruby
1122
+ # classes with only the default state machine
1123
+ job = Job.new
1124
+ job.must_transition_from :sleeping, to: :running, on_event: :run
1125
+ job.wont_transition_from :sleeping, to: :cleaning, on_event: :run
1126
+ job.must_have_state :sleeping
1127
+ job.wont_have_state :running
1128
+ job.must_allow_event :run
1129
+ job.wont_allow_event :clean
1130
+ job.must_allow_transition_to :running
1131
+ job.wont_allow_transition_to :cleaning
1132
+ # on_event also accept arguments
1133
+ job.must_transition_from :sleeping, :defragmentation, to: :running, on_event: :run
1134
+
1135
+ # classes with multiple state machine
1136
+ multiple = SimpleMultipleExample.new
1137
+ multiple.must_transition_from :standing, to: :walking, on_event: :walk, on: :move
1138
+ multiple.wont_transition_from :standing, to: :running, on_event: :walk, on: :move
1139
+ multiple.must_have_state :standing, on: :move
1140
+ multiple.wont_have_state :walking, on: :move
1141
+ multiple.must_allow_event :walk, on: :move
1142
+ multiple.wont_allow_event :hold, on: :move
1143
+ multiple.must_allow_transition_to :walking, on: :move
1144
+ multiple.wont_allow_transition_to :running, on: :move
1145
+ multiple.must_transition_from :sleeping, to: :processing, on_event: :start, on: :work
1146
+ multiple.wont_transition_from :sleeping, to: :sleeping, on_event: :start, on: :work
1147
+ multiple.must_have_state :sleeping, on: :work
1148
+ multiple.wont_have_state :processing, on: :work
1149
+ multiple.must_allow_event :start, on: :move
1150
+ multiple.wont_allow_event :stop, on: :move
1151
+ multiple.must_allow_transition_to :processing, on: :move
1152
+ multiple.wont_allow_transition_to :sleeping, on: :move
1153
+ ```
1154
+
1033
1155
  ## <a id="installation">Installation ##
1034
1156
 
1035
1157
  ### Manually from RubyGems.org ###
@@ -1083,14 +1205,7 @@ Feel free to
1083
1205
  * [Anil Maurya](http://github.com/anilmaurya) (since 2016)
1084
1206
 
1085
1207
 
1086
- ## Contributing ##
1087
-
1088
- 1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
1089
- 2. Fork it
1090
- 3. Create your feature branch (git checkout -b my-new-feature)
1091
- 4. Commit your changes (git commit -am 'Added some feature')
1092
- 5. Push to the branch (git push origin my-new-feature)
1093
- 6. Create new Pull Request
1208
+ ## [Contributing](CONTRIBUTING.md)
1094
1209
 
1095
1210
  ## Warranty ##
1096
1211
 
data/Rakefile CHANGED
@@ -23,4 +23,9 @@ Rake::RDocTask.new do |rdoc|
23
23
  rdoc.rdoc_files.include('lib/**/*.rb')
24
24
  end
25
25
 
26
- task :default => :spec
26
+ if ENV["APPRAISAL_INITIALIZED"] || ENV["TRAVIS"]
27
+ task :default => :spec
28
+ else
29
+ require 'appraisal'
30
+ task :default => :appraisal
31
+ end
data/TESTING.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Install dependency matrix
2
+
3
+ appraisal install
4
+
5
+ This will re-generate Gemfiles in `gemfile` folder
6
+
7
+ Use rvm gemsets or similar to avoid global gem pollution
8
+
9
+ ## Run specs
10
+
11
+ For all supported Rails/ORM combinations:
12
+
13
+ appraisal rspec
14
+
15
+ Or for specific one:
16
+
17
+ appraisal rails_4.2 rspec
18
+
19
+ Or for one particular test file
20
+
21
+ appraisal rails_4.2_mongoid_5 rspec spec/unit/persistence/mongoid_persistence_multiple_spec.rb
22
+
23
+ Or down to one test case
24
+
25
+ appraisal rails_4.2_mongoid_5 rspec spec/unit/persistence/mongoid_persistence_multiple_spec.rb:92
data/aasm.gemspec CHANGED
@@ -16,10 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.platform = Gem::Platform::RUBY
17
17
  s.required_ruby_version = '>= 1.9.3'
18
18
 
19
+ s.add_dependency 'concurrent-ruby', '~> 1.0'
20
+
19
21
  s.add_development_dependency 'rake'
20
22
  s.add_development_dependency 'sdoc'
21
23
  s.add_development_dependency 'rspec', ">= 3"
22
24
  s.add_development_dependency 'generator_spec'
25
+ s.add_development_dependency 'appraisal'
23
26
 
24
27
  # debugging
25
28
  # s.add_development_dependency 'debugger'
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", :platforms => :ruby
6
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
+ gem "rails", "~>3.2.22"
8
+ gem "mongoid", "~>3.1"
9
+ gem "sequel"
10
+ gem "bson_ext", :platforms => :ruby
11
+ gem "test-unit", "~> 3.0"
12
+
13
+ gemspec :path => "../"
@@ -1,16 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.0.13"
10
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
9
+ gem "mongoid", "~>4.0"
10
+ gem "sequel"
11
+ gem "dynamoid", "~> 1", :platforms => :ruby
12
+ gem "aws-sdk", "~>2", :platforms => :ruby
14
13
  gem "redis-objects"
15
14
 
16
15
  gemspec :path => "../"
@@ -1,15 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.2.5"
10
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "nokogiri", "1.6.8.1", :platforms => [:ruby_19]
9
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
10
+ gem "mongoid", "~>4.0"
11
+ gem "sequel"
12
+ gem "dynamoid", "~> 1", :platforms => :ruby
13
+ gem "aws-sdk", "~>2", :platforms => :ruby
14
+ gem "redis-objects"
14
15
 
15
16
  gemspec :path => "../"
@@ -1,15 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.2.5"
10
- gem 'mongoid', '~>5.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
9
+ gem "mongoid", "~>5.0"
14
10
 
15
11
  gemspec :path => "../"