aasm 4.12.0 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -1
  3. data/Appraisals +2 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +1 -1
  6. data/README.md +102 -8
  7. data/gemfiles/rails_4.2.gemfile +1 -0
  8. data/gemfiles/rails_5.0.gemfile +1 -0
  9. data/lib/aasm/base.rb +8 -0
  10. data/lib/aasm/core/event.rb +1 -1
  11. data/lib/aasm/core/transition.rb +1 -1
  12. data/lib/aasm/instance_base.rb +0 -2
  13. data/lib/aasm/minitest.rb +5 -0
  14. data/lib/aasm/minitest/allow_event.rb +13 -0
  15. data/lib/aasm/minitest/allow_transition_to.rb +13 -0
  16. data/lib/aasm/minitest/have_state.rb +13 -0
  17. data/lib/aasm/minitest/transition_from.rb +21 -0
  18. data/lib/aasm/minitest_spec.rb +15 -0
  19. data/lib/aasm/persistence/active_record_persistence.rb +25 -101
  20. data/lib/aasm/persistence/base.rb +7 -3
  21. data/lib/aasm/persistence/mongoid_persistence.rb +15 -60
  22. data/lib/aasm/persistence/orm.rb +142 -0
  23. data/lib/aasm/persistence/redis_persistence.rb +16 -11
  24. data/lib/aasm/persistence/sequel_persistence.rb +36 -63
  25. data/lib/aasm/version.rb +1 -1
  26. data/lib/generators/active_record/templates/migration.rb +1 -1
  27. data/lib/generators/active_record/templates/migration_existing.rb +1 -1
  28. data/lib/motion-aasm.rb +2 -0
  29. data/spec/models/active_record/complex_active_record_example.rb +5 -1
  30. data/spec/models/guardian_without_from_specified.rb +18 -0
  31. data/spec/models/namespaced_multiple_example.rb +14 -0
  32. data/spec/models/redis/complex_redis_example.rb +40 -0
  33. data/spec/models/redis/redis_multiple.rb +20 -0
  34. data/spec/models/redis/redis_simple.rb +20 -0
  35. data/spec/models/sequel/complex_sequel_example.rb +4 -3
  36. data/spec/models/sequel/invalid_persistor.rb +52 -0
  37. data/spec/models/sequel/sequel_multiple.rb +13 -13
  38. data/spec/models/sequel/sequel_simple.rb +13 -12
  39. data/spec/models/sequel/silent_persistor.rb +50 -0
  40. data/spec/models/sequel/transactor.rb +112 -0
  41. data/spec/models/sequel/validator.rb +93 -0
  42. data/spec/models/sequel/worker.rb +12 -0
  43. data/spec/spec_helpers/redis.rb +8 -0
  44. data/spec/unit/guard_spec.rb +17 -0
  45. data/spec/unit/guard_without_from_specified_spec.rb +10 -0
  46. data/spec/unit/namespaced_multiple_example_spec.rb +22 -0
  47. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +4 -4
  48. data/spec/unit/persistence/active_record_persistence_spec.rb +4 -4
  49. data/spec/unit/persistence/redis_persistence_multiple_spec.rb +88 -0
  50. data/spec/unit/persistence/redis_persistence_spec.rb +5 -25
  51. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +2 -2
  52. data/spec/unit/persistence/sequel_persistence_spec.rb +275 -2
  53. data/test/minitest_helper.rb +57 -0
  54. data/test/unit/minitest_matcher_test.rb +80 -0
  55. metadata +35 -2
