state_machine 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/.travis.yml +23 -7
  2. data/Appraisals +31 -25
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +3 -1
  5. data/gemfiles/active_model-3.0.0.gemfile.lock +7 -5
  6. data/gemfiles/active_model-3.0.5.gemfile.lock +7 -5
  7. data/gemfiles/active_model-3.1.1.gemfile.lock +6 -4
  8. data/gemfiles/active_record-2.0.0.gemfile +1 -1
  9. data/gemfiles/active_record-2.0.0.gemfile.lock +7 -5
  10. data/gemfiles/active_record-2.0.5.gemfile +1 -1
  11. data/gemfiles/active_record-2.0.5.gemfile.lock +7 -5
  12. data/gemfiles/active_record-2.1.0.gemfile +1 -1
  13. data/gemfiles/active_record-2.1.0.gemfile.lock +7 -5
  14. data/gemfiles/active_record-2.1.2.gemfile +1 -1
  15. data/gemfiles/active_record-2.1.2.gemfile.lock +7 -5
  16. data/gemfiles/active_record-2.2.3.gemfile +1 -1
  17. data/gemfiles/active_record-2.2.3.gemfile.lock +7 -5
  18. data/gemfiles/active_record-2.3.12.gemfile +1 -1
  19. data/gemfiles/active_record-2.3.12.gemfile.lock +7 -5
  20. data/gemfiles/active_record-3.0.0.gemfile +1 -1
  21. data/gemfiles/active_record-3.0.0.gemfile.lock +8 -6
  22. data/gemfiles/active_record-3.0.5.gemfile +1 -1
  23. data/gemfiles/active_record-3.0.5.gemfile.lock +8 -6
  24. data/gemfiles/active_record-3.1.1.gemfile +1 -1
  25. data/gemfiles/active_record-3.1.1.gemfile.lock +7 -5
  26. data/gemfiles/data_mapper-0.10.2.gemfile +3 -3
  27. data/gemfiles/data_mapper-0.10.2.gemfile.lock +14 -5
  28. data/gemfiles/data_mapper-0.9.11.gemfile +3 -3
  29. data/gemfiles/data_mapper-0.9.11.gemfile.lock +7 -5
  30. data/gemfiles/data_mapper-0.9.4.gemfile +3 -3
  31. data/gemfiles/data_mapper-0.9.4.gemfile.lock +13 -13
  32. data/gemfiles/data_mapper-0.9.7.gemfile +3 -3
  33. data/gemfiles/data_mapper-0.9.7.gemfile.lock +13 -13
  34. data/gemfiles/data_mapper-1.0.0.gemfile +3 -3
  35. data/gemfiles/data_mapper-1.0.0.gemfile.lock +17 -8
  36. data/gemfiles/data_mapper-1.0.1.gemfile +3 -3
  37. data/gemfiles/data_mapper-1.0.1.gemfile.lock +17 -8
  38. data/gemfiles/data_mapper-1.0.2.gemfile +3 -3
  39. data/gemfiles/data_mapper-1.0.2.gemfile.lock +17 -8
  40. data/gemfiles/data_mapper-1.1.0.gemfile +3 -3
  41. data/gemfiles/data_mapper-1.1.0.gemfile.lock +17 -8
  42. data/gemfiles/data_mapper-1.2.0.gemfile +3 -3
  43. data/gemfiles/data_mapper-1.2.0.gemfile.lock +13 -4
  44. data/gemfiles/default.gemfile.lock +7 -5
  45. data/gemfiles/graphviz-0.9.0.gemfile.lock +6 -4
  46. data/gemfiles/graphviz-0.9.21.gemfile.lock +6 -4
  47. data/gemfiles/graphviz-1.0.0.gemfile.lock +6 -4
  48. data/gemfiles/mongo_mapper-0.10.0.gemfile.lock +6 -3
  49. data/gemfiles/mongo_mapper-0.5.5.gemfile +1 -1
  50. data/gemfiles/mongo_mapper-0.5.5.gemfile.lock +7 -5
  51. data/gemfiles/mongo_mapper-0.5.8.gemfile +1 -1
  52. data/gemfiles/mongo_mapper-0.5.8.gemfile.lock +7 -5
  53. data/gemfiles/mongo_mapper-0.6.0.gemfile +1 -1
  54. data/gemfiles/mongo_mapper-0.6.0.gemfile.lock +7 -5
  55. data/gemfiles/mongo_mapper-0.6.10.gemfile +1 -1
  56. data/gemfiles/mongo_mapper-0.6.10.gemfile.lock +7 -5
  57. data/gemfiles/mongo_mapper-0.7.0.gemfile +1 -1
  58. data/gemfiles/mongo_mapper-0.7.0.gemfile.lock +7 -5
  59. data/gemfiles/mongo_mapper-0.7.5.gemfile +1 -1
  60. data/gemfiles/mongo_mapper-0.7.5.gemfile.lock +7 -5
  61. data/gemfiles/mongo_mapper-0.8.0.gemfile +2 -2
  62. data/gemfiles/mongo_mapper-0.8.0.gemfile.lock +7 -5
  63. data/gemfiles/mongo_mapper-0.8.3.gemfile +2 -2
  64. data/gemfiles/mongo_mapper-0.8.3.gemfile.lock +7 -5
  65. data/gemfiles/mongo_mapper-0.8.4.gemfile +1 -1
  66. data/gemfiles/mongo_mapper-0.8.4.gemfile.lock +11 -8
  67. data/gemfiles/mongo_mapper-0.8.6.gemfile +1 -1
  68. data/gemfiles/mongo_mapper-0.8.6.gemfile.lock +11 -8
  69. data/gemfiles/mongo_mapper-0.9.0.gemfile.lock +14 -11
  70. data/gemfiles/mongoid-2.0.0.gemfile.lock +22 -17
  71. data/gemfiles/mongoid-2.1.4.gemfile.lock +21 -16
  72. data/gemfiles/mongoid-2.2.4.gemfile.lock +11 -8
  73. data/gemfiles/mongoid-2.3.3.gemfile.lock +11 -8
  74. data/gemfiles/sequel-2.11.0.gemfile.lock +7 -5
  75. data/gemfiles/sequel-2.12.0.gemfile.lock +7 -5
  76. data/gemfiles/sequel-2.8.0.gemfile.lock +7 -5
  77. data/gemfiles/sequel-3.0.0.gemfile.lock +7 -5
  78. data/gemfiles/sequel-3.13.0.gemfile.lock +7 -5
  79. data/gemfiles/sequel-3.14.0.gemfile.lock +7 -5
  80. data/gemfiles/sequel-3.23.0.gemfile.lock +7 -5
  81. data/gemfiles/sequel-3.24.0.gemfile.lock +7 -5
  82. data/gemfiles/sequel-3.29.0.gemfile.lock +5 -3
  83. data/lib/state_machine.rb +7 -1
  84. data/lib/state_machine/eval_helpers.rb +8 -9
  85. data/lib/state_machine/event.rb +10 -2
  86. data/lib/state_machine/integrations.rb +0 -1
  87. data/lib/state_machine/integrations/active_model.rb +46 -35
  88. data/lib/state_machine/integrations/active_record.rb +8 -0
  89. data/lib/state_machine/integrations/active_record/versions.rb +0 -20
  90. data/lib/state_machine/integrations/data_mapper.rb +22 -21
  91. data/lib/state_machine/integrations/data_mapper/versions.rb +0 -27
  92. data/lib/state_machine/integrations/mongo_mapper.rb +8 -0
  93. data/lib/state_machine/integrations/mongo_mapper/versions.rb +0 -4
  94. data/lib/state_machine/integrations/mongoid.rb +15 -2
  95. data/lib/state_machine/integrations/mongoid/versions.rb +0 -7
  96. data/lib/state_machine/integrations/sequel.rb +14 -0
  97. data/lib/state_machine/machine.rb +12 -0
  98. data/lib/state_machine/state.rb +4 -3
  99. data/lib/state_machine/state_context.rb +10 -9
  100. data/lib/state_machine/transition.rb +6 -1
  101. data/lib/state_machine/version.rb +1 -1
  102. data/state_machine.gemspec +1 -1
  103. data/test/functional/state_machine_test.rb +21 -1
  104. data/test/unit/event_test.rb +10 -0
  105. data/test/unit/integrations/active_model_test.rb +31 -29
  106. data/test/unit/integrations/active_record_test.rb +56 -26
  107. data/test/unit/integrations/data_mapper_test.rb +34 -57
  108. data/test/unit/integrations/mongo_mapper_test.rb +30 -24
  109. data/test/unit/integrations/mongoid_test.rb +114 -29
  110. data/test/unit/integrations/sequel_test.rb +36 -0
  111. data/test/unit/invalid_transition_test.rb +38 -0
  112. data/test/unit/machine_test.rb +38 -0
  113. data/test/unit/state_context_test.rb +29 -9
  114. data/test/unit/state_test.rb +21 -1
  115. data/test/unit/transition_collection_test.rb +72 -26
  116. data/test/unit/transition_test.rb +84 -73
  117. metadata +8 -8
