aasm 4.11.0 → 4.12.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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -17
  3. data/Appraisals +44 -0
  4. data/CHANGELOG.md +24 -1
  5. data/CONTRIBUTING.md +24 -0
  6. data/Gemfile +4 -21
  7. data/README.md +81 -34
  8. data/Rakefile +6 -1
  9. data/TESTING.md +25 -0
  10. data/aasm.gemspec +5 -2
  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 +9 -9
  14. data/gemfiles/rails_4.2_mongoid_5.gemfile +5 -9
  15. data/gemfiles/rails_5.0.gemfile +7 -16
  16. data/lib/aasm/aasm.rb +9 -3
  17. data/lib/aasm/base.rb +3 -1
  18. data/lib/aasm/configuration.rb +4 -0
  19. data/lib/aasm/core/event.rb +19 -9
  20. data/lib/aasm/core/state.rb +7 -0
  21. data/lib/aasm/core/transition.rb +9 -0
  22. data/lib/aasm/instance_base.rb +8 -8
  23. data/lib/aasm/persistence/active_record_persistence.rb +1 -1
  24. data/lib/aasm/persistence/base.rb +3 -3
  25. data/lib/aasm/persistence/mongoid_persistence.rb +48 -9
  26. data/lib/aasm/persistence.rb +0 -3
  27. data/lib/aasm/state_machine.rb +4 -2
  28. data/lib/aasm/state_machine_store.rb +5 -2
  29. data/lib/aasm/version.rb +1 -1
  30. data/lib/generators/active_record/aasm_generator.rb +1 -1
  31. data/lib/motion-aasm.rb +0 -1
  32. data/spec/en.yml +3 -0
  33. data/spec/generators/active_record_generator_spec.rb +42 -34
  34. data/spec/generators/mongoid_generator_spec.rb +4 -6
  35. data/spec/models/{invalid_persistor.rb → active_record/invalid_persistor.rb} +0 -2
  36. data/spec/models/{silent_persistor.rb → active_record/silent_persistor.rb} +0 -2
  37. data/spec/models/active_record/simple_new_dsl.rb +2 -2
  38. data/spec/models/{transactor.rb → active_record/transactor.rb} +0 -2
  39. data/spec/models/{validator.rb → active_record/validator.rb} +6 -3
  40. data/spec/models/callbacks/basic.rb +5 -2
  41. data/spec/models/guard_with_params.rb +24 -0
  42. data/spec/models/guard_with_params_multiple.rb +18 -0
  43. data/spec/models/mongoid/invalid_persistor_mongoid.rb +39 -0
  44. data/spec/models/mongoid/silent_persistor_mongoid.rb +39 -0
  45. data/spec/models/mongoid/simple_mongoid.rb +2 -2
  46. data/spec/models/mongoid/validator_mongoid.rb +100 -0
  47. data/spec/models/multi_transitioner.rb +10 -0
  48. data/spec/models/multiple_transitions_that_differ_only_by_guard.rb +31 -0
  49. data/spec/models/parametrised_event.rb +7 -0
  50. data/spec/models/simple_multiple_example.rb +12 -0
  51. data/spec/models/sub_class.rb +34 -0
  52. data/spec/spec_helper.rb +0 -33
  53. data/spec/spec_helpers/active_record.rb +7 -0
  54. data/spec/spec_helpers/dynamoid.rb +33 -0
  55. data/spec/spec_helpers/mongoid.rb +7 -0
  56. data/spec/spec_helpers/redis.rb +7 -0
  57. data/spec/spec_helpers/remove_warnings.rb +1 -0
  58. data/spec/spec_helpers/sequel.rb +7 -0
  59. data/spec/unit/api_spec.rb +76 -73
  60. data/spec/unit/callbacks_spec.rb +5 -0
  61. data/spec/unit/event_spec.rb +12 -0
  62. data/spec/unit/guard_with_params_multiple_spec.rb +10 -0
  63. data/spec/unit/guard_with_params_spec.rb +14 -0
  64. data/spec/unit/inspection_spec.rb +5 -0
  65. data/spec/unit/localizer_spec.rb +55 -53
  66. data/spec/unit/multiple_transitions_that_differ_only_by_guard_spec.rb +14 -0
  67. data/spec/unit/override_warning_spec.rb +8 -0
  68. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +452 -445
  69. data/spec/unit/persistence/active_record_persistence_spec.rb +523 -490
  70. data/spec/unit/persistence/dynamoid_persistence_multiple_spec.rb +4 -9
  71. data/spec/unit/persistence/dynamoid_persistence_spec.rb +4 -9
  72. data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +87 -10
  73. data/spec/unit/persistence/mongoid_persistence_spec.rb +89 -10
  74. data/spec/unit/persistence/redis_persistence_spec.rb +3 -7
  75. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +4 -9
  76. data/spec/unit/persistence/sequel_persistence_spec.rb +4 -9
  77. data/spec/unit/simple_multiple_example_spec.rb +28 -0
  78. data/spec/unit/subclassing_multiple_spec.rb +37 -2
  79. data/spec/unit/subclassing_spec.rb +17 -2
  80. metadata +77 -32
  81. data/gemfiles/rails_3.2_stable.gemfile +0 -15
  82. data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -17
  83. data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -18
  84. data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -163
  85. data/spec/models/mongo_mapper/complex_mongo_mapper_example.rb +0 -37
  86. data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
  87. data/spec/models/mongo_mapper/simple_mongo_mapper.rb +0 -23
  88. data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
  89. data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -146
  90. data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -93
  91. /data/spec/models/{worker.rb → active_record/worker.rb} +0 -0