@@ -0,0 +1,57 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'models')))
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
4
+ require 'aasm'
5
+ require 'minitest/autorun'
6
+ require 'aasm/minitest_spec'
7
+ require 'pry'
8
+
9
+ # require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
10
+ # require 'ruby-debug/completion'
11
+ # require 'pry'
12
+
13
+ SEQUEL_DB = defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/'
14
+
15
+ def load_schema
16
+ require 'logger'
17
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
18
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
19
+ ActiveRecord::Base.establish_connection(config['sqlite3'])
20
+ require File.dirname(__FILE__) + "/database.rb"
21
+ end
22
+
23
+ # Dynamoid initialization
24
+ begin
25
+ require 'dynamoid'
26
+ require 'aws-sdk-resources'
27
+
28
+ ENV['ACCESS_KEY'] ||= 'abcd'
29
+ ENV['SECRET_KEY'] ||= '1234'
30
+
31
+ Aws.config.update({
32
+ region: 'us-west-2',
33
+ credentials: Aws::Credentials.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY'])
34
+ })
35
+
36
+ Dynamoid.configure do |config|
37
+ config.namespace = "dynamoid_tests"
38
+ config.endpoint = 'http://127.0.0.1:30180'
39
+ config.warn_on_scan = false
40
+ end
41
+
42
+ Dynamoid.logger.level = Logger::FATAL
43
+
44
+ class Minitest::Spec
45
+ before do
46
+ Dynamoid.adapter.list_tables.each do |table|
47
+ Dynamoid.adapter.delete_table(table) if table =~ /^#{Dynamoid::Config.namespace}/
48
+ end
49
+ Dynamoid.adapter.tables.clear
50
+ end
51
+ end
52
+ rescue LoadError
53
+ # Without Dynamoid settings
54
+ end
55
+
56
+ # example model classes
57
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'models')) + '/*.rb'].sort.each { |f| require File.expand_path(f) }
@@ -0,0 +1,80 @@
1
+ require 'minitest_helper'
2
+
3
+ class StateMachineTest < Minitest::Spec
4
+
5
+ let(:simple) { SimpleExample.new }
6
+ let(:multiple) { SimpleMultipleExample.new }
7
+
8
+ describe 'transition_from' do
9
+ it "works for simple state machines" do
10
+ simple.must_transition_from :initialised, to: :filled_out, on_event: :fill_out
11
+ simple.wont_transition_from :initialised, to: :authorised, on_event: :fill_out
12
+ end
13
+
14
+ it "works for multiple state machines" do
15
+ multiple.must_transition_from :standing, to: :walking, on_event: :walk, on: :move
16
+ multiple.wont_transition_from :standing, to: :running, on_event: :walk, on: :move
17
+
18
+ multiple.must_transition_from :sleeping, to: :processing, on_event: :start, on: :work
19
+ multiple.wont_transition_from :sleeping, to: :sleeping, on_event: :start, on: :work
20
+ end
21
+ end
22
+
23
+ describe 'allow_transition_to' do
24
+ it "works for simple state machines" do
25
+ simple.must_allow_transition_to :filled_out
26
+ simple.wont_allow_transition_to :authorised
27
+ end
28
+
29
+ it "works for multiple state machines" do
30
+ multiple.must_allow_transition_to :walking, on: :move
31
+ multiple.wont_allow_transition_to :standing, on: :move
32
+
33
+ multiple.must_allow_transition_to :processing, on: :work
34
+ multiple.wont_allow_transition_to :sleeping, on: :work
35
+ end
36
+ end
37
+
38
+ describe "have_state" do
39
+ it "works for simple state machines" do
40
+ simple.must_have_state :initialised
41
+ simple.wont_have_state :filled_out
42
+ simple.fill_out
43
+ simple.must_have_state :filled_out
44
+ end
45
+
46
+ it "works for multiple state machines" do
47
+ multiple.must_have_state :standing, on: :move
48
+ multiple.wont_have_state :walking, on: :move
49
+ multiple.walk
50
+ multiple.must_have_state :walking, on: :move
51
+
52
+ multiple.must_have_state :sleeping, on: :work
53
+ multiple.wont_have_state :processing, on: :work
54
+ multiple.start
55
+ multiple.must_have_state :processing, on: :work
56
+ end
57
+ end
58
+
59
+ describe "allow_event" do
60
+ it "works for simple state machines" do
61
+ simple.must_allow_event :fill_out
62
+ simple.wont_allow_event :authorise
63
+ simple.fill_out
64
+ simple.must_allow_event :authorise
65
+ end
66
+
67
+ it "works for multiple state machines" do
68
+ multiple.must_allow_event :walk, on: :move
69
+ multiple.wont_allow_event :hold, on: :move
70
+ multiple.walk
71
+ multiple.must_allow_event :hold, on: :move
72
+
73
+ multiple.must_allow_event :start, on: :work
74
+ multiple.wont_allow_event :stop, on: :work
75
+ multiple.start
76
+ multiple.must_allow_event :stop, on: :work
77
+ end
78
+ end
79
+
80
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.0
4
+ version: 4.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-21 00:00:00.000000000 Z
12
+ date: 2017-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -150,12 +150,19 @@ files:
150
150
  - lib/aasm/errors.rb