@@ -75,3 +75,41 @@ class InvalidTransitionWithNamespaceTest < Test::Unit::TestCase
75
75
  assert_equal :alarm_active, @invalid_transition.qualified_from_name
76
76
  end
77
77
  end
78
+
79
+ class InvalidTransitionWithIntegrationTest < Test::Unit::TestCase
80
+ def setup
81
+ StateMachine::Integrations.const_set('Custom', Module.new do
82
+ include StateMachine::Integrations::Base
83
+
84
+ def errors_for(object)
85
+ object.errors
86
+ end
87
+ end)
88
+
89
+ @klass = Class.new do
90
+ attr_accessor :errors
91
+ end
92
+ @machine = StateMachine::Machine.new(@klass, :integration => :custom)
93
+ @machine.state :parked
94
+ @machine.event :ignite
95
+
96
+ @object = @klass.new
97
+ @object.state = 'parked'
98
+ end
99
+
100
+ def test_should_generate_a_message_without_reasons_if_empty
101
+ @object.errors = ''
102
+ invalid_transition = StateMachine::InvalidTransition.new(@object, @machine, :ignite)
103
+ assert_equal 'Cannot transition state via :ignite from :parked', invalid_transition.message
104
+ end
105
+
106
+ def test_should_generate_a_message_with_error_reasons_if_errors_found
107
+ @object.errors = 'Id is invalid, Name is invalid'
108
+ invalid_transition = StateMachine::InvalidTransition.new(@object, @machine, :ignite)
109
+ assert_equal 'Cannot transition state via :ignite from :parked (Reason(s): Id is invalid, Name is invalid)', invalid_transition.message
110
+ end
111
+
112
+ def teardown
113
+ StateMachine::Integrations.send(:remove_const, 'Custom')
114
+ end
115
+ end
@@ -125,6 +125,10 @@ class MachineByDefaultTest < Test::Unit::TestCase
125
125
  assert @object.respond_to?(:state_paths)
