state_machine 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -11
- data/.travis.yml +49 -7
- data/Appraisals +255 -87
- data/CHANGELOG.md +30 -0
- data/README.md +142 -21
- data/Rakefile +1 -11
- data/examples/Gemfile +5 -0
- data/examples/Gemfile.lock +14 -0
- data/examples/auto_shop.rb +2 -0
- data/examples/car.rb +2 -0
- data/examples/doc/AutoShop.html +2856 -0
- data/examples/doc/AutoShop_state.png +0 -0
- data/examples/doc/Car.html +919 -0
- data/examples/doc/Car_state.png +0 -0
- data/examples/doc/TrafficLight.html +2230 -0
- data/examples/doc/TrafficLight_state.png +0 -0
- data/examples/doc/Vehicle.html +7921 -0
- data/examples/doc/Vehicle_state.png +0 -0
- data/examples/doc/_index.html +136 -0
- data/examples/doc/class_list.html +47 -0
- data/examples/doc/css/common.css +1 -0
- data/examples/doc/css/full_list.css +55 -0
- data/examples/doc/css/style.css +322 -0
- data/examples/doc/file_list.html +46 -0
- data/examples/doc/frames.html +13 -0
- data/examples/doc/index.html +136 -0
- data/examples/doc/js/app.js +205 -0
- data/examples/doc/js/full_list.js +173 -0
- data/examples/doc/js/jquery.js +16 -0
- data/examples/doc/method_list.html +734 -0
- data/examples/doc/top-level-namespace.html +105 -0
- data/examples/rails-rest/migration.rb +1 -5
- data/examples/rails-rest/view__form.html.erb +34 -0
- data/examples/rails-rest/view_edit.html.erb +2 -21
- data/examples/rails-rest/view_index.html.erb +6 -4
- data/examples/rails-rest/view_new.html.erb +2 -11
- data/examples/rails-rest/view_show.html.erb +5 -3
- data/examples/traffic_light.rb +2 -0
- data/examples/vehicle.rb +2 -0
- data/gemfiles/active_model-3.0.0.gemfile.lock +9 -6
- data/gemfiles/active_model-3.0.5.gemfile.lock +10 -7
- data/gemfiles/active_model-3.1.1.gemfile.lock +12 -10
- data/gemfiles/{active_model-3.2.0.gemfile → active_model-3.2.1.gemfile} +1 -1
- data/gemfiles/{graphviz-0.9.0.gemfile → active_model-3.2.12.gemfile} +1 -1
- data/gemfiles/active_model-3.2.12.gemfile.lock +36 -0
- data/gemfiles/{active_record-3.2.0.gemfile → active_model-3.2.13.rc1.gemfile} +1 -2
- data/gemfiles/active_model-3.2.13.rc1.gemfile.lock +36 -0
- data/gemfiles/active_model-4.0.0.gemfile +9 -0
- data/gemfiles/active_model-4.0.0.gemfile.lock +78 -0
- data/gemfiles/active_record-2.0.0.gemfile +2 -1
- data/gemfiles/active_record-2.0.0.gemfile.lock +15 -6
- data/gemfiles/active_record-2.0.5.gemfile +2 -1
- data/gemfiles/active_record-2.0.5.gemfile.lock +15 -6
- data/gemfiles/active_record-2.1.0.gemfile +2 -1
- data/gemfiles/active_record-2.1.0.gemfile.lock +15 -6
- data/gemfiles/active_record-2.1.2.gemfile +2 -1
- data/gemfiles/active_record-2.1.2.gemfile.lock +15 -6
- data/gemfiles/active_record-2.2.3.gemfile +2 -1
- data/gemfiles/active_record-2.2.3.gemfile.lock +15 -6
- data/gemfiles/active_record-2.3.12.gemfile +2 -1
- data/gemfiles/active_record-2.3.12.gemfile.lock +15 -6
- data/gemfiles/active_record-2.3.5.gemfile +9 -0
- data/gemfiles/active_record-2.3.5.gemfile.lock +39 -0
- data/gemfiles/active_record-3.0.0.gemfile +2 -1
- data/gemfiles/active_record-3.0.0.gemfile.lock +18 -11
- data/gemfiles/active_record-3.0.5.gemfile +2 -1
- data/gemfiles/active_record-3.0.5.gemfile.lock +19 -12
- data/gemfiles/active_record-3.1.1.gemfile +2 -1
- data/gemfiles/active_record-3.1.1.gemfile.lock +22 -16
- data/gemfiles/active_record-3.2.12.gemfile +9 -0
- data/gemfiles/active_record-3.2.12.gemfile.lock +51 -0
- data/gemfiles/active_record-3.2.13.rc1.gemfile +9 -0
- data/gemfiles/active_record-3.2.13.rc1.gemfile.lock +51 -0
- data/gemfiles/active_record-4.0.0.gemfile +11 -0
- data/gemfiles/active_record-4.0.0.gemfile.lock +83 -0
- data/gemfiles/data_mapper-0.10.2.gemfile +1 -0
- data/gemfiles/data_mapper-0.10.2.gemfile.lock +13 -9
- data/gemfiles/data_mapper-0.9.11.gemfile +1 -0
- data/gemfiles/data_mapper-0.9.11.gemfile.lock +31 -7
- data/gemfiles/data_mapper-0.9.4.gemfile.lock +25 -14
- data/gemfiles/data_mapper-0.9.7.gemfile +1 -0
- data/gemfiles/data_mapper-0.9.7.gemfile.lock +27 -15
- data/gemfiles/data_mapper-1.0.0.gemfile.lock +20 -17
- data/gemfiles/data_mapper-1.0.1.gemfile.lock +20 -17
- data/gemfiles/data_mapper-1.0.2.gemfile.lock +20 -17
- data/gemfiles/data_mapper-1.1.0.gemfile.lock +19 -16
- data/gemfiles/data_mapper-1.2.0.gemfile.lock +19 -16
- data/gemfiles/default.gemfile.lock +8 -5
- data/gemfiles/graphviz-0.9.17.gemfile +7 -0
- data/gemfiles/graphviz-0.9.17.gemfile.lock +29 -0
- data/gemfiles/graphviz-0.9.21.gemfile.lock +7 -4
- data/gemfiles/graphviz-1.0.0.gemfile.lock +7 -4
- data/gemfiles/graphviz-1.0.3.gemfile +7 -0
- data/gemfiles/graphviz-1.0.3.gemfile.lock +29 -0
- data/gemfiles/graphviz-1.0.8.gemfile +7 -0
- data/gemfiles/graphviz-1.0.8.gemfile.lock +29 -0
- data/gemfiles/mongo_mapper-0.10.0.gemfile +1 -0
- data/gemfiles/mongo_mapper-0.10.0.gemfile.lock +14 -11
- data/gemfiles/mongo_mapper-0.11.1.gemfile +7 -0
- data/gemfiles/mongo_mapper-0.11.1.gemfile.lock +44 -0
- data/gemfiles/mongo_mapper-0.11.2.gemfile +9 -0
- data/gemfiles/mongo_mapper-0.11.2.gemfile.lock +48 -0
- data/gemfiles/mongo_mapper-0.12.0.gemfile +9 -0
- data/gemfiles/mongo_mapper-0.12.0.gemfile.lock +48 -0
- data/gemfiles/mongo_mapper-0.5.5.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.5.8.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.6.0.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.6.10.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.7.0.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.7.5.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.8.0.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.8.3.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.8.4.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.8.6.gemfile.lock +7 -4
- data/gemfiles/mongo_mapper-0.9.0.gemfile.lock +7 -4
- data/gemfiles/mongoid-2.0.0.gemfile +2 -0
- data/gemfiles/mongoid-2.0.0.gemfile.lock +22 -18
- data/gemfiles/mongoid-2.1.4.gemfile +2 -0
- data/gemfiles/mongoid-2.1.4.gemfile.lock +21 -17
- data/gemfiles/mongoid-2.2.4.gemfile +2 -0
- data/gemfiles/mongoid-2.2.4.gemfile.lock +21 -17
- data/gemfiles/mongoid-2.3.3.gemfile +2 -0
- data/gemfiles/mongoid-2.3.3.gemfile.lock +21 -17
- data/gemfiles/mongoid-2.4.0.gemfile +9 -0
- data/gemfiles/mongoid-2.4.0.gemfile.lock +47 -0
- data/gemfiles/mongoid-2.4.10.gemfile +9 -0
- data/gemfiles/mongoid-2.4.10.gemfile.lock +47 -0
- data/gemfiles/mongoid-2.5.2.gemfile +9 -0
- data/gemfiles/mongoid-2.5.2.gemfile.lock +47 -0
- data/gemfiles/mongoid-2.6.0.gemfile +9 -0
- data/gemfiles/mongoid-2.6.0.gemfile.lock +47 -0
- data/gemfiles/mongoid-3.0.0.gemfile +8 -0
- data/gemfiles/mongoid-3.0.0.gemfile.lock +45 -0
- data/gemfiles/mongoid-3.0.22.gemfile +8 -0
- data/gemfiles/mongoid-3.0.22.gemfile.lock +45 -0
- data/gemfiles/mongoid-3.1.0.gemfile +8 -0
- data/gemfiles/mongoid-3.1.0.gemfile.lock +45 -0
- data/gemfiles/sequel-2.11.0.gemfile +2 -1
- data/gemfiles/sequel-2.11.0.gemfile.lock +11 -6
- data/gemfiles/sequel-2.12.0.gemfile +2 -1
- data/gemfiles/sequel-2.12.0.gemfile.lock +11 -6
- data/gemfiles/sequel-2.8.0.gemfile +2 -1
- data/gemfiles/sequel-2.8.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.0.0.gemfile +2 -1
- data/gemfiles/sequel-3.0.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.10.0.gemfile +9 -0
- data/gemfiles/sequel-3.10.0.gemfile.lock +33 -0
- data/gemfiles/sequel-3.13.0.gemfile +2 -1
- data/gemfiles/sequel-3.13.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.14.0.gemfile +2 -1
- data/gemfiles/sequel-3.14.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.23.0.gemfile +2 -1
- data/gemfiles/sequel-3.23.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.24.0.gemfile +2 -1
- data/gemfiles/sequel-3.24.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.29.0.gemfile +2 -1
- data/gemfiles/sequel-3.29.0.gemfile.lock +11 -6
- data/gemfiles/sequel-3.34.0.gemfile +9 -0
- data/gemfiles/sequel-3.34.0.gemfile.lock +33 -0
- data/gemfiles/sequel-3.35.0.gemfile +9 -0
- data/gemfiles/sequel-3.35.0.gemfile.lock +33 -0
- data/gemfiles/sequel-3.4.0.gemfile +9 -0
- data/gemfiles/sequel-3.4.0.gemfile.lock +33 -0
- data/gemfiles/sequel-3.44.0.gemfile +9 -0
- data/gemfiles/sequel-3.44.0.gemfile.lock +33 -0
- data/lib/state_machine.rb +6 -0
- data/lib/state_machine/branch.rb +9 -8
- data/lib/state_machine/callback.rb +2 -2
- data/lib/state_machine/core.rb +10 -0
- data/lib/state_machine/core_ext.rb +1 -0
- data/lib/state_machine/eval_helpers.rb +5 -3
- data/lib/state_machine/event.rb +17 -6
- data/lib/state_machine/graph.rb +92 -0
- data/lib/state_machine/integrations.rb +13 -1
- data/lib/state_machine/integrations/active_model.rb +14 -20
- data/lib/state_machine/integrations/active_model/observer.rb +3 -3
- data/lib/state_machine/integrations/active_model/observer_update.rb +42 -0
- data/lib/state_machine/integrations/active_record.rb +52 -25
- data/lib/state_machine/integrations/active_record/locale.rb +1 -1
- data/lib/state_machine/integrations/active_record/versions.rb +1 -17
- data/lib/state_machine/integrations/base.rb +15 -6
- data/lib/state_machine/integrations/data_mapper.rb +98 -35
- data/lib/state_machine/integrations/data_mapper/versions.rb +46 -8
- data/lib/state_machine/integrations/mongo_mapper.rb +39 -12
- data/lib/state_machine/integrations/mongo_mapper/locale.rb +1 -1
- data/lib/state_machine/integrations/mongo_mapper/versions.rb +3 -20
- data/lib/state_machine/integrations/mongoid.rb +52 -14
- data/lib/state_machine/integrations/mongoid/locale.rb +1 -1
- data/lib/state_machine/integrations/mongoid/versions.rb +52 -26
- data/lib/state_machine/integrations/sequel.rb +82 -33
- data/lib/state_machine/integrations/sequel/versions.rb +19 -44
- data/lib/state_machine/machine.rb +99 -59
- data/lib/state_machine/machine_collection.rb +1 -2
- data/lib/state_machine/macro_methods.rb +29 -0
- data/lib/state_machine/node_collection.rb +1 -1
- data/lib/state_machine/state.rb +18 -10
- data/lib/state_machine/state_context.rb +2 -2
- data/lib/state_machine/transition.rb +8 -1
- data/lib/state_machine/transition_collection.rb +2 -1
- data/lib/state_machine/version.rb +1 -1
- data/lib/state_machine/yard.rb +8 -0
- data/lib/state_machine/yard/handlers.rb +12 -0
- data/lib/state_machine/yard/handlers/base.rb +32 -0
- data/lib/state_machine/yard/handlers/event.rb +25 -0
- data/lib/state_machine/yard/handlers/machine.rb +344 -0
- data/lib/state_machine/yard/handlers/state.rb +25 -0
- data/lib/state_machine/yard/handlers/transition.rb +47 -0
- data/lib/state_machine/yard/templates.rb +3 -0
- data/lib/state_machine/yard/templates/default/class/html/setup.rb +30 -0
- data/lib/state_machine/yard/templates/default/class/html/state_machines.erb +12 -0
- data/lib/tasks/state_machine.rb +2 -1
- data/lib/yard-state_machine.rb +2 -0
- data/state_machine.gemspec +4 -3
- data/test/files/switch.rb +4 -0
- data/test/test_helper.rb +5 -0
- data/test/unit/branch_test.rb +117 -36
- data/test/unit/callback_test.rb +5 -2
- data/test/unit/eval_helpers_test.rb +49 -1
- data/test/unit/event_collection_test.rb +3 -1
- data/test/unit/event_test.rb +182 -12
- data/test/unit/graph_test.rb +98 -0
- data/test/unit/integrations/active_model_test.rb +82 -12
- data/test/unit/integrations/active_record_test.rb +393 -37
- data/test/unit/integrations/base_test.rb +7 -2
- data/test/unit/integrations/data_mapper_test.rb +326 -72
- data/test/unit/integrations/mongo_mapper_test.rb +338 -44
- data/test/unit/integrations/mongoid_test.rb +606 -98
- data/test/unit/integrations/sequel_test.rb +429 -102
- data/test/unit/integrations_test.rb +28 -6
- data/test/unit/machine_collection_test.rb +6 -2
- data/test/unit/machine_test.rb +134 -82
- data/test/unit/node_collection_test.rb +2 -2
- data/test/unit/path_test.rb +1 -1
- data/test/unit/state_test.rb +65 -21
- data/test/unit/transition_collection_test.rb +43 -23
- data/test/unit/transition_test.rb +8 -2
- metadata +303 -221
- data/gemfiles/active_model-3.2.0.gemfile.lock +0 -32
- data/gemfiles/active_record-3.2.0.gemfile.lock +0 -43
- data/gemfiles/graphviz-0.9.0.gemfile.lock +0 -26
@@ -109,13 +109,13 @@ class NodeCollectionWithoutIndicesTest < Test::Unit::TestCase
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_should_not_allow_lookup
|
112
|
-
@collection <<
|
112
|
+
@collection << Object.new
|
113
113
|
exception = assert_raise(ArgumentError) { @collection[0] }
|
114
114
|
assert_equal 'No indices configured', exception.message
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_should_not_allow_fetching
|
118
|
-
@collection <<
|
118
|
+
@collection << Object.new
|
119
119
|
exception = assert_raise(ArgumentError) { @collection.fetch(0) }
|
120
120
|
assert_equal 'No indices configured', exception.message
|
121
121
|
end
|
data/test/unit/path_test.rb
CHANGED
@@ -240,7 +240,7 @@ class PathWithGuardedTransitionsTest < Test::Unit::TestCase
|
|
240
240
|
def test_should_not_walk_transitions_if_guard_enabled
|
241
241
|
path = StateMachine::Path.new(@object, @machine)
|
242
242
|
path.concat([
|
243
|
-
|
243
|
+
StateMachine::Transition.new(@object, @machine, :ignite, :parked, :idling)
|
244
244
|
])
|
245
245
|
|
246
246
|
paths = []
|
data/test/unit/state_test.rb
CHANGED
@@ -115,6 +115,10 @@ class StateWithoutNameTest < Test::Unit::TestCase
|
|
115
115
|
def test_should_have_a_description
|
116
116
|
assert_equal 'nil', @state.description
|
117
117
|
end
|
118
|
+
|
119
|
+
def test_should_have_a_description_using_human_name
|
120
|
+
assert_equal 'nil', @state.description(:human_name => true)
|
121
|
+
end
|
118
122
|
end
|
119
123
|
|
120
124
|
class StateWithNameTest < Test::Unit::TestCase
|
@@ -149,6 +153,11 @@ class StateWithNameTest < Test::Unit::TestCase
|
|
149
153
|
assert_equal 'parked', @state.description
|
150
154
|
end
|
151
155
|
|
156
|
+
def test_should_allow_using_human_name_in_description
|
157
|
+
@state.human_name = 'Parked'
|
158
|
+
assert_equal 'Parked', @state.description(:human_name => true)
|
159
|
+
end
|
160
|
+
|
152
161
|
def test_should_define_predicate
|
153
162
|
assert @klass.new.respond_to?(:parked?)
|
154
163
|
end
|
@@ -177,6 +186,11 @@ class StateWithNilValueTest < Test::Unit::TestCase
|
|
177
186
|
assert_equal 'parked (nil)', @state.description
|
178
187
|
end
|
179
188
|
|
189
|
+
def test_should_have_a_description_with_human_name
|
190
|
+
@state.human_name = 'Parked'
|
191
|
+
assert_equal 'Parked (nil)', @state.description(:human_name => true)
|
192
|
+
end
|
193
|
+
|
180
194
|
def test_should_define_predicate
|
181
195
|
object = @klass.new
|
182
196
|
assert object.respond_to?(:parked?)
|
@@ -198,6 +212,11 @@ class StateWithSymbolicValueTest < Test::Unit::TestCase
|
|
198
212
|
assert_equal 'parked', @state.description
|
199
213
|
end
|
200
214
|
|
215
|
+
def test_should_allow_human_name_in_description
|
216
|
+
@state.human_name = 'Parked'
|
217
|
+
assert_equal 'Parked', @state.description(:human_name => true)
|
218
|
+
end
|
219
|
+
|
201
220
|
def test_should_match_symbolic_value
|
202
221
|
assert @state.matches?(:parked)
|
203
222
|
assert !@state.matches?('parked')
|
@@ -224,6 +243,11 @@ class StateWithIntegerValueTest < Test::Unit::TestCase
|
|
224
243
|
assert_equal 'parked (1)', @state.description
|
225
244
|
end
|
226
245
|
|
246
|
+
def test_should_allow_human_name_in_description
|
247
|
+
@state.human_name = 'Parked'
|
248
|
+
assert_equal 'Parked (1)', @state.description(:human_name => true)
|
249
|
+
end
|
250
|
+
|
227
251
|
def test_should_match_integer_value
|
228
252
|
assert @state.matches?(1)
|
229
253
|
assert !@state.matches?(2)
|
@@ -843,8 +867,9 @@ begin
|
|
843
867
|
transition :parked => :idling
|
844
868
|
end
|
845
869
|
|
846
|
-
graph =
|
847
|
-
@
|
870
|
+
graph = StateMachine::Graph.new('test')
|
871
|
+
@state.draw(graph)
|
872
|
+
@node = graph.get_node('parked')
|
848
873
|
end
|
849
874
|
|
850
875
|
def test_should_use_ellipse_shape
|
@@ -859,10 +884,6 @@ begin
|
|
859
884
|
assert_equal '1', @node['height'].to_s.gsub('"', '')
|
860
885
|
end
|
861
886
|
|
862
|
-
def test_should_use_stringified_name_as_name
|
863
|
-
assert_equal 'parked', Gem::Version.new(Constants::RGV_VERSION) <= Gem::Version.new('0.9.11') ? @node.name : @node.id
|
864
|
-
end
|
865
|
-
|
866
887
|
def test_should_use_description_as_label
|
867
888
|
assert_equal 'parked (1)', @node['label'].to_s.gsub('"', '')
|
868
889
|
end
|
@@ -876,8 +897,9 @@ begin
|
|
876
897
|
transition :parked => :idling
|
877
898
|
end
|
878
899
|
|
879
|
-
@graph =
|
880
|
-
@
|
900
|
+
@graph = StateMachine::Graph.new('test')
|
901
|
+
@state.draw(@graph)
|
902
|
+
@node = @graph.get_node('parked')
|
881
903
|
end
|
882
904
|
|
883
905
|
def test_should_use_ellipse_as_shape
|
@@ -895,12 +917,13 @@ begin
|
|
895
917
|
@machine = StateMachine::Machine.new(Class.new)
|
896
918
|
@machine.states << @state = StateMachine::State.new(@machine, nil)
|
897
919
|
|
898
|
-
graph =
|
899
|
-
@
|
920
|
+
graph = StateMachine::Graph.new('test')
|
921
|
+
@state.draw(graph)
|
922
|
+
@node = graph.get_node('nil')
|
900
923
|
end
|
901
924
|
|
902
|
-
def
|
903
|
-
|
925
|
+
def test_should_have_a_node
|
926
|
+
assert_not_nil @node
|
904
927
|
end
|
905
928
|
|
906
929
|
def test_should_use_description_as_label
|
@@ -913,12 +936,13 @@ begin
|
|
913
936
|
@machine = StateMachine::Machine.new(Class.new)
|
914
937
|
@machine.states << @state = StateMachine::State.new(@machine, :parked, :value => lambda {})
|
915
938
|
|
916
|
-
graph =
|
917
|
-
@
|
939
|
+
graph = StateMachine::Graph.new('test')
|
940
|
+
@state.draw(graph)
|
941
|
+
@node = graph.get_node('parked')
|
918
942
|
end
|
919
943
|
|
920
|
-
def
|
921
|
-
|
944
|
+
def test_should_have_a_node
|
945
|
+
assert_not_nil @node
|
922
946
|
end
|
923
947
|
|
924
948
|
def test_should_use_description_as_label
|
@@ -934,8 +958,9 @@ begin
|
|
934
958
|
transition :parked => :idling
|
935
959
|
end
|
936
960
|
|
937
|
-
graph =
|
938
|
-
@
|
961
|
+
graph = StateMachine::Graph.new('test')
|
962
|
+
@state.draw(graph)
|
963
|
+
@node = graph.get_node('parked')
|
939
964
|
end
|
940
965
|
|
941
966
|
def test_should_use_ellipse_as_shape
|
@@ -948,14 +973,33 @@ begin
|
|
948
973
|
@machine = StateMachine::Machine.new(Class.new)
|
949
974
|
@machine.states << @state = StateMachine::State.new(@machine, :parked)
|
950
975
|
|
951
|
-
graph =
|
952
|
-
@
|
976
|
+
graph = StateMachine::Graph.new('test')
|
977
|
+
@state.draw(graph)
|
978
|
+
@node = graph.get_node('parked')
|
953
979
|
end
|
954
980
|
|
955
981
|
def test_should_use_doublecircle_as_shape
|
956
982
|
assert_equal 'doublecircle', @node['shape'].to_s.gsub('"', '')
|
957
983
|
end
|
958
984
|
end
|
985
|
+
|
986
|
+
class StateDrawingWithHumanNameTest < Test::Unit::TestCase
|
987
|
+
def setup
|
988
|
+
@machine = StateMachine::Machine.new(Class.new)
|
989
|
+
@machine.states << @state = StateMachine::State.new(@machine, :parked, :human_name => 'Parked')
|
990
|
+
@machine.event :ignite do
|
991
|
+
transition :parked => :idling
|
992
|
+
end
|
993
|
+
|
994
|
+
graph = StateMachine::Graph.new('test')
|
995
|
+
@state.draw(graph, :human_name => true)
|
996
|
+
@node = graph.get_node('parked')
|
997
|
+
end
|
998
|
+
|
999
|
+
def test_should_use_description_with_human_name_as_label
|
1000
|
+
assert_equal 'Parked', @node['label'].to_s.gsub('"', '')
|
1001
|
+
end
|
1002
|
+
end
|
959
1003
|
rescue LoadError
|
960
|
-
$stderr.puts 'Skipping GraphViz StateMachine::State tests. `gem install ruby-graphviz` >= v0.9.
|
1004
|
+
$stderr.puts 'Skipping GraphViz StateMachine::State tests. `gem install ruby-graphviz` >= v0.9.17 and try again.'
|
961
1005
|
end unless ENV['TRAVIS']
|
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|
3
3
|
class TransitionCollectionTest < Test::Unit::TestCase
|
4
4
|
def test_should_raise_exception_if_invalid_option_specified
|
5
5
|
exception = assert_raise(ArgumentError) {StateMachine::TransitionCollection.new([], :invalid => true)}
|
6
|
-
|
6
|
+
assert_equal 'Invalid key(s): invalid', exception.message
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_should_raise_exception_if_multiple_transitions_for_same_attribute_specified
|
@@ -107,12 +107,14 @@ class TransitionCollectionPartialInvalidTest < Test::Unit::TestCase
|
|
107
107
|
attr_accessor :ran_transaction
|
108
108
|
end
|
109
109
|
|
110
|
+
@callbacks = []
|
111
|
+
|
110
112
|
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
111
113
|
@machine.state :idling
|
112
114
|
@machine.event :ignite
|
113
|
-
@machine.before_transition {@
|
114
|
-
@machine.after_transition {@
|
115
|
-
@machine.around_transition {|block| @
|
115
|
+
@machine.before_transition {@callbacks << :before}
|
116
|
+
@machine.after_transition {@callbacks << :after}
|
117
|
+
@machine.around_transition {|block| @callbacks << :around_before; block.call; @callbacks << :around_after}
|
116
118
|
|
117
119
|
class << @machine
|
118
120
|
def within_transaction(object)
|
@@ -147,7 +149,7 @@ class TransitionCollectionPartialInvalidTest < Test::Unit::TestCase
|
|
147
149
|
end
|
148
150
|
|
149
151
|
def test_should_not_run_before_callbacks
|
150
|
-
assert !@
|
152
|
+
assert !@callbacks.include?(:before)
|
151
153
|
end
|
152
154
|
|
153
155
|
def test_should_not_persist_states
|
@@ -155,15 +157,15 @@ class TransitionCollectionPartialInvalidTest < Test::Unit::TestCase
|
|
155
157
|
end
|
156
158
|
|
157
159
|
def test_should_not_run_after_callbacks
|
158
|
-
assert !@
|
160
|
+
assert !@callbacks.include?(:after)
|
159
161
|
end
|
160
162
|
|
161
163
|
def test_should_not_run_around_callbacks_before_yield
|
162
|
-
assert !@
|
164
|
+
assert !@callbacks.include?(:around_before)
|
163
165
|
end
|
164
166
|
|
165
167
|
def test_should_not_run_around_callbacks_after_yield
|
166
|
-
assert !@
|
168
|
+
assert !@callbacks.include?(:around_after)
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
@@ -173,6 +175,7 @@ class TransitionCollectionValidTest < Test::Unit::TestCase
|
|
173
175
|
attr_reader :persisted
|
174
176
|
|
175
177
|
def initialize
|
178
|
+
@persisted = nil
|
176
179
|
super
|
177
180
|
@persisted = []
|
178
181
|
end
|
@@ -557,6 +560,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
557
560
|
|
558
561
|
def test_should_not_halt_if_action_fails_for_first_transition
|
559
562
|
@klass.class_eval do
|
563
|
+
remove_method :save_state
|
560
564
|
def save_state
|
561
565
|
(@actions ||= []) << :save_state
|
562
566
|
false
|
@@ -570,6 +574,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
570
574
|
|
571
575
|
def test_should_halt_if_action_fails_for_second_transition
|
572
576
|
@klass.class_eval do
|
577
|
+
remove_method :save_status
|
573
578
|
def save_status
|
574
579
|
(@actions ||= []) << :save_status
|
575
580
|
false
|
@@ -582,6 +587,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
582
587
|
|
583
588
|
def test_should_rollback_if_action_errors_for_first_transition
|
584
589
|
@klass.class_eval do
|
590
|
+
remove_method :save_state
|
585
591
|
def save_state
|
586
592
|
raise ArgumentError
|
587
593
|
end
|
@@ -594,6 +600,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
594
600
|
|
595
601
|
def test_should_rollback_if_action_errors_for_second_transition
|
596
602
|
@klass.class_eval do
|
603
|
+
remove_method :save_status
|
597
604
|
def save_status
|
598
605
|
raise ArgumentError
|
599
606
|
end
|
@@ -606,6 +613,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
606
613
|
|
607
614
|
def test_should_not_run_after_callbacks_if_action_fails_for_first_transition
|
608
615
|
@klass.class_eval do
|
616
|
+
remove_method :save_state
|
609
617
|
def save_state
|
610
618
|
false
|
611
619
|
end
|
@@ -623,6 +631,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
623
631
|
|
624
632
|
def test_should_not_run_after_callbacks_if_action_fails_for_second_transition
|
625
633
|
@klass.class_eval do
|
634
|
+
remove_method :save_status
|
626
635
|
def save_status
|
627
636
|
false
|
628
637
|
end
|
@@ -640,6 +649,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
640
649
|
|
641
650
|
def test_should_run_after_failure_callbacks_if_action_fails_for_first_transition
|
642
651
|
@klass.class_eval do
|
652
|
+
remove_method :save_state
|
643
653
|
def save_state
|
644
654
|
false
|
645
655
|
end
|
@@ -655,6 +665,7 @@ class TransitionCollectionWithDifferentActionsTest < Test::Unit::TestCase
|
|
655
665
|
|
656
666
|
def test_should_run_after_failure_callbacks_if_action_fails_for_second_transition
|
657
667
|
@klass.class_eval do
|
668
|
+
remove_method :save_status
|
658
669
|
def save_status
|
659
670
|
false
|
660
671
|
end
|
@@ -979,7 +990,7 @@ class TransitionCollectionWithCallbacksTest < Test::Unit::TestCase
|
|
979
990
|
|
980
991
|
def state=(value)
|
981
992
|
@state = value
|
982
|
-
@saved_on_persist =
|
993
|
+
@saved_on_persist = saved
|
983
994
|
end
|
984
995
|
end
|
985
996
|
|
@@ -994,7 +1005,7 @@ class TransitionCollectionWithCallbacksTest < Test::Unit::TestCase
|
|
994
1005
|
|
995
1006
|
def state=(value)
|
996
1007
|
@state = value
|
997
|
-
@saved_on_persist =
|
1008
|
+
@saved_on_persist = saved
|
998
1009
|
end
|
999
1010
|
end
|
1000
1011
|
|
@@ -1112,10 +1123,12 @@ class TransitionCollectionWithSkippedAfterCallbacksTest < Test::Unit::TestCase
|
|
1112
1123
|
def setup
|
1113
1124
|
@klass = Class.new
|
1114
1125
|
|
1126
|
+
@callbacks = []
|
1127
|
+
|
1115
1128
|
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
1116
1129
|
@machine.state :idling
|
1117
1130
|
@machine.event :ignite
|
1118
|
-
@machine.after_transition {@
|
1131
|
+
@machine.after_transition {@callbacks << :after}
|
1119
1132
|
|
1120
1133
|
@object = @klass.new
|
1121
1134
|
|
@@ -1130,24 +1143,26 @@ class TransitionCollectionWithSkippedAfterCallbacksTest < Test::Unit::TestCase
|
|
1130
1143
|
end
|
1131
1144
|
|
1132
1145
|
def test_should_not_run_after_callbacks
|
1133
|
-
assert !@
|
1146
|
+
assert !@callbacks.include?(:after)
|
1134
1147
|
end
|
1135
1148
|
|
1136
1149
|
def test_should_run_after_callbacks_on_subsequent_perform
|
1137
1150
|
StateMachine::TransitionCollection.new([@transition]).perform
|
1138
|
-
assert @
|
1151
|
+
assert @callbacks.include?(:after)
|
1139
1152
|
end
|
1140
1153
|
end
|
1141
1154
|
|
1142
|
-
if
|
1155
|
+
if StateMachine::Transition.pause_supported?
|
1143
1156
|
class TransitionCollectionWithSkippedAfterCallbacksAndAroundCallbacksTest < Test::Unit::TestCase
|
1144
1157
|
def setup
|
1145
1158
|
@klass = Class.new
|
1146
1159
|
|
1160
|
+
@callbacks = []
|
1161
|
+
|
1147
1162
|
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
1148
1163
|
@machine.state :idling
|
1149
1164
|
@machine.event :ignite
|
1150
|
-
@machine.around_transition {|block| @
|
1165
|
+
@machine.around_transition {|block| @callbacks << :around_before; block.call; @callbacks << :around_after}
|
1151
1166
|
|
1152
1167
|
@object = @klass.new
|
1153
1168
|
|
@@ -1162,19 +1177,19 @@ if RUBY_PLATFORM != 'java'
|
|
1162
1177
|
end
|
1163
1178
|
|
1164
1179
|
def test_should_not_run_around_callbacks_after_yield
|
1165
|
-
assert !@
|
1180
|
+
assert !@callbacks.include?(:around_after)
|
1166
1181
|
end
|
1167
1182
|
|
1168
1183
|
def test_should_run_around_callbacks_after_yield_on_subsequent_perform
|
1169
1184
|
StateMachine::TransitionCollection.new([@transition]).perform
|
1170
|
-
assert @
|
1185
|
+
assert @callbacks.include?(:around_after)
|
1171
1186
|
end
|
1172
1187
|
|
1173
1188
|
def test_should_not_rerun_around_callbacks_before_yield_on_subsequent_perform
|
1174
|
-
@
|
1189
|
+
@callbacks = []
|
1175
1190
|
StateMachine::TransitionCollection.new([@transition]).perform
|
1176
1191
|
|
1177
|
-
assert !@
|
1192
|
+
assert !@callbacks.include?(:around_before)
|
1178
1193
|
end
|
1179
1194
|
end
|
1180
1195
|
else
|
@@ -1182,10 +1197,12 @@ else
|
|
1182
1197
|
def setup
|
1183
1198
|
@klass = Class.new
|
1184
1199
|
|
1200
|
+
@callbacks = []
|
1201
|
+
|
1185
1202
|
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
1186
1203
|
@machine.state :idling
|
1187
1204
|
@machine.event :ignite
|
1188
|
-
@machine.around_transition {|block| @
|
1205
|
+
@machine.around_transition {|block| @callbacks << :around_before; block.call; @callbacks << :around_after}
|
1189
1206
|
|
1190
1207
|
@object = @klass.new
|
1191
1208
|
|
@@ -1453,6 +1470,7 @@ class TransitionCollectionWithActionHookMultipleTest < TransitionCollectionWithA
|
|
1453
1470
|
@klass.class_eval do
|
1454
1471
|
attr_reader :status_on_save, :status_event_on_save, :status_event_transition_on_save
|
1455
1472
|
|
1473
|
+
remove_method :save
|
1456
1474
|
def save
|
1457
1475
|
@saved = true
|
1458
1476
|
@state_on_save = state
|
@@ -1522,6 +1540,7 @@ class TransitionCollectionWithActionHookErrorTest < TransitionCollectionWithActi
|
|
1522
1540
|
super
|
1523
1541
|
|
1524
1542
|
@superclass.class_eval do
|
1543
|
+
remove_method :save
|
1525
1544
|
def save
|
1526
1545
|
raise ArgumentError
|
1527
1546
|
end
|
@@ -1767,7 +1786,8 @@ class AttributeTransitionCollectionWithCallbacksTest < Test::Unit::TestCase
|
|
1767
1786
|
@state.around_transition {|object, transition, block| block.call; @around_state_event = object.state_event }
|
1768
1787
|
@transitions.perform
|
1769
1788
|
|
1770
|
-
assert_nil @
|
1789
|
+
assert_nil @after_state_event
|
1790
|
+
assert_nil @around_state_event
|
1771
1791
|
end
|
1772
1792
|
|
1773
1793
|
def test_should_not_have_event_transitions_during_before_callbacks
|
@@ -2046,7 +2066,7 @@ class AttributeTransitionCollectionWithAroundCallbackAfterYieldHaltTest < Test::
|
|
2046
2066
|
end
|
2047
2067
|
end
|
2048
2068
|
|
2049
|
-
class
|
2069
|
+
class AttributeTransitionCollectionWithAroundCallbackAfterYieldErrorTest < Test::Unit::TestCase
|
2050
2070
|
def setup
|
2051
2071
|
@klass = Class.new
|
2052
2072
|
|
@@ -2117,7 +2137,7 @@ class AttributeTransitionCollectionMarshallingTest < Test::Unit::TestCase
|
|
2117
2137
|
end
|
2118
2138
|
end
|
2119
2139
|
|
2120
|
-
if
|
2140
|
+
if StateMachine::Transition.pause_supported?
|
2121
2141
|
def test_should_marshal_during_around_callbacks_before_yield
|
2122
2142
|
@machine.around_transition {|object, transition, block| Marshal.dump(object); block.call}
|
2123
2143
|
assert_nothing_raised do
|