151
151
  - lib/aasm/instance_base.rb
152
152
  - lib/aasm/localizer.rb
153
+ - lib/aasm/minitest.rb
154
+ - lib/aasm/minitest/allow_event.rb
155
+ - lib/aasm/minitest/allow_transition_to.rb
156
+ - lib/aasm/minitest/have_state.rb
157
+ - lib/aasm/minitest/transition_from.rb
158
+ - lib/aasm/minitest_spec.rb
153
159
  - lib/aasm/persistence.rb
154
160
  - lib/aasm/persistence/active_record_persistence.rb
155
161
  - lib/aasm/persistence/base.rb
156
162
  - lib/aasm/persistence/core_data_query_persistence.rb
157
163
  - lib/aasm/persistence/dynamoid_persistence.rb
158
164
  - lib/aasm/persistence/mongoid_persistence.rb
165
+ - lib/aasm/persistence/orm.rb
159
166
  - lib/aasm/persistence/plain_persistence.rb
160
167
  - lib/aasm/persistence/redis_persistence.rb
161
168
  - lib/aasm/persistence/sequel_persistence.rb
@@ -231,6 +238,7 @@ files:
231
238
  - spec/models/guard_with_params_multiple.rb
232
239
  - spec/models/guardian.rb
233
240
  - spec/models/guardian_multiple.rb
241
+ - spec/models/guardian_without_from_specified.rb
234
242
  - spec/models/initial_state_proc.rb
235
243
  - spec/models/mongoid/complex_mongoid_example.rb
236
244
  - spec/models/mongoid/invalid_persistor_mongoid.rb
@@ -249,9 +257,17 @@ files:
249
257
  - spec/models/parametrised_event_multiple.rb
250
258
  - spec/models/process_with_new_dsl.rb
251
259
  - spec/models/provided_state.rb
260
+ - spec/models/redis/complex_redis_example.rb
261
+ - spec/models/redis/redis_multiple.rb
262
+ - spec/models/redis/redis_simple.rb
252
263
  - spec/models/sequel/complex_sequel_example.rb
264
+ - spec/models/sequel/invalid_persistor.rb
253
265
  - spec/models/sequel/sequel_multiple.rb
254
266
  - spec/models/sequel/sequel_simple.rb
267
+ - spec/models/sequel/silent_persistor.rb
268
+ - spec/models/sequel/transactor.rb
269
+ - spec/models/sequel/validator.rb
270
+ - spec/models/sequel/worker.rb
255
271
  - spec/models/silencer.rb
256
272
  - spec/models/simple_custom_example.rb
257
273
  - spec/models/simple_example.rb
@@ -286,6 +302,7 @@ files:
286
302
  - spec/unit/guard_spec.rb
287
303
  - spec/unit/guard_with_params_multiple_spec.rb
288
304
  - spec/unit/guard_with_params_spec.rb
305
+ - spec/unit/guard_without_from_specified_spec.rb
289
306
  - spec/unit/initial_state_multiple_spec.rb
290
307
  - spec/unit/initial_state_spec.rb
291
308
  - spec/unit/inspection_multiple_spec.rb