126
126
  end
127
127
 
128
+ def test_should_define_an_event_runner_for_the_attribute
129
+ assert @object.respond_to?(:fire_state_event)
130
+ end
131
+
128
132
  def test_should_not_define_an_event_attribute_reader
129
133
  assert !@object.respond_to?(:state_event)
130
134
  end
@@ -222,6 +226,10 @@ class MachineWithCustomNameTest < Test::Unit::TestCase
222
226
  assert @object.respond_to?(:status_transitions)
223
227
  end
224
228
 
229
+ def test_should_define_an_event_runner_for_the_attribute
230
+ assert @object.respond_to?(:fire_status_event)
231
+ end
232
+
225
233
  def test_should_define_a_human_attribute_name_reader_for_the_attribute
226
234
  assert @klass.respond_to?(:human_status_name)
227
235
  end
@@ -492,6 +500,10 @@ class MachineWithoutIntegrationTest < Test::Unit::TestCase
492
500
  def test_reset_should_do_nothing
493
501
  assert_nil @machine.reset(@object)
494
502
  end
503
+
504
+ def test_errors_for_should_be_empty
505
+ assert_equal '', @machine.errors_for(@object)
506
+ end
495
507
  end
496
508
 
497
509
  class MachineWithCustomIntegrationTest < Test::Unit::TestCase
@@ -1500,6 +1512,10 @@ class MachineWithConflictingHelpersBeforeDefinitionTest < Test::Unit::TestCase
1500
1512
  def state_paths
1501
1513
  [[{:parked => :idling}]]
1502
1514
  end
