aasm 4.5.1 → 5.5.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 (186) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/README.md +809 -129
  4. data/lib/aasm/aasm.rb +74 -37
  5. data/lib/aasm/base.rb +188 -41
  6. data/lib/aasm/configuration.rb +27 -2
  7. data/lib/aasm/core/event.rb +75 -47
  8. data/lib/aasm/core/invoker.rb +129 -0
  9. data/lib/aasm/core/invokers/base_invoker.rb +75 -0
  10. data/lib/aasm/core/invokers/class_invoker.rb +52 -0
  11. data/lib/aasm/core/invokers/literal_invoker.rb +49 -0
  12. data/lib/aasm/core/invokers/proc_invoker.rb +59 -0
  13. data/lib/aasm/core/state.rb +22 -13
  14. data/lib/aasm/core/transition.rb +30 -23
  15. data/lib/aasm/dsl_helper.rb +24 -22
  16. data/lib/aasm/errors.rb +8 -5
  17. data/lib/aasm/instance_base.rb +63 -15
  18. data/lib/aasm/localizer.rb +13 -3
  19. data/lib/aasm/minitest/allow_event.rb +13 -0
  20. data/lib/aasm/minitest/allow_transition_to.rb +13 -0
  21. data/lib/aasm/minitest/have_state.rb +13 -0
  22. data/lib/aasm/minitest/transition_from.rb +21 -0
  23. data/lib/aasm/minitest.rb +5 -0
  24. data/lib/aasm/minitest_spec.rb +15 -0
  25. data/lib/aasm/persistence/active_record_persistence.rb +87 -79
  26. data/lib/aasm/persistence/base.rb +30 -30
  27. data/lib/aasm/persistence/core_data_query_persistence.rb +94 -0
  28. data/lib/aasm/persistence/dynamoid_persistence.rb +92 -0
  29. data/lib/aasm/persistence/mongoid_persistence.rb +49 -35
  30. data/lib/aasm/persistence/no_brainer_persistence.rb +105 -0
  31. data/lib/aasm/persistence/orm.rb +154 -0
  32. data/lib/aasm/persistence/plain_persistence.rb +2 -1
  33. data/lib/aasm/persistence/redis_persistence.rb +112 -0
  34. data/lib/aasm/persistence/sequel_persistence.rb +37 -67
  35. data/lib/aasm/persistence.rb +20 -5
  36. data/lib/aasm/rspec/allow_event.rb +5 -1
  37. data/lib/aasm/rspec/allow_transition_to.rb +5 -1
  38. data/lib/aasm/rspec/transition_from.rb +8 -4
  39. data/lib/aasm/state_machine.rb +6 -12
  40. data/lib/aasm/state_machine_store.rb +76 -0
  41. data/lib/aasm/version.rb +1 -1
  42. data/lib/aasm.rb +8 -2
  43. data/lib/generators/aasm/aasm_generator.rb +16 -0
  44. data/lib/generators/aasm/orm_helpers.rb +41 -0
  45. data/lib/generators/active_record/aasm_generator.rb +40 -0
  46. data/lib/generators/active_record/templates/migration.rb +8 -0
  47. data/lib/generators/active_record/templates/migration_existing.rb +5 -0
  48. data/lib/generators/mongoid/aasm_generator.rb +28 -0
  49. data/lib/generators/nobrainer/aasm_generator.rb +28 -0
  50. data/lib/motion-aasm.rb +37 -0
  51. metadata +104 -259
  52. data/.document +0 -6
  53. data/.gitignore +0 -19
  54. data/.travis.yml +0 -37
  55. data/API +0 -34
  56. data/CHANGELOG.md +0 -272
  57. data/CODE_OF_CONDUCT.md +0 -13
  58. data/Gemfile +0 -15
  59. data/HOWTO +0 -12
  60. data/PLANNED_CHANGES.md +0 -11
  61. data/README_FROM_VERSION_3_TO_4.md +0 -240
  62. data/Rakefile +0 -26
  63. data/aasm.gemspec +0 -31
  64. data/callbacks.txt +0 -51
  65. data/gemfiles/rails_3.2.gemfile +0 -14
  66. data/gemfiles/rails_4.0.gemfile +0 -12
  67. data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -14
  68. data/gemfiles/rails_4.1.gemfile +0 -12
  69. data/gemfiles/rails_4.1_mongo_mapper.gemfile +0 -14
  70. data/gemfiles/rails_4.2.gemfile +0 -12
  71. data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -14
  72. data/gemfiles/rails_4.2_mongoid_5.gemfile +0 -12
  73. data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -157
  74. data/spec/database.rb +0 -63
  75. data/spec/database.yml +0 -3
  76. data/spec/en.yml +0 -9
  77. data/spec/en_deprecated_style.yml +0 -10
  78. data/spec/models/active_record/basic_active_record_two_state_machines_example.rb +0 -25
  79. data/spec/models/active_record/complex_active_record_example.rb +0 -33
  80. data/spec/models/active_record/derivate_new_dsl.rb +0 -7
  81. data/spec/models/active_record/false_state.rb +0 -35
  82. data/spec/models/active_record/gate.rb +0 -39
  83. data/spec/models/active_record/localizer_test_model.rb +0 -34
  84. data/spec/models/active_record/no_direct_assignment.rb +0 -21
  85. data/spec/models/active_record/no_scope.rb +0 -21
  86. data/spec/models/active_record/persisted_state.rb +0 -12
  87. data/spec/models/active_record/provided_and_persisted_state.rb +0 -24
  88. data/spec/models/active_record/reader.rb +0 -7
  89. data/spec/models/active_record/readme_job.rb +0 -21
  90. data/spec/models/active_record/simple_new_dsl.rb +0 -17
  91. data/spec/models/active_record/thief.rb +0 -29
  92. data/spec/models/active_record/transient.rb +0 -6
  93. data/spec/models/active_record/with_enum.rb +0 -39
  94. data/spec/models/active_record/with_false_enum.rb +0 -31
  95. data/spec/models/active_record/with_true_enum.rb +0 -39
  96. data/spec/models/active_record/writer.rb +0 -6
  97. data/spec/models/basic_two_state_machines_example.rb +0 -25
  98. data/spec/models/callbacks/basic.rb +0 -78
  99. data/spec/models/callbacks/basic_multiple.rb +0 -75
  100. data/spec/models/callbacks/guard_within_block.rb +0 -66
  101. data/spec/models/callbacks/guard_within_block_multiple.rb +0 -66
  102. data/spec/models/callbacks/multiple_transitions_transition_guard.rb +0 -65
  103. data/spec/models/callbacks/multiple_transitions_transition_guard_multiple.rb +0 -65
  104. data/spec/models/callbacks/private_method.rb +0 -44
  105. data/spec/models/callbacks/private_method_multiple.rb +0 -44
  106. data/spec/models/callbacks/with_args.rb +0 -61
  107. data/spec/models/callbacks/with_args_multiple.rb +0 -61
  108. data/spec/models/callbacks/with_state_arg.rb +0 -26
  109. data/spec/models/callbacks/with_state_arg_multiple.rb +0 -26
  110. data/spec/models/complex_example.rb +0 -222
  111. data/spec/models/conversation.rb +0 -93
  112. data/spec/models/default_state.rb +0 -12
  113. data/spec/models/double_definer.rb +0 -21
  114. data/spec/models/foo.rb +0 -92
  115. data/spec/models/foo_callback_multiple.rb +0 -45
  116. data/spec/models/guardian.rb +0 -48
  117. data/spec/models/guardian_multiple.rb +0 -48
  118. data/spec/models/initial_state_proc.rb +0 -31
  119. data/spec/models/invalid_persistor.rb +0 -31
  120. data/spec/models/mongo_mapper/complex_mongo_mapper_example.rb +0 -37
  121. data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
  122. data/spec/models/mongo_mapper/simple_mongo_mapper.rb +0 -23
  123. data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
  124. data/spec/models/mongoid/complex_mongoid_example.rb +0 -37
  125. data/spec/models/mongoid/no_scope_mongoid.rb +0 -21
  126. data/spec/models/mongoid/simple_mongoid.rb +0 -23
  127. data/spec/models/mongoid/simple_new_dsl_mongoid.rb +0 -25
  128. data/spec/models/no_initial_state.rb +0 -25
  129. data/spec/models/not_auto_loaded/process.rb +0 -21
  130. data/spec/models/parametrised_event.rb +0 -29
  131. data/spec/models/parametrised_event_multiple.rb +0 -29
  132. data/spec/models/process_with_new_dsl.rb +0 -31
  133. data/spec/models/provided_state.rb +0 -24
  134. data/spec/models/sequel/complex_sequel_example.rb +0 -45
  135. data/spec/models/sequel/sequel_multiple.rb +0 -25
  136. data/spec/models/sequel/sequel_simple.rb +0 -25
  137. data/spec/models/silencer.rb +0 -27
  138. data/spec/models/simple_example.rb +0 -15
  139. data/spec/models/simple_multiple_example.rb +0 -30
  140. data/spec/models/state_machine_with_failed_event.rb +0 -12
  141. data/spec/models/sub_class.rb +0 -7
  142. data/spec/models/sub_class_with_more_states.rb +0 -18
  143. data/spec/models/sub_classing.rb +0 -3
  144. data/spec/models/super_class.rb +0 -46
  145. data/spec/models/this_name_better_not_be_in_use.rb +0 -11
  146. data/spec/models/transactor.rb +0 -53
  147. data/spec/models/valid_state_name.rb +0 -23
  148. data/spec/models/validator.rb +0 -79
  149. data/spec/models/worker.rb +0 -2
  150. data/spec/spec_helper.rb +0 -25
  151. data/spec/unit/api_spec.rb +0 -77
  152. data/spec/unit/basic_two_state_machines_example_spec.rb +0 -10
  153. data/spec/unit/callback_multiple_spec.rb +0 -295
  154. data/spec/unit/callbacks_spec.rb +0 -296
  155. data/spec/unit/complex_example_spec.rb +0 -84
  156. data/spec/unit/complex_multiple_example_spec.rb +0 -99
  157. data/spec/unit/edge_cases_spec.rb +0 -16
  158. data/spec/unit/event_multiple_spec.rb +0 -73
  159. data/spec/unit/event_naming_spec.rb +0 -11
  160. data/spec/unit/event_spec.rb +0 -322
  161. data/spec/unit/guard_multiple_spec.rb +0 -60
  162. data/spec/unit/guard_spec.rb +0 -60
  163. data/spec/unit/initial_state_multiple_spec.rb +0 -15
  164. data/spec/unit/initial_state_spec.rb +0 -12
  165. data/spec/unit/inspection_multiple_spec.rb +0 -201
  166. data/spec/unit/inspection_spec.rb +0 -111
  167. data/spec/unit/localizer_spec.rb +0 -76
  168. data/spec/unit/memory_leak_spec.rb +0 -38
  169. data/spec/unit/new_dsl_spec.rb +0 -12
  170. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +0 -573
  171. data/spec/unit/persistence/active_record_persistence_spec.rb +0 -552
  172. data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -146
  173. data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -93
  174. data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +0 -127
  175. data/spec/unit/persistence/mongoid_persistence_spec.rb +0 -79
  176. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +0 -153
  177. data/spec/unit/persistence/sequel_persistence_spec.rb +0 -100
  178. data/spec/unit/readme_spec.rb +0 -42
  179. data/spec/unit/reloading_spec.rb +0 -15
  180. data/spec/unit/rspec_matcher_spec.rb +0 -79
  181. data/spec/unit/simple_example_spec.rb +0 -42
  182. data/spec/unit/simple_multiple_example_spec.rb +0 -63
  183. data/spec/unit/state_spec.rb +0 -89
  184. data/spec/unit/subclassing_multiple_spec.rb +0 -39
  185. data/spec/unit/subclassing_spec.rb +0 -31
  186. data/spec/unit/transition_spec.rb +0 -291