@@ -5,7 +5,7 @@ class SimpleMongoid
5
5
  field :status, :type => String
6
6
 
7
7
  aasm column: :status do
8
- state :unknown_scope
8
+ state :unknown_scope, :another_unknown_scope
9
9
  state :new
10
10
  end
11
11
  end
@@ -17,7 +17,7 @@ class SimpleMongoidMultiple
17
17
  field :status, :type => String
18
18
 
19
19
  aasm :left, column: :status do
20
- state :unknown_scope
20
+ state :unknown_scope, :another_unknown_scope
21
21
  state :new
22
22
  end
23
23
  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
@@ -11,14 +11,24 @@ class MultiTransitioner
11
11
  state :sleeping, :initial => true
12
12
  state :running
13
13
  state :dancing
14
+ state :dead
14
15
 
15
16
  event :start do
16
17
  transitions :from => :sleeping, :to => :running, guard: :runnable?
17
18
  transitions :from => :sleeping, :to => :dancing
18
19
  end
20
+
21
+ event :sleep do
22
+ transitions to: :sleeping, if: :alive?
23
+ transitions to: :dead, from: [:running, :dancing]
24
+ end
19
25
  end
20
26
 
21
27
  def runnable?
22
28
  @can_run
23
29
  end
30
+
31
+ def alive?
32
+ true
33
+ end
24
34
  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
@@ -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
 
@@ -27,4 +27,16 @@ class SimpleMultipleExample
27
27
  transitions :from => :processing, :to => :sleeping
28
28
  end
29
29
  end
30
+
31
+ aasm(:question) do
32
+ state :answered, :initial => true
33
+ state :asked
34
+
35
+ event :ask, :binding_event => :start do
36
+ transitions :from => :answered, :to => :asked
37
+ end
38
+ event :answer, :binding_event => :stop do
39
+ transitions :from => :asked, :to => :answered
40
+ end
41
+ end
30
42
  end
@@ -1,7 +1,41 @@
1
1
  require_relative 'super_class'
2
2
 
3
3
  class SubClass < SuperClass
4
+ # Add an after callback that is not defined in the parent
5
+ aasm.state_machine.events[:foo].options[:after] = [:after_foo_event]
6
+
7
+ # Add global callback that is not defined in the parent
8
+ aasm.state_machine.global_callbacks[:after_all_transitions] = :after_all_event
9
+
10
+ attr_accessor :called_after
11
+
12
+ def after_foo_event
13
+ self.called_after = true
14
+ end
15
+
16
+ def after_all_event; end
4
17
  end