1515
+
1516
+ def fire_state_event
1517
+ true
1518
+ end
1503
1519
  end
1504
1520
  @klass = Class.new(@superclass)
1505
1521
 
@@ -1578,10 +1594,15 @@ class MachineWithConflictingHelpersBeforeDefinitionTest < Test::Unit::TestCase
1578
1594
  assert_equal [[{:parked => :idling}]], @object.state_paths
1579
1595
  end
1580
1596
 
1597
+ def test_should_not_redefine_event_runner
1598
+ assert_equal true, @object.fire_state_event
1599
+ end
1600
+
1581
1601
  def test_should_output_warning
1582
1602
  expected = [
1583
1603
  'Instance method "state_events"',
1584
1604
  'Instance method "state_transitions"',
1605
+ 'Instance method "fire_state_event"',
1585
1606
  'Instance method "state_paths"',
1586
1607
  'Class method "human_state_name"',
1587
1608
  'Class method "human_state_event_name"',
@@ -1665,6 +1686,10 @@ class MachineWithConflictingHelpersAfterDefinitionTest < Test::Unit::TestCase
1665
1686
  def state_paths
1666
1687
  [[{:parked => :idling}]]
1667
1688
  end
1689
+
1690
+ def fire_state_event
1691
+ true
1692
+ end
1668
1693
  end
1669
1694
 
1670
1695
  StateMachine::Integrations.const_set('Custom', Module.new do
@@ -1742,6 +1767,10 @@ class MachineWithConflictingHelpersAfterDefinitionTest < Test::Unit::TestCase
1742
1767
  assert_equal [[{:parked => :idling}]], @object.state_paths
1743
1768
  end
1744
1769
 
1770
+ def test_should_not_redefine_event_runner
1771
+ assert_equal true, @object.fire_state_event
1772
+ end
1773
+
1745
1774
  def test_should_allow_super_chaining
1746
1775
  @klass.class_eval do
1747
1776
  def self.with_state(*states)
@@ -1801,6 +1830,10 @@ class MachineWithConflictingHelpersAfterDefinitionTest < Test::Unit::TestCase
1801
1830
  def state_paths
1802
1831
  super
1803
1832
  end
1833
+
1834
+ def fire_state_event(event)
1835
+ super
1836
+ end
1804
1837
  end
1805
1838
 
1806
1839
  assert_equal [], @klass.with_state
@@ -1820,6 +1853,7 @@ class MachineWithConflictingHelpersAfterDefinitionTest < Test::Unit::TestCase
1820
1853
  assert_equal [], @object.state_events
1821
1854
  assert_equal [], @object.state_transitions
1822
1855
  assert_equal [], @object.state_paths
1856
+ assert_equal false, @object.fire_state_event(:ignite)
1823
1857
  end
1824
1858
 
1825
1859
  def test_should_not_output_warning
@@ -2954,6 +2988,10 @@ class MachineWithCustomAttributeTest < Test::Unit::TestCase
2954
2988
  assert @object.respond_to?(:state_paths)
2955
2989
  end
2956
2990
 
2991
+ def test_should_define_an_event_runner_for_the_attribute
2992
+ assert @object.respond_to?(:fire_state_event)
2993
+ end
2994
+
2957
2995
  def test_should_define_a_human_attribute_name_reader
2958
2996
  assert @klass.respond_to?(:human_state_name)
2959
2997
  end
@@ -41,11 +41,6 @@ class StateContextTransitionTest < Test::Unit::TestCase
41
41
  assert_equal 'Invalid key(s): except_to', exception.message
42
42
  end
43
43
 
44
- def test_should_not_allow_from
45
- exception = assert_raise(ArgumentError) { @state_context.transition(:from => :idling) }
46
- assert_equal 'Invalid key(s): from', exception.message
47
- end
48
-
49
44
  def test_should_not_allow_except_from
50
45
  exception = assert_raise(ArgumentError) { @state_context.transition(:except_from => :idling) }
51
46
  assert_equal 'Invalid key(s): except_from', exception.message
@@ -63,15 +58,40 @@ class StateContextTransitionTest < Test::Unit::TestCase
63
58
 
64
59
  def test_should_require_on_event
65
60
  exception = assert_raise(ArgumentError) { @state_context.transition(:to => :idling) }
66
- assert_equal 'Must specify :to state and :on event', exception.message
61
+ assert_equal 'Must specify :on event', exception.message
67
62
  end
68
63
 
69
- def test_should_require_to_state
64
+ def test_should_not_allow_missing_from_and_to
70
65
  exception = assert_raise(ArgumentError) { @state_context.transition(:on => :ignite) }
71
- assert_equal 'Must specify :to state and :on event', exception.message
66
+ assert_equal 'Must specify either :to or :from state', exception.message
67
+ end
68
+
69
+ def test_should_not_allow_from_and_to
70
+ exception = assert_raise(ArgumentError) { @state_context.transition(:on => :ignite, :from => :parked, :to => :idling) }
71
+ assert_equal 'Must specify either :to or :from state', exception.message
72
+ end
73
+
74
+ def test_should_allow_to_state_if_missing_from_state
75
+ assert_nothing_raised { @state_context.transition(:on => :park, :from => :parked) }
76
+ end
77
+
78
+ def test_should_allow_from_state_if_missing_to_state
79
+ assert_nothing_raised { @state_context.transition(:on => :ignite, :to => :idling) }
80
+ end
81
+
82
+ def test_should_automatically_set_to_option_with_from_state
83
+ branch = @state_context.transition(:from => :idling, :on => :park)
84
+ assert_instance_of StateMachine::Branch, branch
85
+
86
+ state_requirements = branch.state_requirements
87
+ assert_equal 1, state_requirements.length
88
+
89
+ from_requirement = state_requirements[0][:to]
90
+ assert_instance_of StateMachine::WhitelistMatcher, from_requirement
91
+ assert_equal [:parked], from_requirement.values
72
92
  end
73
93
 
74
- def test_should_automatically_set_from_option
94
+ def test_should_automatically_set_from_option_with_to_state
75
95
  branch = @state_context.transition(:to => :idling, :on => :ignite)
76
96
  assert_instance_of StateMachine::Branch, branch
77
97
 
@@ -779,12 +779,32 @@ class StateWithInvalidMethodCallTest < Test::Unit::TestCase
779
779
  end
780
780
  end
781
781
 
782
- class StateWithValidMethodCallTest < Test::Unit::TestCase
782
+ class StateWithValidMethodCallForDifferentStateTest < Test::Unit::TestCase
783
783
  def setup
784
784
  @klass = Class.new
785
785
  @machine = StateMachine::Machine.new(@klass)
786
786
  @ancestors = @klass.ancestors
787
787
  @machine.states << @state = StateMachine::State.new(@machine, :idling)
788
+ @state.context do
789
+ def speed
790
+ 0
791
+ end
792
+ end
793
+
794
+ @object = @klass.new
795
+ end
796
+
797
+ def test_should_call_method_missing_arg
798
+ assert_equal 1, @state.call(@object, :speed, lambda {1})
799
+ end
800
+ end
801
+
802
+ class StateWithValidMethodCallForCurrentStaeTest < Test::Unit::TestCase
803
+ def setup
804
+ @klass = Class.new
805
+ @machine = StateMachine::Machine.new(@klass, :initial => :idling)
806
+ @ancestors = @klass.ancestors
807
+ @state = @machine.state(:idling)
788
808
  @state.context do
789
809
  def speed(arg = nil)
790
810
  block_given? ? [arg, yield] : arg
@@ -1116,7 +1116,6 @@ class TransitionCollectionWithSkippedAfterCallbacksTest < Test::Unit::TestCase
1116
1116
  @machine.state :idling
1117
1117
  @machine.event :ignite
1118
1118
  @machine.after_transition {@ran_after = true}
1119
- @machine.around_transition {|block| @ran_around_before = true; block.call; @ran_around_after = true}
1120
1119
 
1121
1120
  @object = @klass.new
1122
1121
 
@@ -1134,25 +1133,70 @@ class TransitionCollectionWithSkippedAfterCallbacksTest < Test::Unit::TestCase
1134
1133
  assert !@ran_after
1135
1134
  end
1136
1135
 
1137
- def test_should_not_run_around_callbacks_after_yield
1138
- assert !@ran_around_after
1139
- end
1140
-
1141
1136
  def test_should_run_after_callbacks_on_subsequent_perform
1142
1137
  StateMachine::TransitionCollection.new([@transition]).perform
1143
1138
  assert @ran_after
1144
1139
  end
1145
-
1146
- def test_should_run_around_callbacks_after_yield_on_subsequent_perform
1147
- StateMachine::TransitionCollection.new([@transition]).perform
1148
- assert @ran_around_after
1140
+ end
1141
+
1142
+ if RUBY_PLATFORM != 'java'
1143
+ class TransitionCollectionWithSkippedAfterCallbacksAndAroundCallbacksTest < Test::Unit::TestCase
1144
+ def setup
1145
+ @klass = Class.new
1146
+
1147
+ @machine = StateMachine::Machine.new(@klass, :initial => :parked)
1148
+ @machine.state :idling
1149
+ @machine.event :ignite
1150
+ @machine.around_transition {|block| @ran_around_before = true; block.call; @ran_around_after = true}
1151
+
1152
+ @object = @klass.new
1153
+
1154
+ @transitions = StateMachine::TransitionCollection.new([
1155
+ @transition = StateMachine::Transition.new(@object, @machine, :ignite, :parked, :idling)
1156
+ ], :after => false)
1157
+ @result = @transitions.perform
1158
+ end
1159
+
1160
+ def test_should_succeed
1161
+ assert_equal true, @result
1162
+ end
1163
+
1164
+ def test_should_not_run_around_callbacks_after_yield
1165
+ assert !@ran_around_after
1166
+ end
1167
+
1168
+ def test_should_run_around_callbacks_after_yield_on_subsequent_perform
1169
+ StateMachine::TransitionCollection.new([@transition]).perform
1170
+ assert @ran_around_after
1171
+ end
1172
+
1173
+ def test_should_not_rerun_around_callbacks_before_yield_on_subsequent_perform
1174
+ @ran_around_before = false
1175
+ StateMachine::TransitionCollection.new([@transition]).perform
1176
+
1177
+ assert !@ran_around_before
1178
+ end
1149
1179
  end
1150
-
1151
- def test_should_not_rerun_around_callbacks_before_yield_on_subsequent_perform
1152
- @ran_around_before = false
1153
- StateMachine::TransitionCollection.new([@transition]).perform
1180
+ else
1181
+ class TransitionCollectionWithSkippedAfterCallbacksAndAroundCallbacksTest < Test::Unit::TestCase
1182
+ def setup
1183
+ @klass = Class.new
1184
+
1185
+ @machine = StateMachine::Machine.new(@klass, :initial => :parked)
1186
+ @machine.state :idling
1187
+ @machine.event :ignite
1188
+ @machine.around_transition {|block| @ran_around_before = true; block.call; @ran_around_after = true}
1189
+
1190
+ @object = @klass.new
1191
+
1192
+ @transitions = StateMachine::TransitionCollection.new([
1193
+ @transition = StateMachine::Transition.new(@object, @machine, :ignite, :parked, :idling)
1194
+ ], :after => false)
1195
+ end
1154
1196
 
1155
- assert !@ran_around_before
1197
+ def test_should_raise_exception
1198
+ assert_raise(ArgumentError) { @transitions.perform }
1199
+ end
1156
1200
  end
1157
1201
  end
1158
1202
 
@@ -2073,19 +2117,21 @@ class AttributeTransitionCollectionMarshallingTest < Test::Unit::TestCase
2073
2117
  end
2074
2118
  end
2075
2119
 
2076
- def test_should_marshal_during_around_callbacks_before_yield
2077
- @machine.around_transition {|object, transition, block| Marshal.dump(object); block.call}
2078
- assert_nothing_raised do
2079
- transitions(:after => false).perform { true }
2080
- transitions.perform { true }
2120
+ if RUBY_PLATFORM != 'java'
2121
+ def test_should_marshal_during_around_callbacks_before_yield
2122
+ @machine.around_transition {|object, transition, block| Marshal.dump(object); block.call}
2123
+ assert_nothing_raised do
2124
+ transitions(:after => false).perform { true }
2125
+ transitions.perform { true }
2126
+ end
2081
2127
  end
2082
- end
2083
-
2084
- def test_should_marshal_during_around_callbacks_after_yield
2085
- @machine.around_transition {|object, transition, block| block.call; Marshal.dump(object)}
2086
- assert_nothing_raised do
2087
- transitions(:after => false).perform { true }
2088
- transitions.perform { true }
2128
+
2129
+ def test_should_marshal_during_around_callbacks_after_yield
2130
+ @machine.around_transition {|object, transition, block| block.call; Marshal.dump(object)}
2131
+ assert_nothing_raised do
2132
+ transitions(:after => false).perform { true }
2133
+ transitions.perform { true }
2134
+ end
2089
2135
  end
2090
2136
  end
2091
2137
 
@@ -1209,13 +1209,6 @@ class TransitionWithAfterCallbacksSkippedTest < Test::Unit::TestCase
1209
1209
  assert @run
1210
1210
  end
1211
1211
 
1212
- def test_should_run_around_callbacks_before_yield
1213
- @machine.around_transition {|block| @run = true; block.call}
1214
-
1215
- assert_equal true, @transition.run_callbacks(:after => false)
1216
- assert @run
1217
- end
1218
-
1219
1212
  def test_should_not_run_after_callbacks
1220
1213
  @machine.after_transition {@run = true}
1221
1214
 
@@ -1223,82 +1216,100 @@ class TransitionWithAfterCallbacksSkippedTest < Test::Unit::TestCase
1223
1216
  assert !@run
1224
1217
  end
1225
1218
 
1226
- def test_should_not_run_around_callbacks_after_yield
1227
- @machine.around_transition {|block| block.call; @run = true}
1228
-
1229
- assert_equal true, @transition.run_callbacks(:after => false)
1230
- assert !@run
1231
- end
1232
-
1233
- def test_should_continue_around_transition_execution_on_second_call
1234
- @callbacks = []
1235
- @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1}
1236
- @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2}
1237
- @machine.after_transition {@callbacks << :after}
1238
-
1239
- assert_equal true, @transition.run_callbacks(:after => false)
1240
- assert_equal [:before_around_1, :before_around_2], @callbacks
1241
-
1242
- assert_equal true, @transition.run_callbacks
1243
- assert_equal [:before_around_1, :before_around_2, :after_around_2, :after_around_1, :after], @callbacks
1244
- end
1245
-
1246
- def test_should_not_run_further_callbacks_if_halted_during_continue_around_transition
1247
- @callbacks = []
1248
- @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1}
1249
- @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2; throw :halt}
1250
- @machine.after_transition {@callbacks << :after}
1251
-
1252
- assert_equal true, @transition.run_callbacks(:after => false)
1253
- assert_equal [:before_around_1, :before_around_2], @callbacks
1254
-
1255
- assert_equal true, @transition.run_callbacks
1256
- assert_equal [:before_around_1, :before_around_2, :after_around_2], @callbacks
1257
- end
1258
-
1259
- def test_should_not_be_able_to_continue_twice
1260
- @count = 0
1261
- @machine.around_transition {|block| block.call; @count += 1}
1262
- @machine.after_transition {@count += 1}
1219
+ if RUBY_PLATFORM != 'java'
1220
+ def test_should_run_around_callbacks_before_yield
1221
+ @machine.around_transition {|block| @run = true; block.call}
1222
+
1223
+ assert_equal true, @transition.run_callbacks(:after => false)
1224
+ assert @run
1225
+ end
1263
1226
 
