spree-state_machine 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +12 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +502 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +1246 -0
- data/Rakefile +20 -0
- data/examples/AutoShop_state.png +0 -0
- data/examples/Car_state.png +0 -0
- data/examples/Gemfile +5 -0
- data/examples/Gemfile.lock +14 -0
- data/examples/TrafficLight_state.png +0 -0
- data/examples/Vehicle_state.png +0 -0
- data/examples/auto_shop.rb +13 -0
- data/examples/car.rb +21 -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/merb-rest/controller.rb +51 -0
- data/examples/merb-rest/model.rb +28 -0
- data/examples/merb-rest/view_edit.html.erb +24 -0
- data/examples/merb-rest/view_index.html.erb +23 -0
- data/examples/merb-rest/view_new.html.erb +13 -0
- data/examples/merb-rest/view_show.html.erb +17 -0
- data/examples/rails-rest/controller.rb +43 -0
- data/examples/rails-rest/migration.rb +7 -0
- data/examples/rails-rest/model.rb +23 -0
- data/examples/rails-rest/view__form.html.erb +34 -0
- data/examples/rails-rest/view_edit.html.erb +6 -0
- data/examples/rails-rest/view_index.html.erb +25 -0
- data/examples/rails-rest/view_new.html.erb +5 -0
- data/examples/rails-rest/view_show.html.erb +19 -0
- data/examples/traffic_light.rb +9 -0
- data/examples/vehicle.rb +33 -0
- data/lib/state_machine/assertions.rb +36 -0
- data/lib/state_machine/branch.rb +225 -0
- data/lib/state_machine/callback.rb +236 -0
- data/lib/state_machine/core.rb +7 -0
- data/lib/state_machine/core_ext/class/state_machine.rb +5 -0
- data/lib/state_machine/core_ext.rb +2 -0
- data/lib/state_machine/error.rb +13 -0
- data/lib/state_machine/eval_helpers.rb +87 -0
- data/lib/state_machine/event.rb +257 -0
- data/lib/state_machine/event_collection.rb +141 -0
- data/lib/state_machine/extensions.rb +149 -0
- data/lib/state_machine/graph.rb +92 -0
- data/lib/state_machine/helper_module.rb +17 -0
- data/lib/state_machine/initializers/rails.rb +25 -0
- data/lib/state_machine/initializers.rb +4 -0
- data/lib/state_machine/integrations/active_model/locale.rb +11 -0
- data/lib/state_machine/integrations/active_model/observer.rb +33 -0
- data/lib/state_machine/integrations/active_model/observer_update.rb +42 -0
- data/lib/state_machine/integrations/active_model/versions.rb +31 -0
- data/lib/state_machine/integrations/active_model.rb +585 -0
- data/lib/state_machine/integrations/active_record/locale.rb +20 -0
- data/lib/state_machine/integrations/active_record/versions.rb +123 -0
- data/lib/state_machine/integrations/active_record.rb +525 -0
- data/lib/state_machine/integrations/base.rb +100 -0
- data/lib/state_machine/integrations.rb +121 -0
- data/lib/state_machine/machine.rb +2287 -0
- data/lib/state_machine/machine_collection.rb +74 -0
- data/lib/state_machine/macro_methods.rb +522 -0
- data/lib/state_machine/matcher.rb +123 -0
- data/lib/state_machine/matcher_helpers.rb +54 -0
- data/lib/state_machine/node_collection.rb +222 -0
- data/lib/state_machine/path.rb +120 -0
- data/lib/state_machine/path_collection.rb +90 -0
- data/lib/state_machine/state.rb +297 -0
- data/lib/state_machine/state_collection.rb +112 -0
- data/lib/state_machine/state_context.rb +138 -0
- data/lib/state_machine/transition.rb +470 -0
- data/lib/state_machine/transition_collection.rb +245 -0
- data/lib/state_machine/version.rb +3 -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/handlers.rb +12 -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/state_machine/yard/templates.rb +3 -0
- data/lib/state_machine/yard.rb +8 -0
- data/lib/state_machine.rb +8 -0
- data/lib/yard-state_machine.rb +2 -0
- data/state_machine.gemspec +22 -0
- data/test/files/en.yml +17 -0
- data/test/files/switch.rb +15 -0
- data/test/functional/state_machine_test.rb +1066 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/assertions_test.rb +40 -0
- data/test/unit/branch_test.rb +969 -0
- data/test/unit/callback_test.rb +704 -0
- data/test/unit/error_test.rb +43 -0
- data/test/unit/eval_helpers_test.rb +270 -0
- data/test/unit/event_collection_test.rb +398 -0
- data/test/unit/event_test.rb +1196 -0
- data/test/unit/graph_test.rb +98 -0
- data/test/unit/helper_module_test.rb +17 -0
- data/test/unit/integrations/active_model_test.rb +1245 -0
- data/test/unit/integrations/active_record_test.rb +2551 -0
- data/test/unit/integrations/base_test.rb +104 -0
- data/test/unit/integrations_test.rb +71 -0
- data/test/unit/invalid_event_test.rb +20 -0
- data/test/unit/invalid_parallel_transition_test.rb +18 -0
- data/test/unit/invalid_transition_test.rb +115 -0
- data/test/unit/machine_collection_test.rb +603 -0
- data/test/unit/machine_test.rb +3395 -0
- data/test/unit/matcher_helpers_test.rb +37 -0
- data/test/unit/matcher_test.rb +155 -0
- data/test/unit/node_collection_test.rb +362 -0
- data/test/unit/path_collection_test.rb +266 -0
- data/test/unit/path_test.rb +485 -0
- data/test/unit/state_collection_test.rb +352 -0
- data/test/unit/state_context_test.rb +441 -0
- data/test/unit/state_machine_test.rb +31 -0
- data/test/unit/state_test.rb +1101 -0
- data/test/unit/transition_collection_test.rb +2168 -0
- data/test/unit/transition_test.rb +1558 -0
- metadata +264 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
begin
|
4
|
+
# Load library
|
5
|
+
require 'graphviz'
|
6
|
+
|
7
|
+
class GraphDefaultTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@graph = StateMachine::Graph.new('test')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_have_a_default_font
|
13
|
+
assert_equal 'Arial', @graph.font
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_use_current_directory_for_filepath
|
17
|
+
assert_equal './test.png', @graph.file_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_have_a_default_file_format
|
21
|
+
assert_equal 'png', @graph.file_format
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_have_a_default_orientation
|
25
|
+
assert_equal 'TB', @graph[:rankdir].source
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class GraphNodesTest < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
@graph = StateMachine::Graph.new('test')
|
32
|
+
@node = @graph.add_nodes('parked', :shape => 'ellipse')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_return_generated_node
|
36
|
+
assert_not_nil @node
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_use_specified_name
|
40
|
+
assert_equal @node, @graph.get_node('parked')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_use_specified_options
|
44
|
+
assert_equal 'ellipse', @node['shape'].to_s.gsub('"', '')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_set_default_font
|
48
|
+
assert_equal 'Arial', @node['fontname'].to_s.gsub('"', '')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class GraphEdgesTest < Test::Unit::TestCase
|
53
|
+
def setup
|
54
|
+
@graph = StateMachine::Graph.new('test')
|
55
|
+
@graph.add_nodes('parked', :shape => 'ellipse')
|
56
|
+
@graph.add_nodes('idling', :shape => 'ellipse')
|
57
|
+
@edge = @graph.add_edges('parked', 'idling', :label => 'ignite')
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_return_generated_edge
|
61
|
+
assert_not_nil @edge
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_use_specified_nodes
|
65
|
+
assert_equal 'parked', @edge.node_one(false)
|
66
|
+
assert_equal 'idling', @edge.node_two(false)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_use_specified_options
|
70
|
+
assert_equal 'ignite', @edge['label'].to_s.gsub('"', '')
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_should_set_default_font
|
74
|
+
assert_equal 'Arial', @edge['fontname'].to_s.gsub('"', '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class GraphOutputTest < Test::Unit::TestCase
|
79
|
+
def setup
|
80
|
+
@graph_name = "test_#{rand(1000000)}"
|
81
|
+
@graph = StateMachine::Graph.new(@graph_name)
|
82
|
+
@graph.add_nodes('parked', :shape => 'ellipse')
|
83
|
+
@graph.add_nodes('idling', :shape => 'ellipse')
|
84
|
+
@graph.add_edges('parked', 'idling', :label => 'ignite')
|
85
|
+
@graph.output
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_save_file
|
89
|
+
assert File.exist?("./#{@graph_name}.png")
|
90
|
+
end
|
91
|
+
|
92
|
+
def teardown
|
93
|
+
FileUtils.rm Dir["./#{@graph_name}.png"]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
rescue LoadError
|
97
|
+
$stderr.puts 'Skipping GraphViz StateMachine::Graph tests. `gem install ruby-graphviz` >= v0.9.17 and try again.'
|
98
|
+
end unless ENV['TRAVIS']
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class HelperModuleTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new
|
6
|
+
@machine = StateMachine::Machine.new(@klass)
|
7
|
+
@helper_module = StateMachine::HelperModule.new(@machine, :instance)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_not_have_a_name
|
11
|
+
assert_equal '', @helper_module.name.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_provide_human_readable_to_s
|
15
|
+
assert_equal "#{@klass} :state instance helpers", @helper_module.to_s
|
16
|
+
end
|
17
|
+
end
|