aasm 4.11.1 → 5.2.0

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 (194) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.travis.yml +56 -23
  5. data/Appraisals +67 -0
  6. data/CHANGELOG.md +112 -0
  7. data/CONTRIBUTING.md +24 -0
  8. data/Dockerfile +44 -0
  9. data/Gemfile +3 -21
  10. data/Gemfile.lock_old +151 -0
  11. data/LICENSE +1 -1
  12. data/README.md +540 -139
  13. data/Rakefile +6 -1
  14. data/TESTING.md +25 -0
  15. data/aasm.gemspec +5 -0
  16. data/docker-compose.yml +40 -0
  17. data/gemfiles/norails.gemfile +10 -0
  18. data/gemfiles/rails_4.2.gemfile +13 -11
  19. data/gemfiles/rails_4.2_mongoid_5.gemfile +8 -11
  20. data/gemfiles/rails_4.2_nobrainer.gemfile +9 -0
  21. data/gemfiles/rails_5.0.gemfile +11 -18
  22. data/gemfiles/rails_5.0_nobrainer.gemfile +9 -0
  23. data/gemfiles/rails_5.1.gemfile +14 -0
  24. data/gemfiles/rails_5.2.gemfile +14 -0
  25. data/lib/aasm/aasm.rb +40 -29
  26. data/lib/aasm/base.rb +61 -11
  27. data/lib/aasm/configuration.rb +10 -0
  28. data/lib/aasm/core/event.rb +45 -37
  29. data/lib/aasm/core/invoker.rb +129 -0
  30. data/lib/aasm/core/invokers/base_invoker.rb +75 -0
  31. data/lib/aasm/core/invokers/class_invoker.rb +52 -0
  32. data/lib/aasm/core/invokers/literal_invoker.rb +47 -0
  33. data/lib/aasm/core/invokers/proc_invoker.rb +59 -0
  34. data/lib/aasm/core/state.rb +22 -13
  35. data/lib/aasm/core/transition.rb +17 -69
  36. data/lib/aasm/dsl_helper.rb +24 -22
  37. data/lib/aasm/errors.rb +4 -6
  38. data/lib/aasm/instance_base.rb +22 -4
  39. data/lib/aasm/localizer.rb +13 -3
  40. data/lib/aasm/minitest/allow_event.rb +13 -0
  41. data/lib/aasm/minitest/allow_transition_to.rb +13 -0
  42. data/lib/aasm/minitest/have_state.rb +13 -0
  43. data/lib/aasm/minitest/transition_from.rb +21 -0
  44. data/lib/aasm/minitest.rb +5 -0
  45. data/lib/aasm/minitest_spec.rb +15 -0
  46. data/lib/aasm/persistence/active_record_persistence.rb +49 -105
  47. data/lib/aasm/persistence/base.rb +20 -5
  48. data/lib/aasm/persistence/core_data_query_persistence.rb +2 -1
  49. data/lib/aasm/persistence/dynamoid_persistence.rb +1 -1
  50. data/lib/aasm/persistence/mongoid_persistence.rb +26 -32
  51. data/lib/aasm/persistence/no_brainer_persistence.rb +105 -0
  52. data/lib/aasm/persistence/orm.rb +154 -0
  53. data/lib/aasm/persistence/plain_persistence.rb +2 -1
  54. data/lib/aasm/persistence/redis_persistence.rb +16 -11
  55. data/lib/aasm/persistence/sequel_persistence.rb +36 -64
  56. data/lib/aasm/persistence.rb +3 -3
  57. data/lib/aasm/rspec/allow_event.rb +5 -1
  58. data/lib/aasm/rspec/allow_transition_to.rb +5 -1
  59. data/lib/aasm/rspec/transition_from.rb +5 -1
  60. data/lib/aasm/state_machine.rb +4 -2
  61. data/lib/aasm/state_machine_store.rb +5 -2
  62. data/lib/aasm/version.rb +1 -1
  63. data/lib/aasm.rb +5 -2
  64. data/lib/generators/aasm/orm_helpers.rb +6 -0
  65. data/lib/generators/active_record/aasm_generator.rb +3 -1
  66. data/lib/generators/active_record/templates/migration.rb +1 -1
  67. data/lib/generators/active_record/templates/migration_existing.rb +1 -1
  68. data/lib/generators/nobrainer/aasm_generator.rb +28 -0
  69. data/lib/motion-aasm.rb +3 -1
  70. data/spec/database.rb +20 -7
  71. data/spec/en.yml +0 -3
  72. data/spec/generators/active_record_generator_spec.rb +49 -40
  73. data/spec/generators/mongoid_generator_spec.rb +4 -6
  74. data/spec/generators/no_brainer_generator_spec.rb +29 -0
  75. data/spec/{en_deprecated_style.yml → localizer_test_model_deprecated_style.yml} +6 -3
  76. data/spec/localizer_test_model_new_style.yml +11 -0
  77. data/spec/models/active_record/active_record_callback.rb +93 -0
  78. data/spec/models/active_record/complex_active_record_example.rb +5 -1
  79. data/spec/models/active_record/instance_level_skip_validation_example.rb +19 -0
  80. data/spec/models/{invalid_persistor.rb → active_record/invalid_persistor.rb} +0 -2
  81. data/spec/models/active_record/localizer_test_model.rb +11 -3
  82. data/spec/models/active_record/namespaced.rb +16 -0
  83. data/spec/models/active_record/person.rb +23 -0
  84. data/spec/models/{silent_persistor.rb → active_record/silent_persistor.rb} +0 -2
  85. data/spec/models/active_record/simple_new_dsl.rb +15 -0
  86. data/spec/models/active_record/timestamp_example.rb +16 -0
  87. data/spec/models/{transactor.rb → active_record/transactor.rb} +25 -2
  88. data/spec/models/{validator.rb → active_record/validator.rb} +0 -2
  89. data/spec/models/active_record/work.rb +3 -0
  90. data/spec/models/{worker.rb → active_record/worker.rb} +0 -0
  91. data/spec/models/callbacks/basic.rb +5 -2
  92. data/spec/models/callbacks/with_state_arg.rb +5 -1
  93. data/spec/models/callbacks/with_state_arg_multiple.rb +4 -1
  94. data/spec/models/default_state.rb +1 -1
  95. data/spec/models/guard_arguments_check.rb +17 -0
  96. data/spec/models/guard_with_params.rb +1 -1
  97. data/spec/models/guardian_without_from_specified.rb +18 -0
  98. data/spec/models/mongoid/invalid_persistor_mongoid.rb +39 -0
  99. data/spec/models/mongoid/silent_persistor_mongoid.rb +39 -0
  100. data/spec/models/mongoid/timestamp_example_mongoid.rb +20 -0
  101. data/spec/models/mongoid/validator_mongoid.rb +100 -0
  102. data/spec/models/multiple_transitions_that_differ_only_by_guard.rb +31 -0
  103. data/spec/models/namespaced_multiple_example.rb +14 -0
  104. data/spec/models/nobrainer/complex_no_brainer_example.rb +36 -0
  105. data/spec/models/nobrainer/invalid_persistor_no_brainer.rb +39 -0
  106. data/spec/models/nobrainer/no_scope_no_brainer.rb +21 -0
  107. data/spec/models/nobrainer/nobrainer_relationships.rb +25 -0
  108. data/spec/models/nobrainer/silent_persistor_no_brainer.rb +39 -0
  109. data/spec/models/nobrainer/simple_new_dsl_nobrainer.rb +25 -0
  110. data/spec/models/{mongo_mapper/simple_mongo_mapper.rb → nobrainer/simple_no_brainer.rb} +8 -8
  111. data/spec/models/nobrainer/validator_no_brainer.rb +98 -0
  112. data/spec/models/parametrised_event.rb +7 -0
  113. data/spec/models/{mongo_mapper/complex_mongo_mapper_example.rb → redis/complex_redis_example.rb} +8 -5
  114. data/spec/models/redis/redis_multiple.rb +20 -0
  115. data/spec/models/redis/redis_simple.rb +20 -0
  116. data/spec/models/sequel/complex_sequel_example.rb +4 -3
  117. data/spec/models/sequel/invalid_persistor.rb +52 -0
  118. data/spec/models/sequel/sequel_multiple.rb +13 -13
  119. data/spec/models/sequel/sequel_simple.rb +13 -12
  120. data/spec/models/sequel/silent_persistor.rb +50 -0
  121. data/spec/models/sequel/transactor.rb +112 -0
  122. data/spec/models/sequel/validator.rb +93 -0
  123. data/spec/models/sequel/worker.rb +12 -0
  124. data/spec/models/simple_example.rb +8 -0
  125. data/spec/models/simple_example_with_guard_args.rb +17 -0
  126. data/spec/models/simple_multiple_example.rb +12 -0
  127. data/spec/models/sub_class.rb +34 -0
  128. data/spec/models/timestamps_example.rb +19 -0
  129. data/spec/models/timestamps_with_named_machine_example.rb +13 -0
  130. data/spec/spec_helper.rb +15 -33
  131. data/spec/spec_helpers/active_record.rb +8 -0
  132. data/spec/spec_helpers/dynamoid.rb +35 -0
  133. data/spec/spec_helpers/mongoid.rb +26 -0
  134. data/spec/spec_helpers/nobrainer.rb +15 -0
  135. data/spec/spec_helpers/redis.rb +18 -0
  136. data/spec/spec_helpers/remove_warnings.rb +1 -0
  137. data/spec/spec_helpers/sequel.rb +7 -0
  138. data/spec/unit/abstract_class_spec.rb +27 -0
  139. data/spec/unit/api_spec.rb +79 -72
  140. data/spec/unit/callback_multiple_spec.rb +7 -3
  141. data/spec/unit/callbacks_spec.rb +37 -2
  142. data/spec/unit/complex_example_spec.rb +12 -3
  143. data/spec/unit/complex_multiple_example_spec.rb +20 -4
  144. data/spec/unit/event_multiple_spec.rb +1 -1
  145. data/spec/unit/event_spec.rb +29 -4
  146. data/spec/unit/exception_spec.rb +1 -1
  147. data/spec/unit/guard_arguments_check_spec.rb +9 -0
  148. data/spec/unit/guard_spec.rb +17 -0
  149. data/spec/unit/guard_with_params_spec.rb +4 -0
  150. data/spec/unit/guard_without_from_specified_spec.rb +10 -0
  151. data/spec/unit/inspection_multiple_spec.rb +9 -5
  152. data/spec/unit/inspection_spec.rb +7 -3
  153. data/spec/unit/invoker_spec.rb +189 -0
  154. data/spec/unit/invokers/base_invoker_spec.rb +72 -0
  155. data/spec/unit/invokers/class_invoker_spec.rb +95 -0
  156. data/spec/unit/invokers/literal_invoker_spec.rb +86 -0
  157. data/spec/unit/invokers/proc_invoker_spec.rb +86 -0
  158. data/spec/unit/localizer_spec.rb +85 -52
  159. data/spec/unit/multiple_transitions_that_differ_only_by_guard_spec.rb +14 -0
  160. data/spec/unit/namespaced_multiple_example_spec.rb +22 -0
  161. data/spec/unit/override_warning_spec.rb +8 -0
  162. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +468 -447
  163. data/spec/unit/persistence/active_record_persistence_spec.rb +639 -486
  164. data/spec/unit/persistence/dynamoid_persistence_multiple_spec.rb +4 -9
  165. data/spec/unit/persistence/dynamoid_persistence_spec.rb +4 -9
  166. data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +83 -13
  167. data/spec/unit/persistence/mongoid_persistence_spec.rb +97 -13
  168. data/spec/unit/persistence/no_brainer_persistence_multiple_spec.rb +198 -0
  169. data/spec/unit/persistence/no_brainer_persistence_spec.rb +158 -0
  170. data/spec/unit/persistence/redis_persistence_multiple_spec.rb +88 -0
  171. data/spec/unit/persistence/redis_persistence_spec.rb +8 -32
  172. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +6 -11
  173. data/spec/unit/persistence/sequel_persistence_spec.rb +278 -10
  174. data/spec/unit/rspec_matcher_spec.rb +9 -0
  175. data/spec/unit/simple_example_spec.rb +15 -0
  176. data/spec/unit/simple_multiple_example_spec.rb +28 -0
  177. data/spec/unit/state_spec.rb +23 -7
  178. data/spec/unit/subclassing_multiple_spec.rb +37 -2
  179. data/spec/unit/subclassing_spec.rb +17 -2
  180. data/spec/unit/timestamps_spec.rb +32 -0
  181. data/spec/unit/transition_spec.rb +1 -1
  182. data/test/minitest_helper.rb +57 -0
  183. data/test/unit/minitest_matcher_test.rb +80 -0
  184. metadata +213 -37
  185. data/callbacks.txt +0 -51
  186. data/gemfiles/rails_3.2_stable.gemfile +0 -15
  187. data/gemfiles/rails_4.0.gemfile +0 -16
  188. data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -16
  189. data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -17
  190. data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -163
  191. data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
  192. data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
  193. data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -149
  194. data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -96