1264
- @transition.run_callbacks(:after => false)
1227
+ def test_should_not_run_around_callbacks_after_yield
1228
+ @machine.around_transition {|block| block.call; @run = true}
1229
+
1230
+ assert_equal true, @transition.run_callbacks(:after => false)
1231
+ assert !@run
1232
+ end
1265
1233
 
1266
- 2.times do
1234
+ def test_should_continue_around_transition_execution_on_second_call
1235
+ @callbacks = []
1236
+ @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1}
1237
+ @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2}
1238
+ @machine.after_transition {@callbacks << :after}
1239
+
1240
+ assert_equal true, @transition.run_callbacks(:after => false)
1241
+ assert_equal [:before_around_1, :before_around_2], @callbacks
1242
+
1267
1243
  assert_equal true, @transition.run_callbacks
1268
- assert_equal 2, @count
1244
+ assert_equal [:before_around_1, :before_around_2, :after_around_2, :after_around_1, :after], @callbacks
1269
1245
  end
1270
- end
1271
-
1272
- def test_should_not_be_able_to_continue_again_after_halted
1273
- @count = 0
1274
- @machine.around_transition {|block| block.call; @count += 1; throw :halt}
1275
- @machine.after_transition {@count += 1}
1276
-
1277
- @transition.run_callbacks(:after => false)
1278
1246
 