5
18
 
6
19
  class SubClassMultiple < SuperClassMultiple
20
+ # Add after callbacks that are not defined in the parent
21
+ aasm(:left).state_machine.events[:foo].options[:after] = [:left_after_foo_event]
22
+ aasm(:right).state_machine.events[:close].options[:after] = [:right_after_close_event]
23
+
24
+ # Add global callback that is not defined in the parent
25
+ aasm(:left).state_machine.global_callbacks[:after_all_transitions] = :left_after_all_event
26
+ aasm(:right).state_machine.global_callbacks[:after_all_transitions] = :right_after_all_event
27
+
28
+ attr_accessor :left_called_after, :right_called_after
29
+
30
+ def left_after_foo_event
31
+ self.left_called_after = true
32
+ end
33
+
34
+ def right_after_close_event
35
+ self.right_called_after = true
36
+ end
37
+
38
+ def left_after_all_event; end
39
+
40
+ def right_after_all_event; end
7
41
  end
data/spec/spec_helper.rb CHANGED
@@ -19,39 +19,6 @@ def load_schema
19
19
  require File.dirname(__FILE__) + "/database.rb"
20
20
  end
21
21
 
22
- # Dynamoid initialization
23
- begin
24
- require 'dynamoid'
25
- require 'aws-sdk-resources'
26
-
27
- ENV['ACCESS_KEY'] ||= 'abcd'
28
- ENV['SECRET_KEY'] ||= '1234'
29
-
30
- Aws.config.update({
31
- region: 'us-west-2',
32
- credentials: Aws::Credentials.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY'])
33
- })
34
-
35
- Dynamoid.configure do |config|
36
- config.namespace = "dynamoid_tests"
37
- config.endpoint = 'http://127.0.0.1:30180'
38
- config.warn_on_scan = false
39
- end
40
-
41
- Dynamoid.logger.level = Logger::FATAL
42
-
43
- RSpec.configure do |c|
44
- c.before(:each) do
45
- Dynamoid.adapter.list_tables.each do |table|
46
- Dynamoid.adapter.delete_table(table) if table =~ /^#{Dynamoid::Config.namespace}/
47
- end
48
- Dynamoid.adapter.tables.clear
49
- end
50
- end
51
- rescue LoadError
52
- # Without Dynamoid settings
53
- end
54
-
55
22
  # custom spec helpers
56
23
  Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require File.expand_path(f) }
57
24
 
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'active_record'
4
+ puts "active_record gem found, running ActiveRecord specs \e[32m#{'✔'}\e[0m"
5
+ rescue LoadError
6
+ puts "active_record gem not found, not running ActiveRecord specs \e[31m#{'✖'}\e[0m"
7
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'dynamoid'
4
+ require 'aws-sdk-resources'
5
+ puts "dynamoid gem found, running Dynamoid specs \e[32m#{'✔'}\e[0m"
6
+
7
+ ENV['ACCESS_KEY'] ||= 'abcd'
8
+ ENV['SECRET_KEY'] ||= '1234'
9
+
10
+ Aws.config.update({
11
+ region: 'us-west-2',
12
+ credentials: Aws::Credentials.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY'])
13
+ })
14
+
15
+ Dynamoid.configure do |config|
16
+ config.namespace = "dynamoid_tests"
17
+ config.endpoint = 'http://127.0.0.1:30180'
18
+ config.warn_on_scan = false
19
+ end
20
+
21
+ Dynamoid.logger.level = Logger::FATAL
22
+
23
+ RSpec.configure do |c|
24
+ c.before(:each) do
25
+ Dynamoid.adapter.list_tables.each do |table|
26
+ Dynamoid.adapter.delete_table(table) if table =~ /^#{Dynamoid::Config.namespace}/
27
+ end
28
+ Dynamoid.adapter.tables.clear
29
+ end
30
+ end
31
+ rescue LoadError
32
+ puts "dynamoid gem not found, not running Dynamoid specs \e[31m#{'✖'}\e[0m"
33
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'mongoid'
4
+ puts "mongoid gem found, running mongoid specs \e[32m#{'✔'}\e[0m"
5
+ rescue LoadError
6
+ puts "mongoid gem not found, not running mongoid specs \e[31m#{'✖'}\e[0m"
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'redis-objects'
4
+ puts "redis-objects gem found, running Redis specs \e[32m#{'✔'}\e[0m"
5
+ rescue LoadError
6
+ puts "redis-objects gem not found, not running Redis specs \e[31m#{'✖'}\e[0m"
7
+ end
@@ -0,0 +1 @@
1
+ AASM::Configuration.hide_warnings = true
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'sequel'
4
+ puts "sequel gem found, running Sequel specs \e[32m#{'✔'}\e[0m"
5
+ rescue LoadError
6
+ puts "sequel gem not found, not running Sequel specs \e[31m#{'✖'}\e[0m"
7
+ end
@@ -1,97 +1,100 @@
1
1
  require 'spec_helper'
