branston 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/branston/Gemfile +25 -0
  3. data/lib/branston/Gemfile.lock +76 -0
  4. data/lib/branston/app/controllers/application_controller.rb +1 -1
  5. data/lib/branston/app/controllers/outcomes_controller.rb +2 -0
  6. data/lib/branston/app/controllers/stories_controller.rb +82 -86
  7. data/lib/branston/app/controllers/users_controller.rb +69 -11
  8. data/lib/branston/app/helpers/iterations_helper.rb +13 -13
  9. data/lib/branston/app/models/iteration.rb +3 -1
  10. data/lib/branston/app/models/release.rb +0 -1
  11. data/lib/branston/app/models/story.rb +30 -28
  12. data/lib/branston/app/models/user.rb +46 -1
  13. data/lib/branston/app/views/layouts/_header.html.erb +8 -3
  14. data/lib/branston/app/views/layouts/user_roles.html.erb +5 -5
  15. data/lib/branston/app/views/sessions/new.html.erb +8 -14
  16. data/lib/branston/app/views/users/_admin_controls.html.erb +14 -0
  17. data/lib/branston/app/views/users/_form.html.erb +27 -0
  18. data/lib/branston/app/views/users/edit.html.erb +9 -0
  19. data/lib/branston/app/views/users/index.html.erb +14 -0
  20. data/lib/branston/app/views/users/new.html.erb +3 -22
  21. data/lib/branston/config/boot.rb +20 -0
  22. data/lib/branston/config/environment.rb +2 -7
  23. data/lib/branston/config/environments/test.rb +0 -8
  24. data/lib/branston/config/preinitializer.rb +21 -0
  25. data/lib/branston/config/routes.rb +15 -10
  26. data/lib/branston/db/development.sqlite3 +0 -0
  27. data/lib/branston/db/development_structure.sql +21 -8
  28. data/lib/branston/db/migrate/20100723161424_add_state_to_user.rb +12 -0
  29. data/lib/branston/db/migrate/20100726150322_add_activation_fields_to_user.rb +12 -0
  30. data/lib/branston/db/migrate/20100729125551_set_default_user_state_to_pending.rb +10 -0
  31. data/lib/branston/db/migrate/20100812133837_add_is_admin_property_to_user.rb +10 -0
  32. data/lib/branston/db/migrate/20100812140532_set_default_user_state_to_active.rb +10 -0
  33. data/lib/branston/db/migrate/20100812143455_add_default_admin_user.rb +17 -0
  34. data/lib/branston/db/migrate/20110408162438_remove_is_admin_property_and_add_role_instead.rb +12 -0
  35. data/lib/branston/db/pristine.sqlite3 +0 -0
  36. data/lib/branston/db/schema.rb +6 -8
  37. data/lib/branston/db/test.sqlite3 +0 -0
  38. data/lib/branston/log/development.log +1181 -433
  39. data/lib/branston/log/test.log +145306 -52026
  40. data/lib/branston/test/blueprints.rb +22 -28
  41. data/lib/branston/test/functional/iterations_controller_test.rb +149 -113
  42. data/lib/branston/test/functional/outcomes_controller_test.rb +94 -60
  43. data/lib/branston/test/functional/preconditions_controller_test.rb +101 -67
  44. data/lib/branston/test/functional/releases_controller_test.rb +85 -49
  45. data/lib/branston/test/functional/scenarios_controller_test.rb +104 -70
  46. data/lib/branston/test/functional/stories_controller_test.rb +41 -12
  47. data/lib/branston/test/functional/users_controller_test.rb +364 -43
  48. data/lib/branston/test/unit/iteration_test.rb +37 -6
  49. data/lib/branston/test/unit/outcome_test.rb +2 -2
  50. data/lib/branston/test/unit/participation_test.rb +2 -2
  51. data/lib/branston/test/unit/precondition_test.rb +3 -3
  52. data/lib/branston/test/unit/release_test.rb +4 -0
  53. data/lib/branston/test/unit/scenario_test.rb +4 -4
  54. data/lib/branston/test/unit/story_test.rb +62 -40
  55. data/lib/branston/test/unit/user_test.rb +195 -5
  56. metadata +136 -156
  57. data/lib/branston/app/controllers/user_roles_controller.rb +0 -105
  58. data/lib/branston/app/helpers/user_roles_helper.rb +0 -2
  59. data/lib/branston/app/models/user_role.rb +0 -21
  60. data/lib/branston/app/views/layouts/outcomes.html.erb +0 -17
  61. data/lib/branston/app/views/layouts/preconditions.html.erb +0 -17
  62. data/lib/branston/app/views/layouts/releases.html.erb +0 -17
  63. data/lib/branston/app/views/user_roles/edit.html.erb +0 -16
  64. data/lib/branston/app/views/user_roles/index.html.erb +0 -20
  65. data/lib/branston/app/views/user_roles/new.html.erb +0 -15
  66. data/lib/branston/app/views/user_roles/show.html.erb +0 -8
  67. data/lib/branston/coverage/app-controllers-application_controller_rb.html +0 -231
  68. data/lib/branston/coverage/app-controllers-iterations_controller_rb.html +0 -801
  69. data/lib/branston/coverage/app-controllers-outcomes_controller_rb.html +0 -759
  70. data/lib/branston/coverage/app-controllers-preconditions_controller_rb.html +0 -783
  71. data/lib/branston/coverage/app-controllers-releases_controller_rb.html +0 -705
  72. data/lib/branston/coverage/app-controllers-scenarios_controller_rb.html +0 -777
  73. data/lib/branston/coverage/app-controllers-sessions_controller_rb.html +0 -411
  74. data/lib/branston/coverage/app-controllers-stories_controller_rb.html +0 -1071
  75. data/lib/branston/coverage/app-controllers-user_roles_controller_rb.html +0 -693
  76. data/lib/branston/coverage/app-controllers-users_controller_rb.html +0 -315
  77. data/lib/branston/coverage/app-helpers-application_helper_rb.html +0 -327
  78. data/lib/branston/coverage/app-helpers-iterations_helper_rb.html +0 -363
  79. data/lib/branston/coverage/app-helpers-outcomes_helper_rb.html +0 -75
  80. data/lib/branston/coverage/app-helpers-preconditions_helper_rb.html +0 -75
  81. data/lib/branston/coverage/app-helpers-releases_helper_rb.html +0 -75
  82. data/lib/branston/coverage/app-helpers-sessions_helper_rb.html +0 -75
  83. data/lib/branston/coverage/app-helpers-stories_helper_rb.html +0 -75
  84. data/lib/branston/coverage/app-helpers-user_roles_helper_rb.html +0 -75
  85. data/lib/branston/coverage/app-models-iteration_rb.html +0 -321
  86. data/lib/branston/coverage/app-models-outcome_rb.html +0 -243
  87. data/lib/branston/coverage/app-models-participation_rb.html +0 -189
  88. data/lib/branston/coverage/app-models-precondition_rb.html +0 -243
  89. data/lib/branston/coverage/app-models-release_rb.html +0 -195
  90. data/lib/branston/coverage/app-models-scenario_rb.html +0 -231
  91. data/lib/branston/coverage/app-models-story_rb.html +0 -621
  92. data/lib/branston/coverage/app-models-user_rb.html +0 -513
  93. data/lib/branston/coverage/app-models-user_role_rb.html +0 -189
  94. data/lib/branston/coverage/index.html +0 -570
  95. data/lib/branston/coverage/jquery-1.3.2.min.js +0 -19
  96. data/lib/branston/coverage/jquery.tablesorter.min.js +0 -15
  97. data/lib/branston/coverage/lib-client_rb.html +0 -537
  98. data/lib/branston/coverage/lib-faker_extras_rb.html +0 -207
  99. data/lib/branston/coverage/lib-story_generator_rb.html +0 -873
  100. data/lib/branston/coverage/print.css +0 -12
  101. data/lib/branston/coverage/rcov.js +0 -42
  102. data/lib/branston/coverage/screen.css +0 -270
  103. data/lib/branston/db/migrate/20091127131037_create_user_roles.rb +0 -13
  104. data/lib/branston/db/migrate/20091127172950_add_story_id_to_user_role.rb +0 -10
  105. data/lib/branston/test/functional/user_roles_controller_test.rb +0 -71
  106. data/lib/branston/test/unit/helpers/user_roles_helper_test.rb +0 -4
  107. data/lib/branston/test/unit/user_role_test.rb +0 -9
  108. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_flat.txt +0 -8
  109. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_graph.html +0 -6718
  110. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_tree.txt +0 -9942
  111. data/lib/branston/vendor/plugins/state_machine/CHANGELOG.rdoc +0 -298
  112. data/lib/branston/vendor/plugins/state_machine/LICENSE +0 -20
  113. data/lib/branston/vendor/plugins/state_machine/README.rdoc +0 -466
  114. data/lib/branston/vendor/plugins/state_machine/Rakefile +0 -98
  115. data/lib/branston/vendor/plugins/state_machine/examples/AutoShop_state.png +0 -0
  116. data/lib/branston/vendor/plugins/state_machine/examples/Car_state.png +0 -0
  117. data/lib/branston/vendor/plugins/state_machine/examples/TrafficLight_state.png +0 -0
  118. data/lib/branston/vendor/plugins/state_machine/examples/Vehicle_state.png +0 -0
  119. data/lib/branston/vendor/plugins/state_machine/examples/auto_shop.rb +0 -11
  120. data/lib/branston/vendor/plugins/state_machine/examples/car.rb +0 -19
  121. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/controller.rb +0 -51
  122. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/model.rb +0 -28
  123. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_edit.html.erb +0 -24
  124. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_index.html.erb +0 -23
  125. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_new.html.erb +0 -13
  126. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_show.html.erb +0 -17
  127. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/controller.rb +0 -43
  128. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/migration.rb +0 -11
  129. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/model.rb +0 -23
  130. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_edit.html.erb +0 -25
  131. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_index.html.erb +0 -23
  132. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_new.html.erb +0 -14
  133. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_show.html.erb +0 -17
  134. data/lib/branston/vendor/plugins/state_machine/examples/traffic_light.rb +0 -7
  135. data/lib/branston/vendor/plugins/state_machine/examples/vehicle.rb +0 -31
  136. data/lib/branston/vendor/plugins/state_machine/init.rb +0 -1
  137. data/lib/branston/vendor/plugins/state_machine/lib/state_machine.rb +0 -388
  138. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/assertions.rb +0 -36
  139. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/callback.rb +0 -189
  140. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/condition_proxy.rb +0 -94
  141. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/eval_helpers.rb +0 -67
  142. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event.rb +0 -252
  143. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event_collection.rb +0 -122
  144. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/extensions.rb +0 -149
  145. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/guard.rb +0 -230
  146. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations.rb +0 -68
  147. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record.rb +0 -492
  148. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/locale.rb +0 -11
  149. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/observer.rb +0 -41
  150. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper.rb +0 -351
  151. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper/observer.rb +0 -139
  152. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/sequel.rb +0 -322
  153. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine.rb +0 -1467
  154. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine_collection.rb +0 -155
  155. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher.rb +0 -123
  156. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher_helpers.rb +0 -54
  157. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/node_collection.rb +0 -152
  158. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state.rb +0 -249
  159. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state_collection.rb +0 -112
  160. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/transition.rb +0 -394
  161. data/lib/branston/vendor/plugins/state_machine/state_machine.gemspec +0 -30
  162. data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rake +0 -1
  163. data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rb +0 -30
  164. data/lib/branston/vendor/plugins/state_machine/test/classes/switch.rb +0 -11
  165. data/lib/branston/vendor/plugins/state_machine/test/functional/state_machine_test.rb +0 -941
  166. data/lib/branston/vendor/plugins/state_machine/test/test_helper.rb +0 -4
  167. data/lib/branston/vendor/plugins/state_machine/test/unit/assertions_test.rb +0 -40
  168. data/lib/branston/vendor/plugins/state_machine/test/unit/callback_test.rb +0 -455
  169. data/lib/branston/vendor/plugins/state_machine/test/unit/condition_proxy_test.rb +0 -328
  170. data/lib/branston/vendor/plugins/state_machine/test/unit/eval_helpers_test.rb +0 -120
  171. data/lib/branston/vendor/plugins/state_machine/test/unit/event_collection_test.rb +0 -326
  172. data/lib/branston/vendor/plugins/state_machine/test/unit/event_test.rb +0 -743
  173. data/lib/branston/vendor/plugins/state_machine/test/unit/guard_test.rb +0 -908
  174. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/active_record_test.rb +0 -1367
  175. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/data_mapper_test.rb +0 -962
  176. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/sequel_test.rb +0 -859
  177. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations_test.rb +0 -42
  178. data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_event_test.rb +0 -7
  179. data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_transition_test.rb +0 -7
  180. data/lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb +0 -938
  181. data/lib/branston/vendor/plugins/state_machine/test/unit/machine_test.rb +0 -2004
  182. data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_helpers_test.rb +0 -37
  183. data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_test.rb +0 -155
  184. data/lib/branston/vendor/plugins/state_machine/test/unit/node_collection_test.rb +0 -207
  185. data/lib/branston/vendor/plugins/state_machine/test/unit/state_collection_test.rb +0 -280
  186. data/lib/branston/vendor/plugins/state_machine/test/unit/state_machine_test.rb +0 -31
  187. data/lib/branston/vendor/plugins/state_machine/test/unit/state_test.rb +0 -795
  188. data/lib/branston/vendor/plugins/state_machine/test/unit/transition_test.rb +0 -1212
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class MatcherHelpersAllTest < Test::Unit::TestCase
4
- include StateMachine::MatcherHelpers
5
-
6
- def setup
7
- @matcher = all
8
- end
9
-
10
- def test_should_build_an_all_matcher
11
- assert_equal StateMachine::AllMatcher.instance, @matcher
12
- end
13
- end
14
-
15
- class MatcherHelpersAnyTest < Test::Unit::TestCase
16
- include StateMachine::MatcherHelpers
17
-
18
- def setup
19
- @matcher = any
20
- end
21
-
22
- def test_should_build_an_all_matcher
23
- assert_equal StateMachine::AllMatcher.instance, @matcher
24
- end
25
- end
26
-
27
- class MatcherHelpersSameTest < Test::Unit::TestCase
28
- include StateMachine::MatcherHelpers
29
-
30
- def setup
31
- @matcher = same
32
- end
33
-
34
- def test_should_build_a_loopback_matcher
35
- assert_equal StateMachine::LoopbackMatcher.instance, @matcher
36
- end
37
- end
@@ -1,155 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class MatcherByDefaultTest < Test::Unit::TestCase
4
- def setup
5
- @matcher = StateMachine::Matcher.new
6
- end
7
-
8
- def test_should_have_no_values
9
- assert_equal [], @matcher.values
10
- end
11
-
12
- def test_should_filter_all_values
13
- assert_equal [], @matcher.filter([:parked, :idling])
14
- end
15
- end
16
-
17
- class MatcherWithValueTest < Test::Unit::TestCase
18
- def setup
19
- @matcher = StateMachine::Matcher.new(nil)
20
- end
21
-
22
- def test_should_have_values
23
- assert_equal [nil], @matcher.values
24
- end
25
-
26
- def test_should_filter_unknown_values
27
- assert_equal [nil], @matcher.filter([nil, :parked])
28
- end
29
- end
30
-
31
- class MatcherWithMultipleValuesTest < Test::Unit::TestCase
32
- def setup
33
- @matcher = StateMachine::Matcher.new([:parked, :idling])
34
- end
35
-
36
- def test_should_have_values
37
- assert_equal [:parked, :idling], @matcher.values
38
- end
39
-
40
- def test_should_filter_unknown_values
41
- assert_equal [:parked], @matcher.filter([:parked, :first_gear])
42
- end
43
- end
44
-
45
- class AllMatcherTest < Test::Unit::TestCase
46
- def setup
47
- @matcher = StateMachine::AllMatcher.instance
48
- end
49
-
50
- def test_should_have_no_values
51
- assert_equal [], @matcher.values
52
- end
53
-
54
- def test_should_always_match
55
- [nil, :parked, :idling].each {|value| assert @matcher.matches?(value)}
56
- end
57
-
58
- def test_should_not_filter_any_values
59
- assert_equal [:parked, :idling], @matcher.filter([:parked, :idling])
60
- end
61
-
62
- def test_should_generate_blacklist_matcher_after_subtraction
63
- matcher = @matcher - [:parked, :idling]
64
- assert_instance_of StateMachine::BlacklistMatcher, matcher
65
- assert_equal [:parked, :idling], matcher.values
66
- end
67
-
68
- def test_should_have_a_description
69
- assert_equal 'all', @matcher.description
70
- end
71
- end
72
-
73
- class WhitelistMatcherTest < Test::Unit::TestCase
74
- def setup
75
- @matcher = StateMachine::WhitelistMatcher.new([:parked, :idling])
76
- end
77
-
78
- def test_should_have_values
79
- assert_equal [:parked, :idling], @matcher.values
80
- end
81
-
82
- def test_should_filter_unknown_values
83
- assert_equal [:parked, :idling], @matcher.filter([:parked, :idling, :first_gear])
84
- end
85
-
86
- def test_should_match_known_values
87
- assert @matcher.matches?(:parked)
88
- end
89
-
90
- def test_should_not_match_unknown_values
91
- assert !@matcher.matches?(:first_gear)
92
- end
93
-
94
- def test_should_have_a_description
95
- assert_equal '[:parked, :idling]', @matcher.description
96
-
97
- matcher = StateMachine::WhitelistMatcher.new([:parked])
98
- assert_equal ':parked', matcher.description
99
- end
100
- end
101
-
102
- class BlacklistMatcherTest < Test::Unit::TestCase
103
- def setup
104
- @matcher = StateMachine::BlacklistMatcher.new([:parked, :idling])
105
- end
106
-
107
- def test_should_have_values
108
- assert_equal [:parked, :idling], @matcher.values
109
- end
110
-
111
- def test_should_filter_known_values
112
- assert_equal [:first_gear], @matcher.filter([:parked, :idling, :first_gear])
113
- end
114
-
115
- def test_should_match_unknown_values
116
- assert @matcher.matches?(:first_gear)
117
- end
118
-
119
- def test_should_not_match_known_values
120
- assert !@matcher.matches?(:parked)
121
- end
122
-
123
- def test_should_have_a_description
124
- assert_equal 'all - [:parked, :idling]', @matcher.description
125
-
126
- matcher = StateMachine::BlacklistMatcher.new([:parked])
127
- assert_equal 'all - :parked', matcher.description
128
- end
129
- end
130
-
131
- class LoopbackMatcherTest < Test::Unit::TestCase
132
- def setup
133
- @matcher = StateMachine::LoopbackMatcher.instance
134
- end
135
-
136
- def test_should_have_no_values
137
- assert_equal [], @matcher.values
138
- end
139
-
140
- def test_should_filter_all_values
141
- assert_equal [], @matcher.filter([:parked, :idling])
142
- end
143
-
144
- def test_should_match_if_from_context_is_same
145
- assert @matcher.matches?(:parked, :from => :parked)
146
- end
147
-
148
- def test_should_not_match_if_from_context_is_different
149
- assert !@matcher.matches?(:parked, :from => :idling)
150
- end
151
-
152
- def test_should_have_a_description
153
- assert_equal 'same', @matcher.description
154
- end
155
- end
@@ -1,207 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class NodeCollectionByDefaultTest < Test::Unit::TestCase
4
- def setup
5
- @machine = StateMachine::Machine.new(Class.new)
6
- @collection = StateMachine::NodeCollection.new(@machine)
7
- end
8
-
9
- def test_should_not_have_any_nodes
10
- assert_equal 0, @collection.length
11
- end
12
-
13
- def test_should_have_a_machine
14
- assert_equal @machine, @collection.machine
15
- end
16
-
17
- def test_should_index_by_name
18
- @collection << object = Struct.new(:name).new(:parked)
19
- assert_equal object, @collection[:parked]
20
- end
21
- end
22
-
23
- class NodeCollectionTest < Test::Unit::TestCase
24
- def setup
25
- @machine = StateMachine::Machine.new(Class.new)
26
- @collection = StateMachine::NodeCollection.new(@machine)
27
- end
28
-
29
- def test_should_raise_exception_if_invalid_option_specified
30
- exception = assert_raise(ArgumentError) { StateMachine::NodeCollection.new(@machine, :invalid => true) }
31
- assert_equal 'Invalid key(s): invalid', exception.message
32
- end
33
-
34
- def test_should_raise_exception_on_lookup_if_invalid_index_specified
35
- exception = assert_raise(ArgumentError) { @collection[:something, :invalid] }
36
- assert_equal 'Invalid index: :invalid', exception.message
37
- end
38
-
39
- def test_should_raise_exception_on_fetch_if_invalid_index_specified
40
- exception = assert_raise(ArgumentError) { @collection.fetch(:something, :invalid) }
41
- assert_equal 'Invalid index: :invalid', exception.message
42
- end
43
- end
44
-
45
- class NodeCollectionAfterBeingCopiedTest < Test::Unit::TestCase
46
- def setup
47
- machine = StateMachine::Machine.new(Class.new)
48
- @collection = StateMachine::NodeCollection.new(machine)
49
- @collection << @parked = Struct.new(:name).new(:parked)
50
-
51
- @copied_collection = @collection.dup
52
- @copied_collection << @idling = Struct.new(:name).new(:idling)
53
- end
54
-
55
- def test_should_not_modify_the_original_list
56
- assert_equal 1, @collection.length
57
- assert_equal 2, @copied_collection.length
58
- end
59
-
60
- def test_should_not_modify_the_indices
61
- assert_nil @collection[:idling]
62
- assert_equal @idling, @copied_collection[:idling]
63
- end
64
-
65
- def test_should_copy_each_node
66
- assert_not_same @parked, @copied_collection[:parked]
67
- end
68
- end
69
-
70
- class NodeCollectionWithoutIndicesTest < Test::Unit::TestCase
71
- def setup
72
- machine = StateMachine::Machine.new(Class.new)
73
- @collection = StateMachine::NodeCollection.new(machine, :index => {})
74
- end
75
-
76
- def test_should_allow_adding_node
77
- @collection << Object.new
78
- assert_equal 1, @collection.length
79
- end
80
-
81
- def test_should_not_allow_keys_retrieval
82
- exception = assert_raise(ArgumentError) { @collection.keys }
83
- assert_equal 'No indices configured', exception.message
84
- end
85
-
86
- def test_should_not_allow_lookup
87
- @collection << object = Object.new
88
- exception = assert_raise(ArgumentError) { @collection[0] }
89
- assert_equal 'No indices configured', exception.message
90
- end
91
-
92
- def test_should_not_allow_fetching
93
- @collection << object = Object.new
94
- exception = assert_raise(ArgumentError) { @collection.fetch(0) }
95
- assert_equal 'No indices configured', exception.message
96
- end
97
- end
98
-
99
- class NodeCollectionWithIndicesTest < Test::Unit::TestCase
100
- def setup
101
- machine = StateMachine::Machine.new(Class.new)
102
- @collection = StateMachine::NodeCollection.new(machine, :index => [:name, :value])
103
-
104
- @object = Struct.new(:name, :value).new(:parked, 1)
105
- @collection << @object
106
- end
107
-
108
- def test_should_use_first_index_by_default_on_key_retrieval
109
- assert_equal [:parked], @collection.keys
110
- end
111
-
112
- def test_should_allow_customizing_index_for_key_retrieval
113
- assert_equal [1], @collection.keys(:value)
114
- end
115
-
116
- def test_should_use_first_index_by_default_on_lookup
117
- assert_equal @object, @collection[:parked]
118
- assert_nil @collection[1]
119
- end
120
-
121
- def test_should_allow_customizing_index_on_lookup
122
- assert_equal @object, @collection[1, :value]
123
- assert_nil @collection[:parked, :value]
124
- end
125
-
126
- def test_should_use_first_index_by_default_on_fetch
127
- assert_equal @object, @collection.fetch(:parked)
128
- exception = assert_raise(IndexError) { @collection.fetch(1) }
129
- assert_equal '1 is an invalid name', exception.message
130
- end
131
-
132
- def test_should_allow_customizing_index_on_fetch
133
- assert_equal @object, @collection.fetch(1, :value)
134
- exception = assert_raise(IndexError) { @collection.fetch(:parked, :value) }
135
- assert_equal ':parked is an invalid value', exception.message
136
- end
137
- end
138
-
139
- class NodeCollectionWithNodesTest < Test::Unit::TestCase
140
- def setup
141
- machine = StateMachine::Machine.new(Class.new)
142
- @collection = StateMachine::NodeCollection.new(machine)
143
-
144
- @klass = Struct.new(:name, :machine)
145
- @parked = @klass.new(:parked, machine)
146
- @idling = @klass.new(:idling, machine)
147
-
148
- @collection << @parked
149
- @collection << @idling
150
- end
151
-
152
- def test_should_be_able_to_enumerate
153
- order = []
154
- @collection.each {|object| order << object}
155
-
156
- assert_equal [@parked, @idling], order
157
- end
158
-
159
- def test_should_be_able_to_access_by_index
160
- assert_equal @parked, @collection.at(0)
161
- assert_equal @idling, @collection.at(1)
162
- end
163
-
164
- def test_should_deep_copy_machine_changes
165
- new_machine = StateMachine::Machine.new(Class.new)
166
- @collection.machine = new_machine
167
-
168
- assert_equal new_machine, @collection.machine
169
- assert_equal new_machine, @parked.machine
170
- assert_equal new_machine, @idling.machine
171
- end
172
- end
173
-
174
- class NodeCollectionAfterUpdateTest < Test::Unit::TestCase
175
- def setup
176
- machine = StateMachine::Machine.new(Class.new)
177
- @collection = StateMachine::NodeCollection.new(machine, :index => [:name, :value])
178
-
179
- @klass = Struct.new(:name, :value)
180
- @parked = @klass.new(:parked, 1)
181
- @idling = @klass.new(:idling, 2)
182
-
183
- @collection << @parked << @idling
184
-
185
- @parked.name = :parking
186
- @parked.value = 0
187
- @collection.update(@parked)
188
- end
189
-
190
- def test_should_not_change_the_index
191
- assert_equal @parked, @collection.at(0)
192
- end
193
-
194
- def test_should_not_duplicate_in_the_collection
195
- assert_equal 2, @collection.length
196
- end
197
-
198
- def test_should_add_each_indexed_key
199
- assert_equal @parked, @collection[:parking]
200
- assert_equal @parked, @collection[0, :value]
201
- end
202
-
203
- def test_should_remove_each_old_indexed_key
204
- assert_nil @collection[:parked]
205
- assert_nil @collection[1, :value]
206
- end
207
- end
@@ -1,280 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class StateCollectionByDefaultTest < Test::Unit::TestCase
4
- def setup
5
- @machine = StateMachine::Machine.new(Class.new)
6
- @states = StateMachine::StateCollection.new(@machine)
7
- end
8
-
9
- def test_should_not_have_any_nodes
10
- assert_equal 0, @states.length
11
- end
12
-
13
- def test_should_have_a_machine
14
- assert_equal @machine, @states.machine
15
- end
16
-
17
- def test_should_be_empty_by_priority
18
- assert_equal [], @states.by_priority
19
- end
20
- end
21
-
22
- class StateCollectionTest < Test::Unit::TestCase
23
- def setup
24
- @klass = Class.new
25
- @machine = StateMachine::Machine.new(@klass)
26
- @states = StateMachine::StateCollection.new(@machine)
27
-
28
- @states << @nil = StateMachine::State.new(@machine, nil)
29
- @states << @parked = StateMachine::State.new(@machine, :parked)
30
- @states << @idling = StateMachine::State.new(@machine, :idling)
31
-
32
- @object = @klass.new
33
- end
34
-
35
- def test_should_index_by_name
36
- assert_equal @parked, @states[:parked, :name]
37
- end
38
-
39
- def test_should_index_by_name_by_default
40
- assert_equal @parked, @states[:parked]
41
- end
42
-
43
- def test_should_index_by_value
44
- assert_equal @parked, @states['parked', :value]
45
- end
46
-
47
- def test_should_not_match_if_value_does_not_match
48
- assert !@states.matches?(@object, :parked)
49
- assert !@states.matches?(@object, :idling)
50
- end
51
-
52
- def test_should_match_if_value_matches
53
- assert @states.matches?(@object, nil)
54
- end
55
-
56
- def test_raise_exception_if_matching_invalid_state
57
- assert_raise(IndexError) { @states.matches?(@object, :invalid) }
58
- end
59
-
60
- def test_should_find_state_for_object_if_value_is_known
61
- @object.state = 'parked'
62
- assert_equal @parked, @states.match(@object)
63
- end
64
-
65
- def test_should_find_bang_state_for_object_if_value_is_known
66
- @object.state = 'parked'
67
- assert_equal @parked, @states.match!(@object)
68
- end
69
-
70
- def test_should_not_find_state_for_object_with_unknown_value
71
- @object.state = 'invalid'
72
- assert_nil @states.match(@object)
73
- end
74
-
75
- def test_should_raise_exception_if_finding_bang_state_for_object_with_unknown_value
76
- @object.state = 'invalid'
77
- exception = assert_raise(ArgumentError) { @states.match!(@object) }
78
- assert_equal '"invalid" is not a known state value', exception.message
79
- end
80
- end
81
-
82
- class StateCollectionWithCustomStateValuesTest < Test::Unit::TestCase
83
- def setup
84
- @klass = Class.new
85
- @machine = StateMachine::Machine.new(@klass)
86
- @states = StateMachine::StateCollection.new(@machine)
87
-
88
- @states << @state = StateMachine::State.new(@machine, :parked, :value => 1)
89
-
90
- @object = @klass.new
91
- @object.state = 1
92
- end
93
-
94
- def test_should_match_if_value_matches
95
- assert @states.matches?(@object, :parked)
96
- end
97
-
98
- def test_should_not_match_if_value_does_not_match
99
- @object.state = 2
100
- assert !@states.matches?(@object, :parked)
101
- end
102
-
103
- def test_should_find_state_for_object_if_value_is_known
104
- assert_equal @state, @states.match(@object)
105
- end
106
- end
107
-
108
- class StateCollectionWithStateMatchersTest < Test::Unit::TestCase
109
- def setup
110
- @klass = Class.new
111
- @machine = StateMachine::Machine.new(@klass)
112
- @states = StateMachine::StateCollection.new(@machine)
113
-
114
- @states << @state = StateMachine::State.new(@machine, :parked, :if => lambda {|value| !value.nil?})
115
-
116
- @object = @klass.new
117
- @object.state = 1
118
- end
119
-
120
- def test_should_match_if_value_matches
121
- assert @states.matches?(@object, :parked)
122
- end
123
-
124
- def test_should_not_match_if_value_does_not_match
125
- @object.state = nil
126
- assert !@states.matches?(@object, :parked)
127
- end
128
-
129
- def test_should_find_state_for_object_if_value_is_known
130
- assert_equal @state, @states.match(@object)
131
- end
132
- end
133
-
134
- class StateCollectionWithInitialStateTest < Test::Unit::TestCase
135
- def setup
136
- @machine = StateMachine::Machine.new(Class.new)
137
- @states = StateMachine::StateCollection.new(@machine)
138
-
139
- @states << @parked = StateMachine::State.new(@machine, :parked)
140
- @states << @idling = StateMachine::State.new(@machine, :idling)
141
-
142
- @parked.initial = true
143
- end
144
-
145
- def test_should_order_state_before_transition_states
146
- @machine.event :ignite do
147
- transition :to => :idling
148
- end
149
- assert_equal [@parked, @idling], @states.by_priority
150
- end
151
-
152
- def test_should_order_state_before_states_with_behaviors
153
- @idling.context do
154
- def speed
155
- 0
156
- end
157
- end
158
- assert_equal [@parked, @idling], @states.by_priority
159
- end
160
-
161
- def test_should_order_state_before_other_states
162
- assert_equal [@parked, @idling], @states.by_priority
163
- end
164
-
165
- def test_should_order_state_before_callback_states
166
- @machine.before_transition :from => :idling, :do => lambda {}
167
- assert_equal [@parked, @idling], @states.by_priority
168
- end
169
- end
170
-
171
- class StateCollectionWithStateBehaviorsTest < Test::Unit::TestCase
172
- def setup
173
- @machine = StateMachine::Machine.new(Class.new)
174
- @states = StateMachine::StateCollection.new(@machine)
175
-
176
- @states << @parked = StateMachine::State.new(@machine, :parked)
177
- @states << @idling = StateMachine::State.new(@machine, :idling)
178
-
179
- @idling.context do
180
- def speed
181
- 0
182
- end
183
- end
184
- end
185
-
186
- def test_should_order_states_after_initial_state
187
- @parked.initial = true
188
- assert_equal [@parked, @idling], @states.by_priority
189
- end
190
-
191
- def test_should_order_states_after_transition_states
192
- @machine.event :ignite do
193
- transition :from => :parked
194
- end
195
- assert_equal [@parked, @idling], @states.by_priority
196
- end
197
-
198
- def test_should_order_states_before_other_states
199
- assert_equal [@idling, @parked], @states.by_priority
200
- end
201
-
202
- def test_should_order_state_before_callback_states
203
- @machine.before_transition :from => :parked, :do => lambda {}
204
- assert_equal [@idling, @parked], @states.by_priority
205
- end
206
- end
207
-
208
- class StateCollectionWithEventTransitionsTest < Test::Unit::TestCase
209
- def setup
210
- @machine = StateMachine::Machine.new(Class.new)
211
- @states = StateMachine::StateCollection.new(@machine)
212
-
213
- @states << @parked = StateMachine::State.new(@machine, :parked)
214
- @states << @idling = StateMachine::State.new(@machine, :idling)
215
-
216
- @machine.event :ignite do
217
- transition :to => :idling
218
- end
219
- end
220
-
221
- def test_should_order_states_after_initial_state
222
- @parked.initial = true
223
- assert_equal [@parked, @idling], @states.by_priority
224
- end
225
-
226
- def test_should_order_states_before_states_with_behaviors
227
- @parked.context do
228
- def speed
229
- 0
230
- end
231
- end
232
- assert_equal [@idling, @parked], @states.by_priority
233
- end
234
-
235
- def test_should_order_states_before_other_states
236
- assert_equal [@idling, @parked], @states.by_priority
237
- end
238
-
239
- def test_should_order_state_before_callback_states
240
- @machine.before_transition :from => :parked, :do => lambda {}
241
- assert_equal [@idling, @parked], @states.by_priority
242
- end
243
- end
244
-
245
- class StateCollectionWithTransitionCallbacksTest < Test::Unit::TestCase
246
- def setup
247
- @machine = StateMachine::Machine.new(Class.new)
248
- @states = StateMachine::StateCollection.new(@machine)
249
-
250
- @states << @parked = StateMachine::State.new(@machine, :parked)
251
- @states << @idling = StateMachine::State.new(@machine, :idling)
252
-
253
- @machine.before_transition :to => :idling, :do => lambda {}
254
- end
255
-
256
- def test_should_order_states_after_initial_state
257
- @parked.initial = true
258
- assert_equal [@parked, @idling], @states.by_priority
259
- end
260
-
261
- def test_should_order_states_after_transition_states
262
- @machine.event :ignite do
263
- transition :from => :parked
264
- end
265
- assert_equal [@parked, @idling], @states.by_priority
266
- end
267
-
268
- def test_should_order_states_after_states_with_behaviors
269
- @parked.context do
270
- def speed
271
- 0
272
- end
273
- end
274
- assert_equal [@parked, @idling], @states.by_priority
275
- end
276
-
277
- def test_should_order_states_after_other_states
278
- assert_equal [@parked, @idling], @states.by_priority
279
- end
280
- end