1279
- 2.times do
1247
+ def test_should_not_run_further_callbacks_if_halted_during_continue_around_transition
1248
+ @callbacks = []
1249
+ @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1}
1250
+ @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2; throw :halt}
1251
+ @machine.after_transition {@callbacks << :after}
1252
+
1253
+ assert_equal true, @transition.run_callbacks(:after => false)
1254
+ assert_equal [:before_around_1, :before_around_2], @callbacks
1255
+
1280
1256
  assert_equal true, @transition.run_callbacks
1281
- assert_equal 1, @count
1257
+ assert_equal [:before_around_1, :before_around_2, :after_around_2], @callbacks
1282
1258
  end
1283
- end
1284
-
1285
- def test_should_have_access_to_result_after_continued
1286
- @machine.around_transition {|block| @around_before_result = @transition.result; block.call; @around_after_result = @transition.result}
1287
- @machine.after_transition {@after_result = @transition.result}
1288
1259
 
1289
- @transition.run_callbacks(:after => false)
1290
- @transition.run_callbacks {{:result => 1}}
1260
+ def test_should_not_be_able_to_continue_twice
1261
+ @count = 0
1262
+ @machine.around_transition {|block| block.call; @count += 1}
1263
+ @machine.after_transition {@count += 1}
1264
+
1265
+ @transition.run_callbacks(:after => false)
1266
+
1267
+ 2.times do
1268
+ assert_equal true, @transition.run_callbacks
1269
+ assert_equal 2, @count
1270
+ end
1271
+ end
1291
1272
 