2
- require 'models/default_state.rb'
3
- require 'models/provided_state.rb'
4
- require 'models/active_record/persisted_state.rb'
5
- require 'models/active_record/provided_and_persisted_state.rb'
6
2
 
7
- load_schema
3
+ if defined?(ActiveRecord)
4
+ require 'models/default_state.rb'
5
+ require 'models/provided_state.rb'
6
+ require 'models/active_record/persisted_state.rb'
7
+ require 'models/active_record/provided_and_persisted_state.rb'
8
8
 
9
- describe "reading the current state" do
10
- it "uses the AASM default" do
11
- expect(DefaultState.new.aasm.current_state).to eql :alpha
12
- end
13
-
14
- it "uses the provided method" do
15
- expect(ProvidedState.new.aasm.current_state).to eql :beta
16
- end
9
+ load_schema
17
10
 
18
- it "uses the persistence storage" do
19
- expect(PersistedState.new.aasm.current_state).to eql :alpha
20
- end
11
+ describe "reading the current state" do
12
+ it "uses the AASM default" do
13
+ expect(DefaultState.new.aasm.current_state).to eql :alpha
14
+ end
21
15
 
22
- it "uses the provided method even if persisted" do
23
- expect(ProvidedAndPersistedState.new.aasm.current_state).to eql :gamma
24
- end
16
+ it "uses the provided method" do
17
+ expect(ProvidedState.new.aasm.current_state).to eql :beta
18
+ end
25
19
 
26
- context "after dup" do
27
20
  it "uses the persistence storage" do
28
- source = PersistedState.create!
29
- copy = source.dup
30
- copy.save!
21
+ expect(PersistedState.new.aasm.current_state).to eql :alpha
22
+ end
31
23
 
32
- copy.release!
24
+ it "uses the provided method even if persisted" do
25
+ expect(ProvidedAndPersistedState.new.aasm.current_state).to eql :gamma
26
+ end
27
+
28
+ context "after dup" do
29
+ it "uses the persistence storage" do
30
+ source = PersistedState.create!
31
+ copy = source.dup
32
+ copy.save!
33
33
 
34
- expect(source.aasm_state).to eql 'alpha'
35
- expect(source.aasm.current_state).to eql :alpha
34
+ copy.release!
36
35
 
37
- source2 = PersistedState.find(source.id)
38
- expect(source2.reload.aasm_state).to eql 'alpha'
39
- expect(source2.aasm.current_state).to eql :alpha
36
+ expect(source.aasm_state).to eql 'alpha'
37
+ expect(source.aasm.current_state).to eql :alpha
40
38
 
41
- expect(copy.aasm_state).to eql 'beta'
42
- expect(copy.aasm.current_state).to eql :beta
39
+ source2 = PersistedState.find(source.id)
40
+ expect(source2.reload.aasm_state).to eql 'alpha'
41
+ expect(source2.aasm.current_state).to eql :alpha
42
+
43
+ expect(copy.aasm_state).to eql 'beta'
44
+ expect(copy.aasm.current_state).to eql :beta
45
+ end
43
46
  end
44
47
  end