@@ -0,0 +1,39 @@
1
+ class SilentPersistorMongoid
2
+ include Mongoid::Document
3
+ include AASM
4
+
5
+ field :name
6
+ field :status
7
+
8
+ aasm :left, column: :status, whiny_persistence: false do
9
+ state :sleeping, :initial => true
10
+ state :running
11
+ event :run do
12
+ transitions :to => :running, :from => :sleeping
13
+ end
14
+ event :sleep do
15
+ transitions :to => :sleeping, :from => :running
16
+ end
17
+ end
18
+ validates_presence_of :name
19
+ end
20
+
21
+ class MultipleSilentPersistorMongoid
22
+ include Mongoid::Document
23
+ include AASM
24
+
25
+ field :name
26
+ field :status
27
+
28
+ aasm :left, column: :status, whiny_persistence: false do
29
+ state :sleeping, :initial => true
30
+ state :running
31
+ event :run do
32
+ transitions :to => :running, :from => :sleeping
33
+ end
34
+ event :sleep do
35
+ transitions :to => :sleeping, :from => :running
36
+ end
37
+ end
38
+ validates_presence_of :name
39
+ end
@@ -0,0 +1,20 @@
1
+ class TimestampExampleMongoid
2
+ include Mongoid::Document
3
+ include AASM
4
+
5
+ field :status, type: String
6
+ field :opened_at, type: Time
7
+
8
+ aasm column: :status, timestamps: true do
9
+ state :opened
10
+ state :closed
11
+
12
+ event :open do
13
+ transitions to: :opened
14
+ end
15
+
16
+ event :close do
17
+ transitions to: :closed
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,100 @@
1
+ class ValidatorMongoid
2
+ include Mongoid::Document
3
+ include AASM
4
+
5
+ field :name
6
+ field :status
7
+
8
+ attr_accessor :invalid
9
+
10
+ validate do |model|
11
+ errors.add(:validator, "invalid") if invalid
12
+ end
13
+
14
+ include AASM
15
+
16
+ aasm :column => :status, :whiny_persistence => true do
17
+ before_all_transactions :before_all_transactions
18
+ after_all_transactions :after_all_transactions
19
+
20
+ state :sleeping, :initial => true
21
+ state :running
22
+ state :failed, :after_enter => :fail
23
+
24
+ event :run, :after_commit => :change_name! do
25
+ transitions :to => :running, :from => :sleeping
26
+ end
27
+
28
+ event :sleep do
29
+ after_commit do |name|
30
+ change_name_on_sleep name
31
+ end
32
+ transitions :to => :sleeping, :from => :running
33
+ end
34
+
35
+ event :fail do
36
+ transitions :to => :failed, :from => [:sleeping, :running]
37
+ end
38
+ end
39
+
40
+ validates_presence_of :name
41
+
42
+ def change_name!
43
+ self.name = "name changed"
44
+ save!
45
+ end
46
+
47
+ def change_name_on_sleep name
48
+ self.name = name
49
+ save!
50
+ end
51
+
52
+ def fail
53
+ raise StandardError.new('failed on purpose')
54
+ end
55
+ end
56
+
57
+ class MultipleValidatorMongoid
58
+ include Mongoid::Document
59
+ include AASM
60
+
61
+ field :name
62
+ field :status
63
+
64
+ attr_accessor :invalid
65
+
66
+ aasm :left, :column => :status, :whiny_persistence => true do
67
+ state :sleeping, :initial => true
68
+ state :running
69
+ state :failed, :after_enter => :fail
70
+
71
+ event :run, :after_commit => :change_name! do
72
+ transitions :to => :running, :from => :sleeping
73
+ end
74
+ event :sleep do
75
+ after_commit do |name|
76
+ change_name_on_sleep name
77
+ end
78
+ transitions :to => :sleeping, :from => :running
79
+ end
80
+ event :fail do
81
+ transitions :to => :failed, :from => [:sleeping, :running]
82
+ end
83
+ end
84
+
85
+ validates_presence_of :name
86
+
87
+ def change_name!
88
+ self.name = "name changed"
89
+ save!
90
+ end
91
+
92
+ def change_name_on_sleep name
93
+ self.name = name
94
+ save!
95
+ end
96
+
97
+ def fail
98
+ raise StandardError.new('failed on purpose')
99
+ end
100
+ end
@@ -0,0 +1,31 @@
1
+ class MultipleTransitionsThatDifferOnlyByGuard
2
+ include AASM
3
+
4
+ attr_accessor :executed_second
5
+
6
+ aasm do
7
+ state :start, :initial => true
8
+ state :gone
9
+
10
+ event :go do
11
+ transitions :from => :start, :to => :gone, :guard => :returns_false, :after => :this_should_not_execute
12
+ transitions :from => :start, :to => :gone, :guard => :returns_true, :after => :this_should_execute
13
+ end
14
+ end
15
+
16
+ def returns_false
17
+ false
18
+ end
19
+
20
+ def returns_true
21
+ true
22
+ end
23
+
24
+ def this_should_not_execute
25
+ raise RuntimeError, "This should not execute"
26
+ end
27
+
28
+ def this_should_execute
29
+ self.executed_second = true
30
+ end
31
+ end
@@ -25,4 +25,18 @@ class NamespacedMultipleExample
25
25
  transitions :from => :approved, :to => :unapproved
