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,40 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class AssertionsBaseTest < Test::Unit::TestCase
|
4
|
-
include StateMachine::Assertions
|
5
|
-
|
6
|
-
def default_test
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class AssertValidKeysTest < AssertionsBaseTest
|
11
|
-
def test_should_not_raise_exception_if_key_is_valid
|
12
|
-
assert_nothing_raised { assert_valid_keys({:name => 'foo', :value => 'bar'}, :name, :value, :force) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_raise_exception_if_key_is_invalid
|
16
|
-
exception = assert_raise(ArgumentError) { assert_valid_keys({:name => 'foo', :value => 'bar', :invalid => true}, :name, :value, :force) }
|
17
|
-
assert_equal 'Invalid key(s): invalid', exception.message
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class AssertExclusiveKeysTest < AssertionsBaseTest
|
22
|
-
def test_should_not_raise_exception_if_no_keys_found
|
23
|
-
assert_nothing_raised { assert_exclusive_keys({:on => :park}, :only, :except) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_not_raise_exception_if_one_key_found
|
27
|
-
assert_nothing_raised { assert_exclusive_keys({:only => :parked}, :only, :except) }
|
28
|
-
assert_nothing_raised { assert_exclusive_keys({:except => :parked}, :only, :except) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_raise_exception_if_two_keys_found
|
32
|
-
exception = assert_raise(ArgumentError) { assert_exclusive_keys({:only => :parked, :except => :parked}, :only, :except) }
|
33
|
-
assert_equal 'Conflicting keys: only, except', exception.message
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_raise_exception_if_multiple_keys_found
|
37
|
-
exception = assert_raise(ArgumentError) { assert_exclusive_keys({:only => :parked, :except => :parked, :on => :park}, :only, :except, :with) }
|
38
|
-
assert_equal 'Conflicting keys: only, except', exception.message
|
39
|
-
end
|
40
|
-
end
|
@@ -1,455 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class CallbackTest < Test::Unit::TestCase
|
4
|
-
def test_should_raise_exception_if_no_methods_specified
|
5
|
-
exception = assert_raise(ArgumentError) { StateMachine::Callback.new }
|
6
|
-
assert_equal 'Method(s) for callback must be specified', exception.message
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_should_not_raise_exception_if_method_specified_in_do_option
|
10
|
-
assert_nothing_raised { StateMachine::Callback.new(:do => :run) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_should_not_raise_exception_if_method_specified_as_argument
|
14
|
-
assert_nothing_raised { StateMachine::Callback.new(:run) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_not_raise_exception_if_method_specified_as_block
|
18
|
-
assert_nothing_raised { StateMachine::Callback.new(:run) {} }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_not_raise_exception_if_implicit_option_specified
|
22
|
-
assert_nothing_raised { StateMachine::Callback.new(:do => :run, :invalid => :valid) }
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_not_bind_to_objects
|
26
|
-
assert !StateMachine::Callback.bind_to_object
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_not_have_a_terminator
|
30
|
-
assert_nil StateMachine::Callback.terminator
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class CallbackByDefaultTest < Test::Unit::TestCase
|
35
|
-
def setup
|
36
|
-
@callback = StateMachine::Callback.new(:do => lambda {})
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_not_have_a_terminator
|
40
|
-
assert_nil @callback.terminator
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_have_a_guard_with_all_matcher_requirements
|
44
|
-
assert_equal StateMachine::AllMatcher.instance, @callback.guard.event_requirement
|
45
|
-
assert_equal StateMachine::AllMatcher.instance, @callback.guard.state_requirements.first[:from]
|
46
|
-
assert_equal StateMachine::AllMatcher.instance, @callback.guard.state_requirements.first[:to]
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_not_have_any_known_states
|
50
|
-
assert_equal [], @callback.known_states
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class CallbackWithMethodArgumentTest < Test::Unit::TestCase
|
55
|
-
def setup
|
56
|
-
@callback = StateMachine::Callback.new(lambda {|*args| @args = args})
|
57
|
-
|
58
|
-
@object = Object.new
|
59
|
-
@result = @callback.call(@object)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_be_successful
|
63
|
-
assert @result
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_call_with_empty_context
|
67
|
-
assert_equal [@object], @args
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class CallbackWithMultipleMethodArgumentsTest < Test::Unit::TestCase
|
72
|
-
def setup
|
73
|
-
@callback = StateMachine::Callback.new(:run_1, :run_2)
|
74
|
-
|
75
|
-
class << @object = Object.new
|
76
|
-
attr_accessor :callbacks
|
77
|
-
|
78
|
-
def run_1
|
79
|
-
(@callbacks ||= []) << :run_1
|
80
|
-
end
|
81
|
-
|
82
|
-
def run_2
|
83
|
-
(@callbacks ||= []) << :run_2
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
@result = @callback.call(@object)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_should_be_successful
|
91
|
-
assert @result
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_call_each_callback_in_order
|
95
|
-
assert_equal [:run_1, :run_2], @object.callbacks
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class CallbackWithDoMethodTest < Test::Unit::TestCase
|
100
|
-
def setup
|
101
|
-
@callback = StateMachine::Callback.new(:do => lambda {|*args| @args = args})
|
102
|
-
|
103
|
-
@object = Object.new
|
104
|
-
@result = @callback.call(@object)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_should_be_successful
|
108
|
-
assert @result
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_should_call_with_empty_context
|
112
|
-
assert_equal [@object], @args
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class CallbackWithMultipleDoMethodsTest < Test::Unit::TestCase
|
117
|
-
def setup
|
118
|
-
@callback = StateMachine::Callback.new(:do => [:run_1, :run_2])
|
119
|
-
|
120
|
-
class << @object = Object.new
|
121
|
-
attr_accessor :callbacks
|
122
|
-
|
123
|
-
def run_1
|
124
|
-
(@callbacks ||= []) << :run_1
|
125
|
-
end
|
126
|
-
|
127
|
-
def run_2
|
128
|
-
(@callbacks ||= []) << :run_2
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
@result = @callback.call(@object)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_should_be_successful
|
136
|
-
assert @result
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_should_call_each_callback_in_order
|
140
|
-
assert_equal [:run_1, :run_2], @object.callbacks
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class CallbackWithBlockTest < Test::Unit::TestCase
|
145
|
-
def setup
|
146
|
-
@callback = StateMachine::Callback.new do |*args|
|
147
|
-
@args = args
|
148
|
-
end
|
149
|
-
|
150
|
-
@object = Object.new
|
151
|
-
@result = @callback.call(@object)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_be_successful
|
155
|
-
assert @result
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_should_call_with_empty_context
|
159
|
-
assert_equal [@object], @args
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
class CallbackWithMixedMethodsTest < Test::Unit::TestCase
|
164
|
-
def setup
|
165
|
-
@callback = StateMachine::Callback.new(:run_argument, :do => :run_do) do |object|
|
166
|
-
object.callbacks << :block
|
167
|
-
end
|
168
|
-
|
169
|
-
class << @object = Object.new
|
170
|
-
attr_accessor :callbacks
|
171
|
-
|
172
|
-
def run_argument
|
173
|
-
(@callbacks ||= []) << :argument
|
174
|
-
end
|
175
|
-
|
176
|
-
def run_do
|
177
|
-
(@callbacks ||= []) << :do
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
@result = @callback.call(@object)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_should_be_successful
|
185
|
-
assert @result
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_should_call_each_callback_in_order
|
189
|
-
assert_equal [:argument, :do, :block], @object.callbacks
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
class CallbackWithExplicitRequirementsTest < Test::Unit::TestCase
|
194
|
-
def setup
|
195
|
-
@object = Object.new
|
196
|
-
@callback = StateMachine::Callback.new(:from => :parked, :to => :idling, :on => :ignite, :do => lambda {})
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_should_call_with_empty_context
|
200
|
-
assert @callback.call(@object, {})
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_should_not_call_if_from_not_included
|
204
|
-
assert !@callback.call(@object, :from => :idling)
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_should_not_call_if_to_not_included
|
208
|
-
assert !@callback.call(@object, :to => :parked)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_should_not_call_if_on_not_included
|
212
|
-
assert !@callback.call(@object, :on => :park)
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_should_call_if_all_requirements_met
|
216
|
-
assert @callback.call(@object, :from => :parked, :to => :idling, :on => :ignite)
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_should_include_in_known_states
|
220
|
-
assert_equal [:parked, :idling], @callback.known_states
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
class CallbackWithImplicitRequirementsTest < Test::Unit::TestCase
|
225
|
-
def setup
|
226
|
-
@object = Object.new
|
227
|
-
@callback = StateMachine::Callback.new(:parked => :idling, :on => :ignite, :do => lambda {})
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_should_call_with_empty_context
|
231
|
-
assert @callback.call(@object, {})
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_should_not_call_if_from_not_included
|
235
|
-
assert !@callback.call(@object, :from => :idling)
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_should_not_call_if_to_not_included
|
239
|
-
assert !@callback.call(@object, :to => :parked)
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_should_not_call_if_on_not_included
|
243
|
-
assert !@callback.call(@object, :on => :park)
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_should_call_if_all_requirements_met
|
247
|
-
assert @callback.call(@object, :from => :parked, :to => :idling, :on => :ignite)
|
248
|
-
end
|
249
|
-
|
250
|
-
def test_should_include_in_known_states
|
251
|
-
assert_equal [:parked, :idling], @callback.known_states
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
class CallbackWithIfConditionTest < Test::Unit::TestCase
|
256
|
-
def setup
|
257
|
-
@object = Object.new
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_should_call_if_true
|
261
|
-
callback = StateMachine::Callback.new(:if => lambda {true}, :do => lambda {})
|
262
|
-
assert callback.call(@object)
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_should_not_call_if_false
|
266
|
-
callback = StateMachine::Callback.new(:if => lambda {false}, :do => lambda {})
|
267
|
-
assert !callback.call(@object)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
class CallbackWithUnlessConditionTest < Test::Unit::TestCase
|
272
|
-
def setup
|
273
|
-
@object = Object.new
|
274
|
-
end
|
275
|
-
|
276
|
-
def test_should_call_if_false
|
277
|
-
callback = StateMachine::Callback.new(:unless => lambda {false}, :do => lambda {})
|
278
|
-
assert callback.call(@object)
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_should_not_call_if_true
|
282
|
-
callback = StateMachine::Callback.new(:unless => lambda {true}, :do => lambda {})
|
283
|
-
assert !callback.call(@object)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
class CallbackWithoutTerminatorTest < Test::Unit::TestCase
|
288
|
-
def setup
|
289
|
-
@object = Object.new
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_should_not_halt_if_result_is_false
|
293
|
-
callback = StateMachine::Callback.new(:do => lambda {false}, :terminator => nil)
|
294
|
-
assert_nothing_thrown { callback.call(@object) }
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
class CallbackWithTerminatorTest < Test::Unit::TestCase
|
299
|
-
def setup
|
300
|
-
@object = Object.new
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_should_not_halt_if_terminator_does_not_match
|
304
|
-
callback = StateMachine::Callback.new(:do => lambda {false}, :terminator => lambda {|result| result == true})
|
305
|
-
assert_nothing_thrown { callback.call(@object) }
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_should_halt_if_terminator_matches
|
309
|
-
callback = StateMachine::Callback.new(:do => lambda {false}, :terminator => lambda {|result| result == false})
|
310
|
-
assert_throws(:halt) { callback.call(@object) }
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_should_halt_if_terminator_matches_any_method
|
314
|
-
callback = StateMachine::Callback.new(:do => [lambda {true}, lambda {false}], :terminator => lambda {|result| result == false})
|
315
|
-
assert_throws(:halt) { callback.call(@object) }
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
class CallbackWithoutArgumentsTest < Test::Unit::TestCase
|
320
|
-
def setup
|
321
|
-
@callback = StateMachine::Callback.new(:do => lambda {|object| @arg = object})
|
322
|
-
|
323
|
-
@object = Object.new
|
324
|
-
@callback.call(@object, {}, 1, 2, 3)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_should_call_method_with_object_as_argument
|
328
|
-
assert_equal @object, @arg
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
class CallbackWithArgumentsTest < Test::Unit::TestCase
|
333
|
-
def setup
|
334
|
-
@callback = StateMachine::Callback.new(:do => lambda {|*args| @args = args})
|
335
|
-
|
336
|
-
@object = Object.new
|
337
|
-
@callback.call(@object, {}, 1, 2, 3)
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_should_call_method_with_all_arguments
|
341
|
-
assert_equal [@object, 1, 2, 3], @args
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
class CallbackWithUnboundMethodTest < Test::Unit::TestCase
|
346
|
-
def setup
|
347
|
-
@callback = StateMachine::Callback.new(:do => lambda {|*args| @context = args.unshift(self)})
|
348
|
-
|
349
|
-
@object = Object.new
|
350
|
-
@callback.call(@object, {}, 1, 2, 3)
|
351
|
-
end
|
352
|
-
|
353
|
-
def test_should_call_method_outside_the_context_of_the_object
|
354
|
-
assert_equal [self, @object, 1, 2, 3], @context
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
class CallbackWithBoundMethodTest < Test::Unit::TestCase
|
359
|
-
def setup
|
360
|
-
@object = Object.new
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_should_call_method_within_the_context_of_the_object_for_block_methods
|
364
|
-
context = nil
|
365
|
-
callback = StateMachine::Callback.new(:do => lambda {|*args| context = [self] + args}, :bind_to_object => true)
|
366
|
-
callback.call(@object, {}, 1, 2, 3)
|
367
|
-
|
368
|
-
assert_equal [@object, 1, 2, 3], context
|
369
|
-
end
|
370
|
-
|
371
|
-
def test_should_ignore_option_for_symbolic_methods
|
372
|
-
class << @object
|
373
|
-
attr_reader :context
|
374
|
-
|
375
|
-
def after_ignite(*args)
|
376
|
-
@context = args
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
callback = StateMachine::Callback.new(:do => :after_ignite, :bind_to_object => true)
|
381
|
-
callback.call(@object)
|
382
|
-
|
383
|
-
assert_equal [], @object.context
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_should_ignore_option_for_string_methods
|
387
|
-
callback = StateMachine::Callback.new(:do => '[1, 2, 3]', :bind_to_object => true)
|
388
|
-
assert callback.call(@object)
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
class CallbackWithMultipleBoundMethodsTest < Test::Unit::TestCase
|
393
|
-
def setup
|
394
|
-
@object = Object.new
|
395
|
-
|
396
|
-
first_context = nil
|
397
|
-
second_context = nil
|
398
|
-
|
399
|
-
@callback = StateMachine::Callback.new(:do => [lambda {first_context = self}, lambda {second_context = self}], :bind_to_object => true)
|
400
|
-
@callback.call(@object)
|
401
|
-
|
402
|
-
@first_context = first_context
|
403
|
-
@second_context = second_context
|
404
|
-
end
|
405
|
-
|
406
|
-
def test_should_call_each_method_within_the_context_of_the_object
|
407
|
-
assert_equal @object, @first_context
|
408
|
-
assert_equal @object, @second_context
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
class CallbackWithApplicationBoundObjectTest < Test::Unit::TestCase
|
413
|
-
def setup
|
414
|
-
@original_bind_to_object = StateMachine::Callback.bind_to_object
|
415
|
-
StateMachine::Callback.bind_to_object = true
|
416
|
-
|
417
|
-
context = nil
|
418
|
-
@callback = StateMachine::Callback.new(:do => lambda {|*args| context = self})
|
419
|
-
|
420
|
-
@object = Object.new
|
421
|
-
@callback.call(@object)
|
422
|
-
@context = context
|
423
|
-
end
|
424
|
-
|
425
|
-
def test_should_call_method_within_the_context_of_the_object
|
426
|
-
assert_equal @object, @context
|
427
|
-
end
|
428
|
-
|
429
|
-
def teardown
|
430
|
-
StateMachine::Callback.bind_to_object = @original_bind_to_object
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
class CallbackWithApplicationTerminatorTest < Test::Unit::TestCase
|
435
|
-
def setup
|
436
|
-
@original_terminator = StateMachine::Callback.bind_to_object
|
437
|
-
StateMachine::Callback.terminator = lambda {|result| result == false}
|
438
|
-
|
439
|
-
@object = Object.new
|
440
|
-
end
|
441
|
-
|
442
|
-
def test_should_not_halt_if_terminator_does_not_match
|
443
|
-
callback = StateMachine::Callback.new(:do => lambda {true})
|
444
|
-
assert_nothing_thrown { callback.call(@object) }
|
445
|
-
end
|
446
|
-
|
447
|
-
def test_should_halt_if_terminator_matches
|
448
|
-
callback = StateMachine::Callback.new(:do => lambda {false})
|
449
|
-
assert_throws(:halt) { callback.call(@object) }
|
450
|
-
end
|
451
|
-
|
452
|
-
def teardown
|
453
|
-
StateMachine::Callback.bind_to_object = @original_bind_to_object
|
454
|
-
end
|
455
|
-
end
|