45
- end
46
48
 
47
- describe "writing and persisting the current state" do
48
- it "uses the AASM default" do
49
- o = DefaultState.new
50
- o.release!
51
- expect(o.persisted_store).to be_nil
52
- end
49
+ describe "writing and persisting the current state" do
50
+ it "uses the AASM default" do
51
+ o = DefaultState.new
52
+ o.release!
53
+ expect(o.persisted_store).to be_nil
54
+ end
53
55
 
54
- it "uses the provided method" do
55
- o = ProvidedState.new
56
- o.release!
57
- expect(o.persisted_store).to eql :beta
58
- end
56
+ it "uses the provided method" do
57
+ o = ProvidedState.new
58
+ o.release!
59
+ expect(o.persisted_store).to eql :beta
60
+ end
59
61
 
60
- it "uses the persistence storage" do
61
- o = PersistedState.new
62
- o.release!
63
- expect(o.persisted_store).to be_nil
64
- end
62
+ it "uses the persistence storage" do
63
+ o = PersistedState.new
64
+ o.release!
65
+ expect(o.persisted_store).to be_nil
66
+ end
65
67
 
66
- it "uses the provided method even if persisted" do
67
- o = ProvidedAndPersistedState.new
68
- o.release!
69
- expect(o.persisted_store).to eql :beta
68
+ it "uses the provided method even if persisted" do
69
+ o = ProvidedAndPersistedState.new
70
+ o.release!
71
+ expect(o.persisted_store).to eql :beta
72
+ end
70
73
  end
71
- end
72
74
 
73
- describe "writing the current state without persisting it" do
74
- it "uses the AASM default" do
75
- o = DefaultState.new
76
- o.release
77
- expect(o.transient_store).to be_nil
78
- end
75
+ describe "writing the current state without persisting it" do
76
+ it "uses the AASM default" do
77
+ o = DefaultState.new
78
+ o.release
79
+ expect(o.transient_store).to be_nil
80
+ end
79
81
 
80
- it "uses the provided method" do
81
- o = ProvidedState.new
82
- o.release
83
- expect(o.transient_store).to eql :beta
84
- end
82
+ it "uses the provided method" do
83
+ o = ProvidedState.new
84
+ o.release
85
+ expect(o.transient_store).to eql :beta
86
+ end
85
87
 
86
- it "uses the persistence storage" do
87
- o = PersistedState.new
88
- o.release
89
- expect(o.transient_store).to be_nil
90
- end
88
+ it "uses the persistence storage" do
89
+ o = PersistedState.new
90
+ o.release
91
+ expect(o.transient_store).to be_nil
92
+ end
91
93
 
92
- it "uses the provided method even if persisted" do
93
- o = ProvidedAndPersistedState.new
94
- o.release
95
- expect(o.transient_store).to eql :beta
94
+ it "uses the provided method even if persisted" do
95
+ o = ProvidedAndPersistedState.new
96
+ o.release
97
+ expect(o.transient_store).to eql :beta
98
+ end
96
99
  end
97
100
  end
@@ -118,6 +118,7 @@ describe 'callbacks for the new DSL' do
118
118
  expect(callback).to receive(:before_enter_closed).once.ordered
119
119
  expect(callback).to receive(:enter_closed).once.ordered
120
120
  expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
121
+ expect(callback).to receive(:event_before_success).once.ordered
121
122
  expect(callback).to receive(:success_transition).once.ordered.and_return(true) # these should be after the state changes
122
123
  expect(callback).to receive(:after_exit_open).once.ordered
123
124
  expect(callback).to receive(:after_enter_closed).once.ordered
@@ -143,6 +144,7 @@ describe 'callbacks for the new DSL' do
143
144
  expect(callback).to_not receive(:before_enter_closed)
144
145
  expect(callback).to_not receive(:enter_closed)
145
146
  expect(callback).to_not receive(:aasm_write_state)
147
+ expect(callback).to_not receive(:event_before_success)
146
148
  expect(callback).to_not receive(:success_transition)
147
149
  expect(callback).to_not receive(:after_exit_open)