26
26
  end
27
27
  end
28
+
29
+ # Test namespace event methods with suffix (ie may_sell_car?, sell_car!)
30
+ aasm(:car, namespace: :car) do
31
+ state :unsold, :initial => true
32
+ state :sold
33
+
34
+ event :sell do
35
+ transitions :from => :unsold, :to => :sold
36
+ end
37
+
38
+ event :return do
39
+ transitions :from => :sold, :to => :unsold
40
+ end
41
+ end
28
42
  end
@@ -0,0 +1,36 @@
1
+ class ComplexNoBrainerExample
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :left, type: String
6
+ field :right, type: String
7
+
8
+ aasm :left, column: 'left' do
9
+ state :one, initial: true
10
+ state :two
11
+ state :three
12
+
13
+ event :increment do
14
+ transitions from: :one, to: :two
15
+ transitions from: :two, to: :three
16
+ end
17
+ event :reset do
18
+ transitions from: :three, to: :one
19
+ end
20
+ end
21
+
22
+ aasm :right, column: 'right' do
23
+ state :alpha, initial: true
24
+ state :beta
25
+ state :gamma
26
+
27
+ event :level_up do
28
+ transitions from: :alpha, to: :beta
29
+ transitions from: :beta, to: :gamma
30
+ end
31
+ event :level_down do
32
+ transitions from: :gamma, to: :beta
33
+ transitions from: :beta, to: :alpha
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ class InvalidPersistorNoBrainer
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :name
6
+ field :status
7
+
8
+ aasm :left, column: :status, skip_validation_on_save: true do
9
+ state :sleeping, initial: true
10
+ state :running
11
+ event :run do
12
+ transitions to: :running, from: :sleeping
13
+ end
14
+ event :sleep do
15
+ transitions to: :sleeping, from: :running
16
+ end
17
+ end
18
+ validates_presence_of :name
19
+ end
20
+
21
+ class MultipleInvalidPersistorNoBrainer
22
+ include NoBrainer::Document
23
+ include AASM
24
+
25
+ field :name
26
+ field :status
27
+
28
+ aasm :left, column: :status, skip_validation_on_save: true do
29
+ state :sleeping, initial: true
30
+ state :running
31
+ event :run do
32
+ transitions to: :running, from: :sleeping
33
+ end
34
+ event :sleep do
35
+ transitions to: :sleeping, from: :running
36
+ end
37
+ end
38
+ validates_presence_of :name
39
+ end
@@ -0,0 +1,21 @@
1
+ class NoScopeNoBrainer
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :status, type: String
6
+
7
+ aasm create_scopes: false, column: :status do
8
+ state :ignored_scope
9
+ end
10
+ end
11
+
12
+ class NoScopeNoBrainerMultiple
13
+ include NoBrainer::Document
14
+ include AASM
15
+
16
+ field :status, type: String
17
+
18
+ aasm :left, create_scopes: false, column: :status do
19
+ state :ignored_scope
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ class Parent
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :status, type: String
6
+ has_many :childs
7
+
8
+ aasm column: :status do
9
+ state :unknown_scope
10
+ state :new
11
+ end
12
+ end
13
+
14
+ class Child
15
+ include NoBrainer::Document
16
+ include AASM
17
+
18
+ field :status, type: String
19
+ belongs_to :parent
20
+
21
+ aasm column: :status do
22
+ state :unknown_scope
23
+ state :new
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ class SilentPersistorNoBrainer
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :name
6
+ field :status
7
+
8
+ aasm :left, column: :status, whiny_persistence: false do
9
+ state :sleeping, initial: true
10
+ state :running
11
+ event :run do
12
+ transitions to: :running, from: :sleeping
13
+ end
14
+ event :sleep do
15
+ transitions to: :sleeping, from: :running
16
+ end
17
+ end
18
+ validates_presence_of :name
19
+ end
20
+
21
+ class MultipleSilentPersistorNoBrainer
22
+ include NoBrainer::Document
23
+ include AASM
24
+
25
+ field :name
26
+ field :status
27
+
28
+ aasm :left, column: :status, whiny_persistence: false do
29
+ state :sleeping, initial: true
30
+ state :running
31
+ event :run do
32
+ transitions to: :running, from: :sleeping
33
+ end
34
+ event :sleep do
35
+ transitions to: :sleeping, from: :running
36
+ end
37
+ end
38
+ validates_presence_of :name
39
+ end
@@ -0,0 +1,25 @@
1
+ class SimpleNewDslNoBrainer
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :status, type: String
6
+
7
+ aasm column: :status
8
+ aasm do
9
+ state :unknown_scope, initial: true
10
+ state :new
11
+ end
12
+ end
13
+
14
+ class SimpleNewDslNoBrainerMultiple
15
+ include NoBrainer::Document
16
+ include AASM
17
+
18
+ field :status, type: String
19
+
20
+ aasm :left, column: :status
21
+ aasm :left do
22
+ state :unknown_scope, initial: true
23
+ state :new
24
+ end
25
+ end
@@ -1,23 +1,23 @@
1
- class SimpleMongoMapper
2
- include MongoMapper::Document
1
+ class SimpleNoBrainer
2
+ include NoBrainer::Document
3
3
  include AASM