@@ -1,93 +0,0 @@
1
- describe 'mongo_mapper' do
2
- begin
3
- require 'mongo_mapper'
4
- require 'logger'
5
- require 'spec_helper'
6
-
7
- Dir[File.dirname(__FILE__) + "/../../models/mongo_mapper/*.rb"].sort.each do |f|
8
- require File.expand_path(f)
9
- end
10
-
11
- before(:all) do
12
- config = {
13
- 'test' => {
14
- 'database' => "mongo_mapper_#{Process.pid}"
15
- }
16
- }
17
-
18
- MongoMapper.setup(config, 'test') #, :logger => Logger.new(STDERR))
19
- end
20
-
21
- after do
22
- # Clear Out all non-system Mongo collections between tests
23
- MongoMapper.database.collections.each do |collection|
24
- collection.drop unless collection.capped? || (collection.name =~ /\Asystem/)
25
- end
26
- end
27
-
28
- describe "named scopes with the old DSL" do
29
-
30
- context "Does not already respond_to? the scope name" do
31
- it "should add a scope" do
32
- expect(SimpleMongoMapper).to respond_to(:unknown_scope)
33
- expect(SimpleMongoMapper.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery)
34
- #expect(SimpleMongoMapper.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
35
- end
36
- end
37
-
38
- context "Already respond_to? the scope name" do
39
- it "should not add a scope" do
40
- expect(SimpleMongoMapper).to respond_to(:next)
41
- expect(SimpleMongoMapper.new.class).to eq(SimpleMongoMapper)
42
- end
43
- end
44
-
45
- end
46
-
47
- describe "named scopes with the new DSL" do
48
-
49
- context "Does not already respond_to? the scope name" do
50
- it "should add a scope" do
51
- expect(SimpleNewDslMongoMapper).to respond_to(:unknown_scope)
52
- expect(SimpleNewDslMongoMapper.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery)
53
- end
54
- end
55
-
56
- context "Already respond_to? the scope name" do
57
- it "should not add a scope" do
58
- expect(SimpleNewDslMongoMapper).to respond_to(:next)
59
- expect(SimpleNewDslMongoMapper.new.class).to eq(SimpleNewDslMongoMapper)
60
- end
61
- end
62
-
63
- it "does not create scopes if requested" do
64
- expect(NoScopeMongoMapper).not_to respond_to(:ignored_scope)
65
- end
66
-
67
- end
68
-
69
- describe "instance methods" do
70
-
71
- let(:simple) {SimpleNewDslMongoMapper.new}
72
-
73
- it "should call aasm_ensure_initial_state on validation before create" do
74
- expect(SimpleNewDslMongoMapper.aasm.initial_state).to eq(:unknown_scope)
75
- expect(SimpleNewDslMongoMapper.aasm.attribute_name).to eq(:status)
76
- expect(simple.status).to eq(nil)
77
- simple.valid?
78
- expect(simple.status).to eq('unknown_scope')
79
- end
80
-
81
- it "should call aasm_ensure_initial_state before create, even if skipping validations" do
82
- expect(simple.status).to eq(nil)
83
- simple.save(:validate => false)
84
- expect(simple.status).to eq('unknown_scope')
85
- end
86
- end
87
-
88
- rescue LoadError
89
- puts "--------------------------------------------------------------------------"
90
- puts "Not running MongoMapper multiple-specs because mongo_mapper gem is not installed!!!"
91
- puts "--------------------------------------------------------------------------"
92
- end
93
- end
@@ -1,127 +0,0 @@
1
- describe 'mongoid' do
2
- begin
3
- require 'mongoid'
4
- require 'logger'
5
- require 'spec_helper'
6
-
7
- Dir[File.dirname(__FILE__) + "/../../models/mongoid/*.rb"].sort.each do |f|
8
- require File.expand_path(f)
9
- end
10
-
11
- before(:all) do
12
- # if you want to see the statements while running the spec enable the following line
13
- # Mongoid.logger = Logger.new(STDERR)
14
-
15
- Mongoid.configure do |config|
16
- config.connect_to "mongoid_#{Process.pid}"
17
- end
18
- end
19
-
20
- after do
21
- Mongoid.purge!
22
- end
23
-
24
- describe "named scopes with the old DSL" do
25
-
26
- context "Does not already respond_to? the scope name" do
27
- it "should add a scope" do
28
- expect(SimpleMongoidMultiple).to respond_to(:unknown_scope)
29
- expect(SimpleMongoidMultiple.unknown_scope.class).to eq(Mongoid::Criteria)
30
- end
31
- end
32
-
33
- context "Already respond_to? the scope name" do
34
- it "should not add a scope" do
35
- expect(SimpleMongoidMultiple).to respond_to(:new)
36
- expect(SimpleMongoidMultiple.new.class).to eq(SimpleMongoidMultiple)
37
- end
38
- end
39
-
40
- end
41
-
42
- describe "named scopes with the new DSL" do
43
- context "Does not already respond_to? the scope name" do
44
- it "should add a scope" do
45
- expect(SimpleNewDslMongoidMultiple).to respond_to(:unknown_scope)
46
- expect(SimpleNewDslMongoidMultiple.unknown_scope.class).to eq(Mongoid::Criteria)
47
- end
48
- end
49
-
50
- context "Already respond_to? the scope name" do
51
- it "should not add a scope" do
52
- expect(SimpleNewDslMongoidMultiple).to respond_to(:new)
53
- expect(SimpleNewDslMongoidMultiple.new.class).to eq(SimpleNewDslMongoidMultiple)
54
- end
55
- end
56
-
57
- it "does not create scopes if requested" do
58
- expect(NoScopeMongoidMultiple).not_to respond_to(:ignored_scope)
59
- end
60
- end
61
-
62
- describe "instance methods" do
63
- let(:simple) {SimpleNewDslMongoidMultiple.new}
64
-
65
- it "should initialize the aasm state on instantiation" do
66
- expect(SimpleNewDslMongoidMultiple.new.status).to eql 'unknown_scope'
67
- expect(SimpleNewDslMongoidMultiple.new.aasm(:left).current_state).to eql :unknown_scope
68
- end
69
-
70
- end
71
-
72
- describe "complex example" do
73
- it "works" do
74
- record = ComplexMongoidExample.new
75
- expect_aasm_states record, :one, :alpha
76
-
77
- record.save!
78
- expect_aasm_states record, :one, :alpha
79
- record.reload
80
- expect_aasm_states record, :one, :alpha
81
-
82
- record.increment!
83
- expect_aasm_states record, :two, :alpha
84
- record.reload
85
- expect_aasm_states record, :two, :alpha
86
-
87
- record.level_up!
88
- expect_aasm_states record, :two, :beta
89
- record.reload
90
- expect_aasm_states record, :two, :beta
91
-
92
- record.increment!
93
- expect { record.increment! }.to raise_error(AASM::InvalidTransition)
94
- expect_aasm_states record, :three, :beta
95
- record.reload
96
- expect_aasm_states record, :three, :beta
97
-
98
- record.level_up!
99
- expect_aasm_states record, :three, :gamma
100
- record.reload
101
- expect_aasm_states record, :three, :gamma
102
-
103
- record.level_down # without saving
104
- expect_aasm_states record, :three, :beta
105
- record.reload
106
- expect_aasm_states record, :three, :gamma
107
-
108
- record.level_down # without saving
109
- expect_aasm_states record, :three, :beta
110
- record.reset!
111
- expect_aasm_states record, :one, :beta
112
- end
113
-
114
- def expect_aasm_states(record, left_state, right_state)
115
- expect(record.aasm(:left).current_state).to eql left_state.to_sym
116
- expect(record.left).to eql left_state.to_s
117
- expect(record.aasm(:right).current_state).to eql right_state.to_sym
118
- expect(record.right).to eql right_state.to_s
119
- end
120
- end
121
-
122
- rescue LoadError
123
- puts "--------------------------------------------------------------------------"
124
- puts "Not running Mongoid multiple-specs because mongoid gem is not installed!!!"
125
- puts "--------------------------------------------------------------------------"
126
- end
127
- end
@@ -1,79 +0,0 @@
1
- describe 'mongoid' do
2
- begin
3
- require 'mongoid'
4
- require 'logger'
5
- require 'spec_helper'
6
-
7
- Dir[File.dirname(__FILE__) + "/../../models/mongoid/*.rb"].sort.each do |f|
8
- require File.expand_path(f)
9
- end
10
-
11
- before(:all) do
12
- # if you want to see the statements while running the spec enable the following line
13
- # Mongoid.logger = Logger.new(STDERR)
14
-
15
- Mongoid.configure do |config|
16
- config.connect_to "mongoid_#{Process.pid}"
17
- end
18
- end
19
-
20
- after do
21
- Mongoid.purge!
22
- end
23
-
24
- describe "named scopes with the old DSL" do
25
-
26
- context "Does not already respond_to? the scope name" do
27
- it "should add a scope" do
28
- expect(SimpleMongoid).to respond_to(:unknown_scope)
29
- expect(SimpleMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
30
- end
31
- end
32
-
33
- context "Already respond_to? the scope name" do
34
- it "should not add a scope" do
35
- expect(SimpleMongoid).to respond_to(:new)
36
- expect(SimpleMongoid.new.class).to eq(SimpleMongoid)
37
- end
38
- end
39
-
40
- end
41
-
42
- describe "named scopes with the new DSL" do
43
-
44
- context "Does not already respond_to? the scope name" do
45
- it "should add a scope" do
46
- expect(SimpleNewDslMongoid).to respond_to(:unknown_scope)
47
- expect(SimpleNewDslMongoid.unknown_scope.class).to eq(Mongoid::Criteria)
48
- end
49
- end
50
-
51
- context "Already respond_to? the scope name" do
52
- it "should not add a scope" do
53
- expect(SimpleNewDslMongoid).to respond_to(:new)
54
- expect(SimpleNewDslMongoid.new.class).to eq(SimpleNewDslMongoid)
55
- end
56
- end
57
-
58
- it "does not create scopes if requested" do
59
- expect(NoScopeMongoid).not_to respond_to(:ignored_scope)
60
- end
61
-
62
- end
63
-
64
- describe "instance methods" do
65
- let(:simple) {SimpleNewDslMongoid.new}
66
-
67
- it "should initialize the aasm state on instantiation" do
68
- expect(SimpleNewDslMongoid.new.status).to eql 'unknown_scope'
69
- expect(SimpleNewDslMongoid.new.aasm.current_state).to eql :unknown_scope
70
- end
71
-
72
- end
73
-
74
- rescue LoadError
75
- puts "--------------------------------------------------------------------------"
76
- puts "Not running Mongoid specs because mongoid gem is not installed!!!"
77
- puts "--------------------------------------------------------------------------"
78
- end
79
- end
@@ -1,153 +0,0 @@
1
- describe 'sequel' do
2
- begin
3
- require 'sequel'
4
- require 'logger'
5
- require 'spec_helper'
6
-
7
- Dir[File.dirname(__FILE__) + "/../../models/sequel/*.rb"].sort.each do |f|
8
- require File.expand_path(f)
9
- end
10
-
11
- before(:all) do
12
- @model = SequelMultiple
13
- end
14
-
15
- describe "instance methods" do
16
- let(:model) {@model.new}
17
-
18
- it "should respond to aasm persistence methods" do
19
- expect(model).to respond_to(:aasm_read_state)
20
- expect(model).to respond_to(:aasm_write_state)
21
- expect(model).to respond_to(:aasm_write_state_without_persistence)
22
- end
23
-
24
- it "should return the initial state when new and the aasm field is nil" do
25
- expect(model.aasm(:left).current_state).to eq(:alpha)
26
- end
27
-
28
- it "should save the initial state" do
29
- model.save
30
- expect(model.status).to eq("alpha")
31
- end
32
-
33
- it "should return the aasm column when new and the aasm field is not nil" do
34
- model.status = "beta"
35
- expect(model.aasm(:left).current_state).to eq(:beta)
36
- end
37
-
38
- it "should return the aasm column when not new and the aasm_column is not nil" do
39
- allow(model).to receive(:new?).and_return(false)
40
- model.status = "gamma"
41
- expect(model.aasm(:left).current_state).to eq(:gamma)
42
- end
43
-
44
- it "should allow a nil state" do
45
- allow(model).to receive(:new?).and_return(false)
46
- model.status = nil
47
- expect(model.aasm(:left).current_state).to be_nil
48
- end
49
-
50
- it "should not change the state if state is not loaded" do
51
- model.release
52
- model.save
53
- model.class.select(:id).first.save
54
- model.reload
55
- expect(model.aasm(:left).current_state).to eq(:beta)
56
- end
57
-
58
- it "should call aasm_ensure_initial_state on validation before create" do
59
- expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
60
- model.valid?
61
- end
62
-
63
- it "should call aasm_ensure_initial_state before create, even if skipping validations" do
64
- expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
65
- model.save(:validate => false)
66
- end
67
- end
68
-
69
- describe 'subclasses' do
70
- it "should have the same states as its parent class" do
71
- expect(Class.new(@model).aasm(:left).states).to eq(@model.aasm(:left).states)
72
- end
73
-
74
- it "should have the same events as its parent class" do
75
- expect(Class.new(@model).aasm(:left).events).to eq(@model.aasm(:left).events)
76
- end
77
-
78
- it "should have the same column as its parent even for the new dsl" do
79
- expect(@model.aasm(:left).attribute_name).to eq(:status)
80
- expect(Class.new(@model).aasm(:left).attribute_name).to eq(:status)
81
- end
82
- end
83
-
84
- describe 'initial states' do
85
- it 'should support conditions' do
86
- @model.aasm(:left) do
87
- initial_state lambda{ |m| m.default }
88
- end
89
-
90
- expect(@model.new(:default => :beta).aasm(:left).current_state).to eq(:beta)
91
- expect(@model.new(:default => :gamma).aasm(:left).current_state).to eq(:gamma)
92
- end
93
- end
94
-
95
- describe "complex example" do
96
- it "works" do
97
- record = ComplexSequelExample.new
98
- expect(record.aasm(:left).current_state).to eql :one
99
- expect(record.left).to be_nil
100
- expect(record.aasm(:right).current_state).to eql :alpha
101
- expect(record.right).to be_nil
102
-
103
- record.save
104
- expect_aasm_states record, :one, :alpha
105
- record.reload
106
- expect_aasm_states record, :one, :alpha
107
-
108
- record.increment!
109
- expect_aasm_states record, :two, :alpha
110
- record.reload
111
- expect_aasm_states record, :two, :alpha
112
-
113
- record.level_up!
114
- expect_aasm_states record, :two, :beta
115
- record.reload
116
- expect_aasm_states record, :two, :beta
117
-
118
- record.increment!
119
- expect { record.increment! }.to raise_error(AASM::InvalidTransition)
120
- expect_aasm_states record, :three, :beta
121
- record.reload
122
- expect_aasm_states record, :three, :beta
123
-
124
- record.level_up!
125
- expect_aasm_states record, :three, :gamma
126
- record.reload
127
- expect_aasm_states record, :three, :gamma
128
-
129
- record.level_down # without saving
130
- expect_aasm_states record, :three, :beta
131
- record.reload
132
- expect_aasm_states record, :three, :gamma
133
-
134
- record.level_down # without saving
135
- expect_aasm_states record, :three, :beta
136
- record.reset!
137
- expect_aasm_states record, :one, :beta
138
- end
139
-
140
- def expect_aasm_states(record, left_state, right_state)
141
- expect(record.aasm(:left).current_state).to eql left_state.to_sym
142
- expect(record.left).to eql left_state.to_s
143
- expect(record.aasm(:right).current_state).to eql right_state.to_sym
144
- expect(record.right).to eql right_state.to_s
145
- end
146
- end
147
-
148
- rescue LoadError
149
- puts "------------------------------------------------------------------------"
150
- puts "Not running Sequel multiple-specs because sequel gem is not installed!!!"
151
- puts "------------------------------------------------------------------------"
152
- end
153
- end
@@ -1,100 +0,0 @@
1
- describe 'sequel' do
2
- begin
3
- require 'sequel'
4
- require 'logger'
5
- require 'spec_helper'
6
-
7
- Dir[File.dirname(__FILE__) + "/../../models/sequel/*.rb"].sort.each do |f|
8
- require File.expand_path(f)
9
- end
10
-
11
- before(:all) do
12
- @model = SequelSimple
13
- end
14
-
15
- describe "instance methods" do
16
- let(:model) {@model.new}
17
-
18
- it "should respond to aasm persistence methods" do
19
- expect(model).to respond_to(:aasm_read_state)
20
- expect(model).to respond_to(:aasm_write_state)
21
- expect(model).to respond_to(:aasm_write_state_without_persistence)
22
- end
23
-
24
- it "should return the initial state when new and the aasm field is nil" do
25
- expect(model.aasm.current_state).to eq(:alpha)
26
- end
27
-
28
- it "should save the initial state" do
29
- model.save
30
- expect(model.status).to eq("alpha")
31
- end
32
-
33
- it "should return the aasm column when new and the aasm field is not nil" do
34
- model.status = "beta"
35
- expect(model.aasm.current_state).to eq(:beta)
36
- end
37
-
38
- it "should return the aasm column when not new and the aasm_column is not nil" do
39
- allow(model).to receive(:new?).and_return(false)
40
- model.status = "gamma"
41
- expect(model.aasm.current_state).to eq(:gamma)
42
- end
43
-
44
- it "should allow a nil state" do
45
- allow(model).to receive(:new?).and_return(false)
46
- model.status = nil
47
- expect(model.aasm.current_state).to be_nil
48
- end
49
-
50
- it "should not change the state if state is not loaded" do
51
- model.release
52
- model.save
53
- model.class.select(:id).first.save
54
- model.reload
55
- expect(model.aasm.current_state).to eq(:beta)
56
- end
57
-
58
- it "should call aasm_ensure_initial_state on validation before create" do
59
- expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
60
- model.valid?
61
- end
62
-
63
- it "should call aasm_ensure_initial_state before create, even if skipping validations" do
64
- expect(model).to receive(:aasm_ensure_initial_state).and_return(true)
65
- model.save(:validate => false)
66
- end
67
- end
68
-
69
- describe 'subclasses' do
70
- it "should have the same states as its parent class" do
71
- expect(Class.new(@model).aasm.states).to eq(@model.aasm.states)
72
- end
73
-
74
- it "should have the same events as its parent class" do
75
- expect(Class.new(@model).aasm.events).to eq(@model.aasm.events)
76
- end
77
-
78
- it "should have the same column as its parent even for the new dsl" do
79
- expect(@model.aasm.attribute_name).to eq(:status)
80
- expect(Class.new(@model).aasm.attribute_name).to eq(:status)
81
- end
82
- end
83
-
84
- describe 'initial states' do
85
- it 'should support conditions' do
86
- @model.aasm do
87
- initial_state lambda{ |m| m.default }
88
- end
89
-
90
- expect(@model.new(:default => :beta).aasm.current_state).to eq(:beta)
91
- expect(@model.new(:default => :gamma).aasm.current_state).to eq(:gamma)
92
- end
93
- end
94
-
95
- rescue LoadError
96
- puts "------------------------------------------------------------------------"
97
- puts "Not running Sequel specs because sequel gem is not installed!!!"
98
- puts "------------------------------------------------------------------------"
99
- end
100
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'testing the README examples' do
4
-
5
- it 'Usage' do
6
- class Job
7
- include AASM
8
-
9
- aasm do
10
- state :sleeping, :initial => true
11
- state :running
12
- state :cleaning
13
-
14
- event :run do
15
- transitions :from => :sleeping, :to => :running
16
- end
17
-
18
- event :clean do
19
- transitions :from => :running, :to => :cleaning
20
- end
21
-
22
- event :sleep do
23
- transitions :from => [:running, :cleaning], :to => :sleeping
24
- end
25
- end
26
- end
27
-
28
- job = Job.new
29
-
30
- expect(job.sleeping?).to eql true
31
- expect(job.may_run?).to eql true
32
-
33
- job.run
34
-
35
- expect(job.running?).to eql true
36
- expect(job.sleeping?).to eql false
37
- expect(job.may_run?).to eql false
38
-
39
- expect { job.run }.to raise_error(AASM::InvalidTransition)
40
- end
41
-
42
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'when redefining states' do
4
- let(:definer) { DoubleDefiner.new }
5
-
6
- it "allows extending states" do
7
- expect(definer).to receive(:do_enter)
8
- definer.finish
9
- end
10
-
11
- it "allows extending events" do
12
- expect(definer).to receive(:do_on_transition)
13
- definer.finish
14
- end
15
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'state machine' do
4
- let(:simple) { SimpleExample.new }
5
- let(:multiple) { SimpleMultipleExample.new }
6
-
7
- describe 'transition_from' do
8
- it "works for simple state machines" do
9
- expect(simple).to transition_from(:initialised).to(:filled_out).on_event(:fill_out)
10
- expect(simple).to_not transition_from(:initialised).to(:authorised).on_event(:fill_out)
11
- end
12
-
13
- it "works for multiple state machines" do
14
- expect(multiple).to transition_from(:standing).to(:walking).on_event(:walk).on(:move)
15
- expect(multiple).to_not transition_from(:standing).to(:running).on_event(:walk).on(:move)
16
-
17
- expect(multiple).to transition_from(:sleeping).to(:processing).on_event(:start).on(:work)
18
- expect(multiple).to_not transition_from(:sleeping).to(:sleeping).on_event(:start).on(:work)
19
- end
20
- end
21
-
22
- describe 'allow_transition_to' do
23
- it "works for simple state machines" do
24
- expect(simple).to allow_transition_to(:filled_out)
25
- expect(simple).to_not allow_transition_to(:authorised)
26
- end
27
-
28
- it "works for multiple state machines" do
29
- expect(multiple).to allow_transition_to(:walking).on(:move)
30
- expect(multiple).to_not allow_transition_to(:standing).on(:move)
31
-
32
- expect(multiple).to allow_transition_to(:processing).on(:work)
33
- expect(multiple).to_not allow_transition_to(:sleeping).on(:work)
34
- end
35
- end
36
-
37
- describe "have_state" do
38
- it "works for simple state machines" do
39
- expect(simple).to have_state :initialised
40
- expect(simple).to_not have_state :filled_out
41
- simple.fill_out
42
- expect(simple).to have_state :filled_out
43
- end
44
-
45
- it "works for multiple state machines" do
46
- expect(multiple).to have_state(:standing).on(:move)
47
- expect(multiple).to_not have_state(:walking).on(:move)
48
- multiple.walk
49
- expect(multiple).to have_state(:walking).on(:move)
50
-
51
- expect(multiple).to have_state(:sleeping).on(:work)
52
- expect(multiple).to_not have_state(:processing).on(:work)
53
- multiple.start
54
- expect(multiple).to have_state(:processing).on(:work)
55
- end
56
- end
57
-
58
- describe "allow_event" do
59
- it "works for simple state machines" do
60
- expect(simple).to allow_event :fill_out
61
- expect(simple).to_not allow_event :authorise
62
- simple.fill_out
63
- expect(simple).to allow_event :authorise
64
- end
65
-
66
- it "works for multiple state machines" do
67
- expect(multiple).to allow_event(:walk).on(:move)
68
- expect(multiple).to_not allow_event(:hold).on(:move)
69
- multiple.walk
70
- expect(multiple).to allow_event(:hold).on(:move)
71
-
72
- expect(multiple).to allow_event(:start).on(:work)
73
- expect(multiple).to_not allow_event(:stop).on(:work)
74
- multiple.start
75
- expect(multiple).to allow_event(:stop).on(:work)
76
- end
77
- end
78
-
79
- end