branston 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/branston/Gemfile +25 -0
- data/lib/branston/Gemfile.lock +76 -0
- data/lib/branston/app/controllers/application_controller.rb +1 -1
- data/lib/branston/app/controllers/outcomes_controller.rb +2 -0
- data/lib/branston/app/controllers/stories_controller.rb +82 -86
- data/lib/branston/app/controllers/users_controller.rb +69 -11
- data/lib/branston/app/helpers/iterations_helper.rb +13 -13
- data/lib/branston/app/models/iteration.rb +3 -1
- data/lib/branston/app/models/release.rb +0 -1
- data/lib/branston/app/models/story.rb +30 -28
- data/lib/branston/app/models/user.rb +46 -1
- data/lib/branston/app/views/layouts/_header.html.erb +8 -3
- data/lib/branston/app/views/layouts/user_roles.html.erb +5 -5
- data/lib/branston/app/views/sessions/new.html.erb +8 -14
- data/lib/branston/app/views/users/_admin_controls.html.erb +14 -0
- data/lib/branston/app/views/users/_form.html.erb +27 -0
- data/lib/branston/app/views/users/edit.html.erb +9 -0
- data/lib/branston/app/views/users/index.html.erb +14 -0
- data/lib/branston/app/views/users/new.html.erb +3 -22
- data/lib/branston/config/boot.rb +20 -0
- data/lib/branston/config/environment.rb +2 -7
- data/lib/branston/config/environments/test.rb +0 -8
- data/lib/branston/config/preinitializer.rb +21 -0
- data/lib/branston/config/routes.rb +15 -10
- data/lib/branston/db/development.sqlite3 +0 -0
- data/lib/branston/db/development_structure.sql +21 -8
- data/lib/branston/db/migrate/20100723161424_add_state_to_user.rb +12 -0
- data/lib/branston/db/migrate/20100726150322_add_activation_fields_to_user.rb +12 -0
- data/lib/branston/db/migrate/20100729125551_set_default_user_state_to_pending.rb +10 -0
- data/lib/branston/db/migrate/20100812133837_add_is_admin_property_to_user.rb +10 -0
- data/lib/branston/db/migrate/20100812140532_set_default_user_state_to_active.rb +10 -0
- data/lib/branston/db/migrate/20100812143455_add_default_admin_user.rb +17 -0
- data/lib/branston/db/migrate/20110408162438_remove_is_admin_property_and_add_role_instead.rb +12 -0
- data/lib/branston/db/pristine.sqlite3 +0 -0
- data/lib/branston/db/schema.rb +6 -8
- data/lib/branston/db/test.sqlite3 +0 -0
- data/lib/branston/log/development.log +1181 -433
- data/lib/branston/log/test.log +145306 -52026
- data/lib/branston/test/blueprints.rb +22 -28
- data/lib/branston/test/functional/iterations_controller_test.rb +149 -113
- data/lib/branston/test/functional/outcomes_controller_test.rb +94 -60
- data/lib/branston/test/functional/preconditions_controller_test.rb +101 -67
- data/lib/branston/test/functional/releases_controller_test.rb +85 -49
- data/lib/branston/test/functional/scenarios_controller_test.rb +104 -70
- data/lib/branston/test/functional/stories_controller_test.rb +41 -12
- data/lib/branston/test/functional/users_controller_test.rb +364 -43
- data/lib/branston/test/unit/iteration_test.rb +37 -6
- data/lib/branston/test/unit/outcome_test.rb +2 -2
- data/lib/branston/test/unit/participation_test.rb +2 -2
- data/lib/branston/test/unit/precondition_test.rb +3 -3
- data/lib/branston/test/unit/release_test.rb +4 -0
- data/lib/branston/test/unit/scenario_test.rb +4 -4
- data/lib/branston/test/unit/story_test.rb +62 -40
- data/lib/branston/test/unit/user_test.rb +195 -5
- metadata +136 -156
- data/lib/branston/app/controllers/user_roles_controller.rb +0 -105
- data/lib/branston/app/helpers/user_roles_helper.rb +0 -2
- data/lib/branston/app/models/user_role.rb +0 -21
- data/lib/branston/app/views/layouts/outcomes.html.erb +0 -17
- data/lib/branston/app/views/layouts/preconditions.html.erb +0 -17
- data/lib/branston/app/views/layouts/releases.html.erb +0 -17
- data/lib/branston/app/views/user_roles/edit.html.erb +0 -16
- data/lib/branston/app/views/user_roles/index.html.erb +0 -20
- data/lib/branston/app/views/user_roles/new.html.erb +0 -15
- data/lib/branston/app/views/user_roles/show.html.erb +0 -8
- data/lib/branston/coverage/app-controllers-application_controller_rb.html +0 -231
- data/lib/branston/coverage/app-controllers-iterations_controller_rb.html +0 -801
- data/lib/branston/coverage/app-controllers-outcomes_controller_rb.html +0 -759
- data/lib/branston/coverage/app-controllers-preconditions_controller_rb.html +0 -783
- data/lib/branston/coverage/app-controllers-releases_controller_rb.html +0 -705
- data/lib/branston/coverage/app-controllers-scenarios_controller_rb.html +0 -777
- data/lib/branston/coverage/app-controllers-sessions_controller_rb.html +0 -411
- data/lib/branston/coverage/app-controllers-stories_controller_rb.html +0 -1071
- data/lib/branston/coverage/app-controllers-user_roles_controller_rb.html +0 -693
- data/lib/branston/coverage/app-controllers-users_controller_rb.html +0 -315
- data/lib/branston/coverage/app-helpers-application_helper_rb.html +0 -327
- data/lib/branston/coverage/app-helpers-iterations_helper_rb.html +0 -363
- data/lib/branston/coverage/app-helpers-outcomes_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-preconditions_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-releases_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-sessions_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-stories_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-user_roles_helper_rb.html +0 -75
- data/lib/branston/coverage/app-models-iteration_rb.html +0 -321
- data/lib/branston/coverage/app-models-outcome_rb.html +0 -243
- data/lib/branston/coverage/app-models-participation_rb.html +0 -189
- data/lib/branston/coverage/app-models-precondition_rb.html +0 -243
- data/lib/branston/coverage/app-models-release_rb.html +0 -195
- data/lib/branston/coverage/app-models-scenario_rb.html +0 -231
- data/lib/branston/coverage/app-models-story_rb.html +0 -621
- data/lib/branston/coverage/app-models-user_rb.html +0 -513
- data/lib/branston/coverage/app-models-user_role_rb.html +0 -189
- data/lib/branston/coverage/index.html +0 -570
- data/lib/branston/coverage/jquery-1.3.2.min.js +0 -19
- data/lib/branston/coverage/jquery.tablesorter.min.js +0 -15
- data/lib/branston/coverage/lib-client_rb.html +0 -537
- data/lib/branston/coverage/lib-faker_extras_rb.html +0 -207
- data/lib/branston/coverage/lib-story_generator_rb.html +0 -873
- data/lib/branston/coverage/print.css +0 -12
- data/lib/branston/coverage/rcov.js +0 -42
- data/lib/branston/coverage/screen.css +0 -270
- data/lib/branston/db/migrate/20091127131037_create_user_roles.rb +0 -13
- data/lib/branston/db/migrate/20091127172950_add_story_id_to_user_role.rb +0 -10
- data/lib/branston/test/functional/user_roles_controller_test.rb +0 -71
- data/lib/branston/test/unit/helpers/user_roles_helper_test.rb +0 -4
- data/lib/branston/test/unit/user_role_test.rb +0 -9
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_flat.txt +0 -8
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_graph.html +0 -6718
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_tree.txt +0 -9942
- data/lib/branston/vendor/plugins/state_machine/CHANGELOG.rdoc +0 -298
- data/lib/branston/vendor/plugins/state_machine/LICENSE +0 -20
- data/lib/branston/vendor/plugins/state_machine/README.rdoc +0 -466
- data/lib/branston/vendor/plugins/state_machine/Rakefile +0 -98
- data/lib/branston/vendor/plugins/state_machine/examples/AutoShop_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/Car_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/TrafficLight_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/Vehicle_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/auto_shop.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/examples/car.rb +0 -19
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/controller.rb +0 -51
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/model.rb +0 -28
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_edit.html.erb +0 -24
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_index.html.erb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_new.html.erb +0 -13
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_show.html.erb +0 -17
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/controller.rb +0 -43
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/migration.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/model.rb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_edit.html.erb +0 -25
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_index.html.erb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_new.html.erb +0 -14
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_show.html.erb +0 -17
- data/lib/branston/vendor/plugins/state_machine/examples/traffic_light.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/examples/vehicle.rb +0 -31
- data/lib/branston/vendor/plugins/state_machine/init.rb +0 -1
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine.rb +0 -388
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/assertions.rb +0 -36
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/callback.rb +0 -189
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/condition_proxy.rb +0 -94
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/eval_helpers.rb +0 -67
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event.rb +0 -252
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event_collection.rb +0 -122
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/extensions.rb +0 -149
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/guard.rb +0 -230
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations.rb +0 -68
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record.rb +0 -492
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/locale.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/observer.rb +0 -41
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper.rb +0 -351
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper/observer.rb +0 -139
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/sequel.rb +0 -322
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine.rb +0 -1467
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine_collection.rb +0 -155
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher.rb +0 -123
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher_helpers.rb +0 -54
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/node_collection.rb +0 -152
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state.rb +0 -249
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state_collection.rb +0 -112
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/transition.rb +0 -394
- data/lib/branston/vendor/plugins/state_machine/state_machine.gemspec +0 -30
- data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rake +0 -1
- data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rb +0 -30
- data/lib/branston/vendor/plugins/state_machine/test/classes/switch.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/test/functional/state_machine_test.rb +0 -941
- data/lib/branston/vendor/plugins/state_machine/test/test_helper.rb +0 -4
- data/lib/branston/vendor/plugins/state_machine/test/unit/assertions_test.rb +0 -40
- data/lib/branston/vendor/plugins/state_machine/test/unit/callback_test.rb +0 -455
- data/lib/branston/vendor/plugins/state_machine/test/unit/condition_proxy_test.rb +0 -328
- data/lib/branston/vendor/plugins/state_machine/test/unit/eval_helpers_test.rb +0 -120
- data/lib/branston/vendor/plugins/state_machine/test/unit/event_collection_test.rb +0 -326
- data/lib/branston/vendor/plugins/state_machine/test/unit/event_test.rb +0 -743
- data/lib/branston/vendor/plugins/state_machine/test/unit/guard_test.rb +0 -908
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/active_record_test.rb +0 -1367
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/data_mapper_test.rb +0 -962
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/sequel_test.rb +0 -859
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations_test.rb +0 -42
- data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_event_test.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_transition_test.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb +0 -938
- data/lib/branston/vendor/plugins/state_machine/test/unit/machine_test.rb +0 -2004
- data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_helpers_test.rb +0 -37
- data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_test.rb +0 -155
- data/lib/branston/vendor/plugins/state_machine/test/unit/node_collection_test.rb +0 -207
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_collection_test.rb +0 -280
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_machine_test.rb +0 -31
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_test.rb +0 -795
- data/lib/branston/vendor/plugins/state_machine/test/unit/transition_test.rb +0 -1212
@@ -1,328 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class Validateable
|
4
|
-
class << self
|
5
|
-
def validate(*args, &block)
|
6
|
-
args << block if block_given?
|
7
|
-
args
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class ConditionProxyTest < Test::Unit::TestCase
|
13
|
-
def test_should_call_class_with_same_arguments
|
14
|
-
options = {}
|
15
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {})
|
16
|
-
validation = condition_proxy.validate(:name, options)
|
17
|
-
|
18
|
-
assert_equal [:name, options], validation
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_pass_block_through_to_class
|
22
|
-
options = {}
|
23
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {})
|
24
|
-
|
25
|
-
proxy_block = lambda {}
|
26
|
-
validation = condition_proxy.validate(:name, options, &proxy_block)
|
27
|
-
|
28
|
-
assert_equal [:name, options, proxy_block], validation
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_pass_object_into_proxy_condition
|
32
|
-
condition_args = []
|
33
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {|*args| condition_args = args})
|
34
|
-
options = condition_proxy.validate[0]
|
35
|
-
|
36
|
-
object = Validateable.new
|
37
|
-
options[:if].call(object)
|
38
|
-
|
39
|
-
assert_equal [object], condition_args
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_evaluate_symbol_condition
|
43
|
-
klass = Class.new(Validateable) do
|
44
|
-
attr_accessor :callback_called
|
45
|
-
|
46
|
-
def callback
|
47
|
-
@callback_called = true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, :callback)
|
52
|
-
options = condition_proxy.validate[0]
|
53
|
-
|
54
|
-
object = klass.new
|
55
|
-
options[:if].call(object)
|
56
|
-
|
57
|
-
assert object.callback_called
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_evaluate_string_condition
|
61
|
-
klass = Class.new(Validateable) do
|
62
|
-
attr_accessor :callback_called
|
63
|
-
end
|
64
|
-
|
65
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, '@callback_called = true')
|
66
|
-
options = condition_proxy.validate[0]
|
67
|
-
|
68
|
-
object = klass.new
|
69
|
-
options[:if].call(object)
|
70
|
-
|
71
|
-
assert object.callback_called
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class ConditionProxyWithoutConditionsTest < Test::Unit::TestCase
|
76
|
-
def setup
|
77
|
-
@proxy_result = nil
|
78
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
|
79
|
-
|
80
|
-
@object = Validateable.new
|
81
|
-
@options = condition_proxy.validate[0]
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_should_have_options_configuration
|
85
|
-
assert_instance_of Hash, @options
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_should_have_if_option
|
89
|
-
assert_not_nil @options[:if]
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_should_be_false_if_proxy_condition_is_false
|
93
|
-
@proxy_result = false
|
94
|
-
assert !@options[:if].call(@object)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_should_be_true_if_proxy_condition_is_true
|
98
|
-
@proxy_result = true
|
99
|
-
assert @options[:if].call(@object)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_be_true_if_proxy_condition_is_not_true
|
103
|
-
@proxy_result = 1
|
104
|
-
assert @options[:if].call(@object)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class ConditionProxyWithIfConditionTest < Test::Unit::TestCase
|
109
|
-
def setup
|
110
|
-
@proxy_result = nil
|
111
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
|
112
|
-
|
113
|
-
@object = Validateable.new
|
114
|
-
|
115
|
-
@condition_result = nil
|
116
|
-
@options = condition_proxy.validate(:if => lambda {@condition_result})[0]
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_should_have_if_option
|
120
|
-
assert_not_nil @options[:if]
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_should_be_false_if_proxy_condition_is_false
|
124
|
-
@proxy_result = false
|
125
|
-
assert !@options[:if].call(@object)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_should_be_false_if_original_condition_is_false
|
129
|
-
@condition_result = false
|
130
|
-
assert !@options[:if].call(@object)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_should_be_true_if_proxy_and_original_condition_are_true
|
134
|
-
@proxy_result = true
|
135
|
-
@condition_result = true
|
136
|
-
assert @options[:if].call(@object)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_should_evaluate_symbol_condition
|
140
|
-
klass = Class.new(Validateable) do
|
141
|
-
attr_accessor :callback
|
142
|
-
end
|
143
|
-
|
144
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
|
145
|
-
options = condition_proxy.validate(:if => :callback)[0]
|
146
|
-
|
147
|
-
object = klass.new
|
148
|
-
object.callback = false
|
149
|
-
assert !options[:if].call(object)
|
150
|
-
|
151
|
-
object.callback = true
|
152
|
-
assert options[:if].call(object)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_should_evaluate_string_condition
|
156
|
-
klass = Class.new(Validateable) do
|
157
|
-
attr_accessor :callback
|
158
|
-
end
|
159
|
-
|
160
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
|
161
|
-
options = condition_proxy.validate(:if => '@callback')[0]
|
162
|
-
|
163
|
-
object = klass.new
|
164
|
-
object.callback = false
|
165
|
-
assert !options[:if].call(object)
|
166
|
-
|
167
|
-
object.callback = true
|
168
|
-
assert options[:if].call(object)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
class ConditionProxyWithMultipleIfConditionsTest < Test::Unit::TestCase
|
173
|
-
def setup
|
174
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
|
175
|
-
|
176
|
-
@object = Validateable.new
|
177
|
-
|
178
|
-
@first_condition_result = nil
|
179
|
-
@second_condition_result = nil
|
180
|
-
@options = condition_proxy.validate(:if => [lambda {@first_condition_result}, lambda {@second_condition_result}])[0]
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_should_be_true_if_all_conditions_are_true
|
184
|
-
@first_condition_result = true
|
185
|
-
@second_condition_result = true
|
186
|
-
assert @options[:if].call(@object)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_should_be_false_if_any_condition_is_false
|
190
|
-
@first_condition_result = true
|
191
|
-
@second_condition_result = false
|
192
|
-
assert !@options[:if].call(@object)
|
193
|
-
|
194
|
-
@first_condition_result = false
|
195
|
-
@second_condition_result = true
|
196
|
-
assert !@options[:if].call(@object)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
class ConditionProxyWithUnlessConditionTest < Test::Unit::TestCase
|
201
|
-
def setup
|
202
|
-
@proxy_result = nil
|
203
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {@proxy_result})
|
204
|
-
|
205
|
-
@object = Validateable.new
|
206
|
-
|
207
|
-
@condition_result = nil
|
208
|
-
@options = condition_proxy.validate(:unless => lambda {@condition_result})[0]
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_should_have_if_option
|
212
|
-
assert_not_nil @options[:if]
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_should_be_false_if_proxy_condition_is_false
|
216
|
-
@proxy_result = false
|
217
|
-
assert !@options[:if].call(@object)
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_should_be_false_if_original_condition_is_true
|
221
|
-
@condition_result = true
|
222
|
-
assert !@options[:if].call(@object)
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_should_be_true_if_proxy_is_true_and_original_condition_is_false
|
226
|
-
@proxy_result = true
|
227
|
-
@condition_result = false
|
228
|
-
assert @options[:if].call(@object)
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_should_evaluate_symbol_condition
|
232
|
-
klass = Class.new(Validateable) do
|
233
|
-
attr_accessor :callback
|
234
|
-
end
|
235
|
-
|
236
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
|
237
|
-
options = condition_proxy.validate(:unless => :callback)[0]
|
238
|
-
|
239
|
-
object = klass.new
|
240
|
-
object.callback = true
|
241
|
-
assert !options[:if].call(object)
|
242
|
-
|
243
|
-
object.callback = false
|
244
|
-
assert options[:if].call(object)
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_should_evaluate_string_condition
|
248
|
-
klass = Class.new(Validateable) do
|
249
|
-
attr_accessor :callback
|
250
|
-
end
|
251
|
-
|
252
|
-
condition_proxy = StateMachine::ConditionProxy.new(klass, lambda {true})
|
253
|
-
options = condition_proxy.validate(:unless => '@callback')[0]
|
254
|
-
|
255
|
-
object = klass.new
|
256
|
-
object.callback = true
|
257
|
-
assert !options[:if].call(object)
|
258
|
-
|
259
|
-
object.callback = false
|
260
|
-
assert options[:if].call(object)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
class ConditionProxyWithMultipleUnlessConditionsTest < Test::Unit::TestCase
|
265
|
-
def setup
|
266
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
|
267
|
-
|
268
|
-
@object = Validateable.new
|
269
|
-
|
270
|
-
@first_condition_result = nil
|
271
|
-
@second_condition_result = nil
|
272
|
-
@options = condition_proxy.validate(:unless => [lambda {@first_condition_result}, lambda {@second_condition_result}])[0]
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_should_be_true_if_all_conditions_are_false
|
276
|
-
@first_condition_result = false
|
277
|
-
@second_condition_result = false
|
278
|
-
assert @options[:if].call(@object)
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_should_be_false_if_any_condition_is_true
|
282
|
-
@first_condition_result = true
|
283
|
-
@second_condition_result = false
|
284
|
-
assert !@options[:if].call(@object)
|
285
|
-
|
286
|
-
@first_condition_result = false
|
287
|
-
@second_condition_result = true
|
288
|
-
assert !@options[:if].call(@object)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
class ConditionProxyWithIfAndUnlessConditionsTest < Test::Unit::TestCase
|
293
|
-
def setup
|
294
|
-
condition_proxy = StateMachine::ConditionProxy.new(Validateable, lambda {true})
|
295
|
-
|
296
|
-
@object = Validateable.new
|
297
|
-
|
298
|
-
@if_condition_result = nil
|
299
|
-
@unless_condition_result = nil
|
300
|
-
@options = condition_proxy.validate(:if => lambda {@if_condition_result}, :unless => lambda {@unless_condition_result})[0]
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_should_be_false_if_if_condition_is_false
|
304
|
-
@if_condition_result = false
|
305
|
-
@unless_condition_result = false
|
306
|
-
assert !@options[:if].call(@object)
|
307
|
-
|
308
|
-
@if_condition_result = false
|
309
|
-
@unless_condition_result = true
|
310
|
-
assert !@options[:if].call(@object)
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_should_be_false_if_unless_condition_is_true
|
314
|
-
@if_condition_result = false
|
315
|
-
@unless_condition_result = true
|
316
|
-
assert !@options[:if].call(@object)
|
317
|
-
|
318
|
-
@if_condition_result = true
|
319
|
-
@unless_condition_result = true
|
320
|
-
assert !@options[:if].call(@object)
|
321
|
-
end
|
322
|
-
|
323
|
-
def test_should_be_true_if_if_condition_is_true_and_unless_condition_is_false
|
324
|
-
@if_condition_result = true
|
325
|
-
@unless_condition_result = false
|
326
|
-
assert @options[:if].call(@object)
|
327
|
-
end
|
328
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class EvalHelpersBaseTest < Test::Unit::TestCase
|
4
|
-
include StateMachine::EvalHelpers
|
5
|
-
|
6
|
-
def default_test
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class EvalHelpersTest < EvalHelpersBaseTest
|
11
|
-
def setup
|
12
|
-
@object = Object.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_raise_exception_if_method_is_not_symbol_string_or_proc
|
16
|
-
exception = assert_raise(ArgumentError) { evaluate_method(@object, 1) }
|
17
|
-
assert_match /Methods must/, exception.message
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class EvalHelpersSymbolTest < EvalHelpersBaseTest
|
22
|
-
def setup
|
23
|
-
class << (@object = Object.new)
|
24
|
-
def callback
|
25
|
-
true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_should_call_method_on_object_with_no_arguments
|
31
|
-
assert evaluate_method(@object, :callback, 1, 2, 3)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class EvalHelpersSymbolWithArgumentsTest < EvalHelpersBaseTest
|
36
|
-
def setup
|
37
|
-
class << (@object = Object.new)
|
38
|
-
def callback(*args)
|
39
|
-
args
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_call_method_with_all_arguments
|
45
|
-
assert_equal [1, 2, 3], evaluate_method(@object, :callback, 1, 2, 3)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class EvalHelpersSymbolTaintedMethodTest < EvalHelpersBaseTest
|
50
|
-
def setup
|
51
|
-
class << (@object = Object.new)
|
52
|
-
def callback
|
53
|
-
true
|
54
|
-
end
|
55
|
-
|
56
|
-
taint
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_not_raise_security_error
|
61
|
-
assert_nothing_raised { evaluate_method(@object, :callback, 1, 2, 3) }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class EvalHelpersStringTest < EvalHelpersBaseTest
|
66
|
-
def setup
|
67
|
-
@object = Object.new
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_should_evaluate_string
|
71
|
-
assert_equal 1, evaluate_method(@object, '1')
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_should_evaluate_string_within_object_context
|
75
|
-
@object.instance_variable_set('@value', 1)
|
76
|
-
assert_equal 1, evaluate_method(@object, '@value')
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_should_ignore_additional_arguments
|
80
|
-
assert_equal 1, evaluate_method(@object, '1', 2, 3, 4)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class EvalHelpersProcTest < EvalHelpersBaseTest
|
85
|
-
def setup
|
86
|
-
@object = Object.new
|
87
|
-
@proc = lambda {|obj| obj}
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_should_call_proc_with_object_as_argument
|
91
|
-
assert_equal @object, evaluate_method(@object, @proc, 1, 2, 3)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class EvalHelpersProcWithoutArgumentsTest < EvalHelpersBaseTest
|
96
|
-
def setup
|
97
|
-
@object = Object.new
|
98
|
-
@proc = lambda {|*args| args}
|
99
|
-
class << @proc
|
100
|
-
def arity
|
101
|
-
0
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_should_call_proc_with_no_arguments
|
107
|
-
assert_equal [], evaluate_method(@object, @proc, 1, 2, 3)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class EvalHelpersProcWithArgumentsTest < EvalHelpersBaseTest
|
112
|
-
def setup
|
113
|
-
@object = Object.new
|
114
|
-
@proc = lambda {|*args| args}
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_call_method_with_all_arguments
|
118
|
-
assert_equal [@object, 1, 2, 3], evaluate_method(@object, @proc, 1, 2, 3)
|
119
|
-
end
|
120
|
-
end
|
@@ -1,326 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class EventCollectionByDefaultTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@machine = StateMachine::Machine.new(Class.new)
|
6
|
-
@events = StateMachine::EventCollection.new(@machine)
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_should_not_have_any_nodes
|
10
|
-
assert_equal 0, @events.length
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_should_have_a_machine
|
14
|
-
assert_equal @machine, @events.machine
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_not_have_any_valid_events_for_an_object
|
18
|
-
assert @events.valid_for(@object).empty?
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_not_have_any_transitions_for_an_object
|
22
|
-
assert @events.transitions_for(@object).empty?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class EventCollectionTest < Test::Unit::TestCase
|
27
|
-
def setup
|
28
|
-
machine = StateMachine::Machine.new(Class.new, :namespace => 'alarm')
|
29
|
-
@events = StateMachine::EventCollection.new(machine)
|
30
|
-
|
31
|
-
@events << @open = StateMachine::Event.new(machine, :enable)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_index_by_name
|
35
|
-
assert_equal @open, @events[:enable, :name]
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_index_by_name_by_default
|
39
|
-
assert_equal @open, @events[:enable]
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_index_by_qualified_name
|
43
|
-
assert_equal @open, @events[:enable_alarm, :qualified_name]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class EventCollectionWithEventsWithTransitionsTest < Test::Unit::TestCase
|
48
|
-
def setup
|
49
|
-
@klass = Class.new
|
50
|
-
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
51
|
-
@events = StateMachine::EventCollection.new(@machine)
|
52
|
-
|
53
|
-
@machine.state :idling, :stalled
|
54
|
-
@machine.event :ignite
|
55
|
-
|
56
|
-
@events << @ignite = StateMachine::Event.new(@machine, :ignite)
|
57
|
-
@ignite.transition :parked => :idling
|
58
|
-
@ignite.transition :stalled => :idling
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_only_include_valid_events_for_an_object
|
62
|
-
object = @klass.new
|
63
|
-
object.state = 'parked'
|
64
|
-
assert_equal [@ignite], @events.valid_for(object)
|
65
|
-
|
66
|
-
object.state = 'stalled'
|
67
|
-
assert_equal [@ignite], @events.valid_for(object)
|
68
|
-
|
69
|
-
object.state = 'idling'
|
70
|
-
assert_equal [], @events.valid_for(object)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_should_only_include_valid_transitions_for_an_object
|
74
|
-
object = @klass.new
|
75
|
-
object.state = 'parked'
|
76
|
-
assert_equal [{:object => object, :attribute => :state, :event => :ignite, :from => 'parked', :to => 'idling'}], @events.transitions_for(object).map {|transition| transition.attributes}
|
77
|
-
|
78
|
-
object.state = 'stalled'
|
79
|
-
assert_equal [{:object => object, :attribute => :state, :event => :ignite, :from => 'stalled', :to => 'idling'}], @events.transitions_for(object).map {|transition| transition.attributes}
|
80
|
-
|
81
|
-
object.state = 'idling'
|
82
|
-
assert_equal [], @events.transitions_for(object)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_filter_valid_transitions_for_an_object_if_requirements_specified
|
86
|
-
object = @klass.new
|
87
|
-
assert_equal [{:object => object, :attribute => :state, :event => :ignite, :from => 'stalled', :to => 'idling'}], @events.transitions_for(object, :from => :stalled).map {|transition| transition.attributes}
|
88
|
-
assert_equal [], @events.transitions_for(object, :from => :idling).map {|transition| transition.attributes}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class EventCollectionWithMultipleEventsTest < Test::Unit::TestCase
|
93
|
-
def setup
|
94
|
-
@klass = Class.new
|
95
|
-
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
96
|
-
@events = StateMachine::EventCollection.new(@machine)
|
97
|
-
|
98
|
-
@machine.state :first_gear
|
99
|
-
@machine.event :park, :shift_down
|
100
|
-
|
101
|
-
@events << @park = StateMachine::Event.new(@machine, :park)
|
102
|
-
@park.transition :first_gear => :parked
|
103
|
-
|
104
|
-
@events << @shift_down = StateMachine::Event.new(@machine, :shift_down)
|
105
|
-
@shift_down.transition :first_gear => :parked
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_should_only_include_all_valid_events_for_an_object
|
109
|
-
object = @klass.new
|
110
|
-
object.state = 'first_gear'
|
111
|
-
assert_equal [@park, @shift_down], @events.valid_for(object)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
class EventCollectionWithoutMachineActionTest < Test::Unit::TestCase
|
116
|
-
def setup
|
117
|
-
@klass = Class.new
|
118
|
-
@machine = StateMachine::Machine.new(@klass, :initial => :parked)
|
119
|
-
@events = StateMachine::EventCollection.new(@machine)
|
120
|
-
|
121
|
-
@machine.event :ignite
|
122
|
-
@events << StateMachine::Event.new(@machine, :ignite)
|
123
|
-
|
124
|
-
@object = @klass.new
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_should_not_have_an_attribute_transition
|
128
|
-
assert_nil @events.attribute_transition_for(@object)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class EventCollectionAttributeWithMachineActionTest < Test::Unit::TestCase
|
133
|
-
def setup
|
134
|
-
@klass = Class.new do
|
135
|
-
def save
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
@machine = StateMachine::Machine.new(@klass, :initial => :parked, :action => :save)
|
140
|
-
@events = StateMachine::EventCollection.new(@machine)
|
141
|
-
|
142
|
-
@machine.event :ignite
|
143
|
-
@machine.state :parked, :idling
|
144
|
-
@events << @ignite = StateMachine::Event.new(@machine, :ignite)
|
145
|
-
|
146
|
-
@object = @klass.new
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_not_have_transition_if_nil
|
150
|
-
@object.state_event = nil
|
151
|
-
assert_nil @events.attribute_transition_for(@object)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_not_have_transition_if_empty
|
155
|
-
@object.state_event = ''
|
156
|
-
assert_nil @events.attribute_transition_for(@object)
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_should_have_invalid_transition_if_invalid_event_specified
|
160
|
-
@object.state_event = 'invalid'
|
161
|
-
assert_equal false, @events.attribute_transition_for(@object)
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_should_have_invalid_transition_if_event_cannot_be_fired
|
165
|
-
@object.state_event = 'ignite'
|
166
|
-
assert_equal false, @events.attribute_transition_for(@object)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_should_have_valid_transition_if_event_can_be_fired
|
170
|
-
@ignite.transition :parked => :idling
|
171
|
-
@object.state_event = 'ignite'
|
172
|
-
|
173
|
-
assert_instance_of StateMachine::Transition, @events.attribute_transition_for(@object)
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_should_have_valid_transition_if_already_defined_in_transition_cache
|
177
|
-
@ignite.transition :parked => :idling
|
178
|
-
@object.state_event = nil
|
179
|
-
@object.send(:state_event_transition=, transition = @ignite.transition_for(@object))
|
180
|
-
|
181
|
-
assert_equal transition, @events.attribute_transition_for(@object)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_should_use_transition_cache_if_both_event_and_transition_are_present
|
185
|
-
@ignite.transition :parked => :idling
|
186
|
-
@object.state_event = 'ignite'
|
187
|
-
@object.send(:state_event_transition=, transition = @ignite.transition_for(@object))
|
188
|
-
|
189
|
-
assert_equal transition, @events.attribute_transition_for(@object)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
class EventCollectionAttributeWithNamespacedMachineTest < Test::Unit::TestCase
|
194
|
-
def setup
|
195
|
-
@klass = Class.new do
|
196
|
-
def save
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
@machine = StateMachine::Machine.new(@klass, :namespace => 'alarm', :initial => :active, :action => :save)
|
201
|
-
@events = StateMachine::EventCollection.new(@machine)
|
202
|
-
|
203
|
-
@machine.event :disable
|
204
|
-
@machine.state :active, :off
|
205
|
-
@events << @disable = StateMachine::Event.new(@machine, :disable)
|
206
|
-
|
207
|
-
@object = @klass.new
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_should_not_have_transition_if_nil
|
211
|
-
@object.state_event = nil
|
212
|
-
assert_nil @events.attribute_transition_for(@object)
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_should_have_invalid_transition_if_event_cannot_be_fired
|
216
|
-
@object.state_event = 'disable'
|
217
|
-
assert_equal false, @events.attribute_transition_for(@object)
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_should_have_valid_transition_if_event_can_be_fired
|
221
|
-
@disable.transition :active => :off
|
222
|
-
@object.state_event = 'disable'
|
223
|
-
|
224
|
-
assert_instance_of StateMachine::Transition, @events.attribute_transition_for(@object)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
class EventCollectionWithValidationsTest < Test::Unit::TestCase
|
229
|
-
def setup
|
230
|
-
StateMachine::Integrations.const_set('Custom', Module.new do
|
231
|
-
def invalidate(object, attribute, message, values = [])
|
232
|
-
(object.errors ||= []) << generate_message(message, values)
|
233
|
-
end
|
234
|
-
|
235
|
-
def reset(object)
|
236
|
-
object.errors = []
|
237
|
-
end
|
238
|
-
end)
|
239
|
-
|
240
|
-
@klass = Class.new do
|
241
|
-
attr_accessor :errors
|
242
|
-
|
243
|
-
def initialize
|
244
|
-
@errors = []
|
245
|
-
super
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
@machine = StateMachine::Machine.new(@klass, :initial => :parked, :action => :save, :integration => :custom)
|
250
|
-
@events = StateMachine::EventCollection.new(@machine)
|
251
|
-
|
252
|
-
@machine.event :ignite
|
253
|
-
@machine.state :parked, :idling
|
254
|
-
@events << @ignite = StateMachine::Event.new(@machine, :ignite)
|
255
|
-
|
256
|
-
@object = @klass.new
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_should_invalidate_if_invalid_event_specified
|
260
|
-
@object.state_event = 'invalid'
|
261
|
-
@events.attribute_transition_for(@object, true)
|
262
|
-
|
263
|
-
assert_equal ['is invalid'], @object.errors
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_should_invalidate_if_event_cannot_be_fired
|
267
|
-
@object.state = 'idling'
|
268
|
-
@object.state_event = 'ignite'
|
269
|
-
@events.attribute_transition_for(@object, true)
|
270
|
-
|
271
|
-
assert_equal ['cannot transition when idling'], @object.errors
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_should_invalidate_with_friendly_name_if_invalid_event_specified
|
275
|
-
# Add a valid nil state
|
276
|
-
@machine.state nil
|
277
|
-
|
278
|
-
@object.state = nil
|
279
|
-
@object.state_event = 'ignite'
|
280
|
-
@events.attribute_transition_for(@object, true)
|
281
|
-
|
282
|
-
assert_equal ['cannot transition when nil'], @object.errors
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_should_not_invalidate_event_can_be_fired
|
286
|
-
@ignite.transition :parked => :idling
|
287
|
-
@object.state_event = 'ignite'
|
288
|
-
@events.attribute_transition_for(@object, true)
|
289
|
-
|
290
|
-
assert_equal [], @object.errors
|
291
|
-
end
|
292
|
-
|
293
|
-
def teardown
|
294
|
-
StateMachine::Integrations.send(:remove_const, 'Custom')
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
class EventCollectionWithCustomMachineAttributeTest < Test::Unit::TestCase
|
299
|
-
def setup
|
300
|
-
@klass = Class.new do
|
301
|
-
def save
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
@machine = StateMachine::Machine.new(@klass, :state, :attribute => :state_id, :initial => :parked, :action => :save)
|
306
|
-
@events = StateMachine::EventCollection.new(@machine)
|
307
|
-
|
308
|
-
@machine.event :ignite
|
309
|
-
@machine.state :parked, :idling
|
310
|
-
@events << @ignite = StateMachine::Event.new(@machine, :ignite)
|
311
|
-
|
312
|
-
@object = @klass.new
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_should_not_have_transition_if_nil
|
316
|
-
@object.state_event = nil
|
317
|
-
assert_nil @events.attribute_transition_for(@object)
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_should_have_valid_transition_if_event_can_be_fired
|
321
|
-
@ignite.transition :parked => :idling
|
322
|
-
@object.state_event = 'ignite'
|
323
|
-
|
324
|
-
assert_instance_of StateMachine::Transition, @events.attribute_transition_for(@object)
|
325
|
-
end
|
326
|
-
end
|