4
4
 
5
- key :status, String
5
+ field :status, type: String
6
6
 
7
7
  aasm column: :status do
8
8
  state :unknown_scope, :another_unknown_scope
9
- state :next
9
+ state :new
10
10
  end
11
11
  end
12
12
 
13
- class SimpleMongoMapperMultiple
14
- include MongoMapper::Document
13
+ class SimpleNoBrainerMultiple
14
+ include NoBrainer::Document
15
15
  include AASM
16
16
 
17
- key :status, String
17
+ field :status, type: String
18
18
 
19
19
  aasm :left, column: :status do
20
20
  state :unknown_scope, :another_unknown_scope
21
- state :next
21
+ state :new
22
22
  end
23
23
  end
@@ -0,0 +1,98 @@
1
+ class ValidatorNoBrainer
2
+ include NoBrainer::Document
3
+ include AASM
4
+
5
+ field :name
6
+ field :status
7
+
8
+ attr_accessor :invalid
9
+
10
+ validate do |_|
11
+ errors.add(:validator, 'invalid') if invalid
12
+ end
13
+
14
+ aasm column: :status, whiny_persistence: true do
15
+ before_all_transactions :before_all_transactions
16
+ after_all_transactions :after_all_transactions
17
+
18
+ state :sleeping, initial: true
19
+ state :running
20
+ state :failed, after_enter: :fail
21
+
22
+ event :run, after_commit: :change_name! do
23
+ transitions to: :running, from: :sleeping
24
+ end
25
+
26
+ event :sleep do
27
+ after_commit do |name|
28
+ change_name_on_sleep name
29
+ end
30
+ transitions to: :sleeping, from: :running
31
+ end
32
+
33
+ event :fail do
34
+ transitions to: :failed, from: %i[sleeping running]
35
+ end
36
+ end
37
+
38
+ validates_presence_of :name
39
+
40
+ def change_name!
41
+ self.name = 'name changed'
42
+ save!
43
+ end
44
+
45
+ def change_name_on_sleep(name)
46
+ self.name = name
47
+ save!
48
+ end
49
+
50
+ def fail
51
+ raise StandardError, 'failed on purpose'
52
+ end
53
+ end
54
+
55
+ class MultipleValidatorNoBrainer
56
+ include NoBrainer::Document
57
+ include AASM
58
+
59
+ field :name
60
+ field :status
61
+
62
+ attr_accessor :invalid
63
+
64
+ aasm :left, column: :status, whiny_persistence: true do
65
+ state :sleeping, initial: true
66
+ state :running
67
+ state :failed, after_enter: :fail
68
+
69
+ event :run, after_commit: :change_name! do
70
+ transitions to: :running, from: :sleeping
71
+ end
72
+ event :sleep do
73
+ after_commit do |name|
74
+ change_name_on_sleep name
75
+ end
76
+ transitions to: :sleeping, from: :running
77
+ end
78
+ event :fail do
79
+ transitions to: :failed, from: %i[sleeping running]
80
+ end
81
+ end
82
+
83
+ validates_presence_of :name
84
+
85
+ def change_name!
86
+ self.name = 'name changed'
87
+ save!
88
+ end
89
+
90
+ def change_name_on_sleep(name)
91
+ self.name = name
92
+ save!
93
+ end
94
+
95
+ def fail
96
+ raise StandardError, 'failed on purpose'
97
+ end
98
+ end
@@ -11,6 +11,10 @@ class ParametrisedEvent
11
11
  transitions :from => :sleeping, :to => [:showering, :working]