@@ -302,6 +319,7 @@ files:
302
319
  - spec/unit/persistence/dynamoid_persistence_spec.rb
303
320
  - spec/unit/persistence/mongoid_persistence_multiple_spec.rb
304
321
  - spec/unit/persistence/mongoid_persistence_spec.rb
322
+ - spec/unit/persistence/redis_persistence_multiple_spec.rb
305
323
  - spec/unit/persistence/redis_persistence_spec.rb
306
324
  - spec/unit/persistence/sequel_persistence_multiple_spec.rb
307
325
  - spec/unit/persistence/sequel_persistence_spec.rb
@@ -316,6 +334,8 @@ files:
316
334
  - spec/unit/subclassing_multiple_spec.rb
317
335
  - spec/unit/subclassing_spec.rb
318
336
  - spec/unit/transition_spec.rb
337
+ - test/minitest_helper.rb
338
+ - test/unit/minitest_matcher_test.rb
319
339
  homepage: https://github.com/aasm/aasm
320
340
  licenses:
321
341
  - MIT
@@ -398,6 +418,7 @@ test_files:
398
418
  - spec/models/guard_with_params_multiple.rb
399
419
  - spec/models/guardian.rb
400
420
  - spec/models/guardian_multiple.rb
421
+ - spec/models/guardian_without_from_specified.rb
401
422
  - spec/models/initial_state_proc.rb
402
423
  - spec/models/mongoid/complex_mongoid_example.rb
403
424
  - spec/models/mongoid/invalid_persistor_mongoid.rb
@@ -416,9 +437,17 @@ test_files:
416
437
  - spec/models/parametrised_event_multiple.rb
417
438
  - spec/models/process_with_new_dsl.rb
418
439
  - spec/models/provided_state.rb
440
+ - spec/models/redis/complex_redis_example.rb
441
+ - spec/models/redis/redis_multiple.rb
442
+ - spec/models/redis/redis_simple.rb
419
443
  - spec/models/sequel/complex_sequel_example.rb
444
+ - spec/models/sequel/invalid_persistor.rb
420
445
  - spec/models/sequel/sequel_multiple.rb
421
446
  - spec/models/sequel/sequel_simple.rb
447
+ - spec/models/sequel/silent_persistor.rb
448
+ - spec/models/sequel/transactor.rb
449
+ - spec/models/sequel/validator.rb
450
+ - spec/models/sequel/worker.rb
422
451
  - spec/models/silencer.rb
423
452
  - spec/models/simple_custom_example.rb
424
453
  - spec/models/simple_example.rb
@@ -453,6 +482,7 @@ test_files:
453
482
  - spec/unit/guard_spec.rb
454
483
  - spec/unit/guard_with_params_multiple_spec.rb
455
484
  - spec/unit/guard_with_params_spec.rb
485
+ - spec/unit/guard_without_from_specified_spec.rb
456
486
  - spec/unit/initial_state_multiple_spec.rb
457
487
  - spec/unit/initial_state_spec.rb
458
488
  - spec/unit/inspection_multiple_spec.rb
@@ -469,6 +499,7 @@ test_files:
469
499
  - spec/unit/persistence/dynamoid_persistence_spec.rb
470
500
  - spec/unit/persistence/mongoid_persistence_multiple_spec.rb
471
501
  - spec/unit/persistence/mongoid_persistence_spec.rb
502
+ - spec/unit/persistence/redis_persistence_multiple_spec.rb
472
503
  - spec/unit/persistence/redis_persistence_spec.rb
473
504
  - spec/unit/persistence/sequel_persistence_multiple_spec.rb
474
505
  - spec/unit/persistence/sequel_persistence_spec.rb
@@ -483,3 +514,5 @@ test_files:
483
514
  - spec/unit/subclassing_multiple_spec.rb
484
515
  - spec/unit/subclassing_spec.rb
485
516
  - spec/unit/transition_spec.rb
517
+ - test/minitest_helper.rb
518
+ - test/unit/minitest_matcher_test.rb