148
150
  expect(callback).to_not receive(:after_enter_closed)
@@ -186,6 +188,7 @@ describe 'callbacks for the new DSL' do
186
188
  expect(callback).to_not receive(:before_enter_closed)
187
189
  expect(callback).to_not receive(:enter_closed)
188
190
  expect(callback).to_not receive(:aasm_write_state)
191
+ expect(callback).to_not receive(:event_before_success)
189
192
  expect(callback).to_not receive(:success_transition)
190
193
  expect(callback).to_not receive(:after_exit_open)
191
194
  expect(callback).to_not receive(:after_enter_closed)
@@ -217,6 +220,7 @@ describe 'callbacks for the new DSL' do
217
220
  expect(callback).to receive(:after).once.ordered
218
221
 
219
222
  expect(callback).to_not receive(:transitioning)
223
+ expect(callback).to_not receive(:event_before_success)
220
224
  expect(callback).to_not receive(:success_transition)
221
225
  expect(callback).to_not receive(:before_enter_closed)
222
226
  expect(callback).to_not receive(:enter_closed)
@@ -240,6 +244,7 @@ describe 'callbacks for the new DSL' do
240
244
  expect(callback).to_not receive(:before_enter_closed)
241
245
  expect(callback).to_not receive(:enter_closed)
242
246
  expect(callback).to_not receive(:aasm_write_state)
247
+ expect(callback).to_not receive(:event_before_success)
243
248
  expect(callback).to_not receive(:success_transition)
244
249
  expect(callback).to_not receive(:after_exit_open)
245
250
  expect(callback).to_not receive(:after_enter_closed)
@@ -325,6 +325,12 @@ describe 'parametrised events' do
325
325
  pe.dress!(:working, 'blue', 'jeans')
326
326
  end
327
327
 
328
+ it 'should call :after transition method if arg is nil' do
329
+ dryer = nil
330
+ expect(pe).to receive(:wet_hair).with(dryer)
331
+ pe.shower!(dryer)
332
+ end
333
+
328
334
  it 'should call :after transition proc' do
329
335
  pe.wakeup!(:showering)
330
336
  expect(pe).to receive(:wear_clothes).with('purple', 'slacks')
@@ -344,6 +350,12 @@ describe 'parametrised events' do
344
350
  pe.dress!(:working, 'foundation', 'SPF')
345
351
  end
346
352
 
353
+ it 'should call :success transition method if arg is nil' do
354
+ shirt_color = nil
355
+ expect(pe).to receive(:wear_clothes).with(shirt_color)
356
+ pe.shower!(shirt_color)
357
+ end
358
+
347
359
  it 'should call :success transition proc' do
348
360
  pe.wakeup!(:showering)
349
361
  expect(pe).to receive(:wear_makeup).with('purple', 'slacks')
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "guards with params" do
4
+ let(:guard) { GuardWithParamsMultiple.new }
5
+ let(:user) {GuardParamsClass.new}
6
+
7
+ it "list permitted states" do
8
+ expect(guard.aasm(:left).states({:permitted => true}, user).map(&:name)).to eql [:reviewed]
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "guards with params" do
4
+ let(:guard) { GuardWithParams.new }
5
+ let(:user) {GuardParamsClass.new}
6
+
7
+ it "list permitted states" do
8
+ expect(guard.aasm.states({:permitted => true}, user).map(&:name)).to eql [:reviewed]
9
+ end
10
+
11
+ it "list no states if user is blank" do
12
+ expect(guard.aasm.states({:permitted => true}, nil).map(&:name)).to eql []
13
+ end
14
+ end
@@ -74,6 +74,11 @@ describe 'inspection for common cases' do
74
74
  expect(states).to include(:running)
75
75
  expect(states).to_not include(:dancing)
76
76
  end
77
+
78
+ it "transitions to correct state if from state is missing from one transitions" do
79
+ multi.sleep
80
+ expect(multi.aasm.current_state).to eq(:sleeping)
81
+ end
77
82
  end
78
83
 
79
84
  it 'should list states in the order they have been defined' do