12
12
  end
13
13
 
14
+ event :shower do
15
+ transitions :from => :sleeping, :to => :showering, :after => :wet_hair, :success => :wear_clothes
16
+ end
17
+
14
18
  event :dress do
15
19
  transitions :from => :sleeping, :to => :working, :after => :wear_clothes, :success => :wear_makeup
16
20
  transitions :from => :showering, :to => [:working, :dating], :after => Proc.new { |*args| wear_clothes(*args) }, :success => proc { |*args| wear_makeup(*args) }
@@ -24,6 +28,9 @@ class ParametrisedEvent
24
28
  def wear_makeup(makeup, moisturizer)
25
29
  end
26
30
 
31
+ def wet_hair(dryer)
32
+ end
33
+
27
34
  def condition_hair
28
35
  end
29
36
 
@@ -1,9 +1,13 @@
1
- class ComplexMongoMapperExample
2
- include MongoMapper::Document
1
+ class RedisComplexExample
2
+ include Redis::Objects
3
3
  include AASM
4
4
 
5
- key :left, String
6
- key :right, String
5
+ value :left
6
+ value :right
7
+
8
+ def id
9
+ 1
10
+ end
7
11
 
8
12
  aasm :left, :column => 'left' do
9
13
  state :one, :initial => true
@@ -33,5 +37,4 @@ class ComplexMongoMapperExample
33
37
  transitions :from => :beta, :to => :alpha