1292
- assert_nil @around_before_result
1293
- assert_equal 1, @around_after_result
1294
- assert_equal 1, @after_result
1295
- end
1296
-
1297
- def test_should_raise_exceptions_during_around_callbacks_after_yield_in_second_execution
1298
- @machine.around_transition {|block| block.call; raise ArgumentError}
1273
+ def test_should_not_be_able_to_continue_again_after_halted
1274
+ @count = 0
1275
+ @machine.around_transition {|block| block.call; @count += 1; throw :halt}
1276
+ @machine.after_transition {@count += 1}
1277
+
1278
+ @transition.run_callbacks(:after => false)
1279
+
1280
+ 2.times do
1281
+ assert_equal true, @transition.run_callbacks
1282
+ assert_equal 1, @count
1283
+ end
1284
+ end
1299
1285
 
1300
- assert_nothing_raised { @transition.run_callbacks(:after => false) }
1301
- assert_raise(ArgumentError) { @transition.run_callbacks }
1286
+ def test_should_have_access_to_result_after_continued
1287
+ @machine.around_transition {|block| @around_before_result = @transition.result; block.call; @around_after_result = @transition.result}
1288
+ @machine.after_transition {@after_result = @transition.result}
1289
+
1290
+ @transition.run_callbacks(:after => false)
1291
+ @transition.run_callbacks {{:result => 1}}
1292
+
1293
+ assert_nil @around_before_result
1294
+ assert_equal 1, @around_after_result
1295
+ assert_equal 1, @after_result
1296
+ end
1297
+
1298
+ def test_should_raise_exceptions_during_around_callbacks_after_yield_in_second_execution
1299
+ @machine.around_transition {|block| block.call; raise ArgumentError}
1300
+
1301
+ assert_nothing_raised { @transition.run_callbacks(:after => false) }
1302
+ assert_raise(ArgumentError) { @transition.run_callbacks }
1303
+ end
1304
+ else
1305
+ def test_should_raise_exception_on_second_call
1306
+ @callbacks = []
1307
+ @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1}
1308
+ @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2}
1309
+ @machine.after_transition {@callbacks << :after}
1310
+
1311
+ assert_raise(ArgumentError) { @transition.run_callbacks(:after => false) }
1312
+ end
1302
1313
  end
1303
1314
  end
1304
1315