34
38
  end
35
39
  end
36
-
37
40
  end
@@ -0,0 +1,20 @@
1
+ class RedisMultiple
2
+ include Redis::Objects
3
+ include AASM
4
+
5
+ value :status
6
+
7
+ def id
8
+ 1
9
+ end
10
+
11
+ aasm :left, :column => :status
12
+ aasm :left do
13
+ state :alpha, :initial => true
14
+ state :beta
15
+ state :gamma
16
+ event :release do
17
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ class RedisSimple
2
+ include Redis::Objects
3
+ include AASM
4
+
5
+ value :status
6
+
7
+ def id
8
+ 1
9
+ end
10
+
11
+ aasm :column => :status
12
+ aasm do
13
+ state :alpha, :initial => true
14
+ state :beta
15
+ state :gamma
16
+ event :release do
17
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
- db = Sequel.connect(SEQUEL_DB)
1
+ db = Sequel::DATABASES.first || Sequel.connect(SEQUEL_DB)
2
2
 
3
3
  # if you want to see the statements while running the spec enable the following line
4
4
  # db.loggers << Logger.new($stderr)
@@ -8,8 +8,8 @@ db.create_table(:complex_sequel_examples) do
8
8
  String :right
9
9
  end
10
10
 
11
- class ComplexSequelExample < Sequel::Model(db)
12
- set_dataset(:complex_sequel_examples)
11
+ module Sequel
12
+ class ComplexExample < Sequel::Model(:complex_sequel_examples)
13
13
 
14
14
  include AASM
15
15
 
@@ -43,3 +43,4 @@ class ComplexSequelExample < Sequel::Model(db)
43
43
  end
44
44
 
45
45
  end
46
+ end
@@ -0,0 +1,52 @@
1
+ db = Sequel::DATABASES.first || Sequel.connect(SEQUEL_DB)
2
+
3
+ [:invalid_persistors, :multiple_invalid_persistors].each do |table_name|
4
+ db.create_table(table_name) do
5
+ primary_key :id
6
+ String "name"
7
+ String "status"
8
+ end
9
+ end
10
+
11
+ module Sequel
12
+ class InvalidPersistor < Sequel::Model(:invalid_persistors)
13
+ plugin :validation_helpers
14
+
15
+ include AASM
16
+ aasm :column => :status, :skip_validation_on_save => true do
17
+ state :sleeping, :initial => true
18
+ state :running
19
+ event :run do
20
+ transitions :to => :running, :from => :sleeping
21
+ end
22
+ event :sleep do
23
+ transitions :to => :sleeping, :from => :running
24
+ end
25
+ end
26
+
27
+ def validate
28
+ super
29
+ validates_presence :name
30
+ end
31
+ end
32
+
33
+ class MultipleInvalidPersistor < Sequel::Model(:multiple_invalid_persistors)
34
+ plugin :validation_helpers
35
+
36
+ include AASM
37
+ aasm :left, :column => :status, :skip_validation_on_save => true do
38
+ state :sleeping, :initial => true
39
+ state :running
40
+ event :run do
41
+ transitions :to => :running, :from => :sleeping
42
+ end
43
+ event :sleep do
44
+ transitions :to => :sleeping, :from => :running
45
+ end
46
+ end
47
+ def validate
48
+ super
49
+ validates_presence :name
50
+ end
51
+ end
52
+ end