branston 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/lib/branston/app/controllers/scenarios_controller.rb +6 -5
  2. data/lib/branston/app/controllers/stories_controller.rb +101 -89
  3. data/lib/branston/app/models/story.rb +30 -1
  4. data/lib/branston/app/models/user.rb +4 -0
  5. data/lib/branston/app/views/iterations/index.html.erb +1 -1
  6. data/lib/branston/app/views/layouts/_header.html.erb +1 -2
  7. data/lib/branston/app/views/scenarios/_scenario.html.erb +6 -3
  8. data/lib/branston/app/views/scenarios/_scenarios.html.erb +4 -2
  9. data/lib/branston/app/views/stories/_form.html.erb +15 -4
  10. data/lib/branston/app/views/stories/_story.html.erb +26 -6
  11. data/lib/branston/app/views/stories/edit.html.erb +3 -3
  12. data/lib/branston/app/views/stories/index.html.erb +22 -3
  13. data/lib/branston/app/views/stories/new.html.erb +2 -2
  14. data/lib/branston/app/views/stories/show.html.erb +3 -3
  15. data/lib/branston/config/routes.rb +7 -4
  16. data/lib/branston/coverage/app-controllers-application_controller_rb.html +1 -1
  17. data/lib/branston/coverage/app-controllers-iterations_controller_rb.html +1 -1
  18. data/lib/branston/coverage/app-controllers-outcomes_controller_rb.html +1 -1
  19. data/lib/branston/coverage/app-controllers-preconditions_controller_rb.html +1 -1
  20. data/lib/branston/coverage/app-controllers-releases_controller_rb.html +1 -1
  21. data/lib/branston/coverage/app-controllers-scenarios_controller_rb.html +18 -12
  22. data/lib/branston/coverage/app-controllers-sessions_controller_rb.html +1 -1
  23. data/lib/branston/coverage/app-controllers-stories_controller_rb.html +193 -121
  24. data/lib/branston/coverage/app-controllers-user_roles_controller_rb.html +1 -1
  25. data/lib/branston/coverage/app-controllers-users_controller_rb.html +1 -1
  26. data/lib/branston/coverage/app-helpers-application_helper_rb.html +1 -1
  27. data/lib/branston/coverage/app-helpers-iterations_helper_rb.html +1 -1
  28. data/lib/branston/coverage/app-helpers-outcomes_helper_rb.html +1 -1
  29. data/lib/branston/coverage/app-helpers-preconditions_helper_rb.html +1 -1
  30. data/lib/branston/coverage/app-helpers-releases_helper_rb.html +1 -1
  31. data/lib/branston/coverage/app-helpers-sessions_helper_rb.html +1 -1
  32. data/lib/branston/coverage/app-helpers-stories_helper_rb.html +1 -1
  33. data/lib/branston/coverage/app-helpers-user_roles_helper_rb.html +1 -1
  34. data/lib/branston/coverage/app-models-iteration_rb.html +1 -1
  35. data/lib/branston/coverage/app-models-outcome_rb.html +1 -1
  36. data/lib/branston/coverage/app-models-participation_rb.html +1 -1
  37. data/lib/branston/coverage/app-models-precondition_rb.html +1 -1
  38. data/lib/branston/coverage/app-models-release_rb.html +1 -1
  39. data/lib/branston/coverage/app-models-scenario_rb.html +1 -1
  40. data/lib/branston/coverage/app-models-story_rb.html +192 -18
  41. data/lib/branston/coverage/app-models-user_rb.html +33 -9
  42. data/lib/branston/coverage/app-models-user_role_rb.html +1 -1
  43. data/lib/branston/coverage/index.html +13 -13
  44. data/lib/branston/coverage/lib-client_rb.html +1 -1
  45. data/lib/branston/coverage/lib-faker_extras_rb.html +1 -1
  46. data/lib/branston/coverage/lib-story_generator_rb.html +1 -1
  47. data/lib/branston/db/development.sqlite3 +0 -0
  48. data/lib/branston/db/migrate/20091223100903_add_status_to_story.rb +11 -0
  49. data/lib/branston/db/pristine.sqlite3 +0 -0
  50. data/lib/branston/db/schema.rb +5 -3
  51. data/lib/branston/db/test.sqlite3 +0 -0
  52. data/lib/branston/lib/branston.rb +4 -2
  53. data/lib/branston/log/development.log +4970 -0
  54. data/lib/branston/log/test.log +88225 -0
  55. data/lib/branston/test/blueprints.rb +10 -7
  56. data/lib/branston/test/functional/scenarios_controller_test.rb +22 -15
  57. data/lib/branston/test/functional/stories_controller_test.rb +51 -30
  58. data/lib/branston/test/unit/story_test.rb +47 -7
  59. data/lib/branston/test/unit/user_test.rb +4 -0
  60. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_flat.txt +3 -2
  61. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_graph.html +2041 -1307
  62. data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_tree.txt +7922 -7922
  63. data/lib/branston/vendor/plugins/state_machine/CHANGELOG.rdoc +298 -0
  64. data/lib/branston/vendor/plugins/state_machine/LICENSE +20 -0
  65. data/lib/branston/vendor/plugins/state_machine/README.rdoc +466 -0
  66. data/lib/branston/vendor/plugins/state_machine/Rakefile +98 -0
  67. data/lib/branston/vendor/plugins/state_machine/examples/AutoShop_state.png +0 -0
  68. data/lib/branston/vendor/plugins/state_machine/examples/Car_state.png +0 -0
  69. data/lib/branston/vendor/plugins/state_machine/examples/TrafficLight_state.png +0 -0
  70. data/lib/branston/vendor/plugins/state_machine/examples/Vehicle_state.png +0 -0
  71. data/lib/branston/vendor/plugins/state_machine/examples/auto_shop.rb +11 -0
  72. data/lib/branston/vendor/plugins/state_machine/examples/car.rb +19 -0
  73. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/controller.rb +51 -0
  74. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/model.rb +28 -0
  75. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_edit.html.erb +24 -0
  76. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_index.html.erb +23 -0
  77. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_new.html.erb +13 -0
  78. data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_show.html.erb +17 -0
  79. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/controller.rb +43 -0
  80. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/migration.rb +11 -0
  81. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/model.rb +23 -0
  82. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_edit.html.erb +25 -0
  83. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_index.html.erb +23 -0
  84. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_new.html.erb +14 -0
  85. data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_show.html.erb +17 -0
  86. data/lib/branston/vendor/plugins/state_machine/examples/traffic_light.rb +7 -0
  87. data/lib/branston/vendor/plugins/state_machine/examples/vehicle.rb +31 -0
  88. data/lib/branston/vendor/plugins/state_machine/init.rb +1 -0
  89. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/assertions.rb +36 -0
  90. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/callback.rb +189 -0
  91. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/condition_proxy.rb +94 -0
  92. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/eval_helpers.rb +67 -0
  93. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event.rb +252 -0
  94. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event_collection.rb +122 -0
  95. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/extensions.rb +149 -0
  96. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/guard.rb +230 -0
  97. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/locale.rb +11 -0
  98. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/observer.rb +41 -0
  99. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record.rb +492 -0
  100. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper/observer.rb +139 -0
  101. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper.rb +351 -0
  102. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/sequel.rb +322 -0
  103. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations.rb +68 -0
  104. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine.rb +1467 -0
  105. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine_collection.rb +155 -0
  106. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher.rb +123 -0
  107. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher_helpers.rb +54 -0
  108. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/node_collection.rb +152 -0
  109. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state.rb +249 -0
  110. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state_collection.rb +112 -0
  111. data/lib/branston/vendor/plugins/state_machine/lib/state_machine/transition.rb +394 -0
  112. data/lib/branston/vendor/plugins/state_machine/lib/state_machine.rb +388 -0
  113. data/lib/branston/vendor/plugins/state_machine/state_machine.gemspec +30 -0
  114. data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rake +1 -0
  115. data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rb +30 -0
  116. data/lib/branston/vendor/plugins/state_machine/test/classes/switch.rb +11 -0
  117. data/lib/branston/vendor/plugins/state_machine/test/functional/state_machine_test.rb +941 -0
  118. data/lib/branston/vendor/plugins/state_machine/test/test_helper.rb +4 -0
  119. data/lib/branston/vendor/plugins/state_machine/test/unit/assertions_test.rb +40 -0
  120. data/lib/branston/vendor/plugins/state_machine/test/unit/callback_test.rb +455 -0
  121. data/lib/branston/vendor/plugins/state_machine/test/unit/condition_proxy_test.rb +328 -0
  122. data/lib/branston/vendor/plugins/state_machine/test/unit/eval_helpers_test.rb +120 -0
  123. data/lib/branston/vendor/plugins/state_machine/test/unit/event_collection_test.rb +326 -0
  124. data/lib/branston/vendor/plugins/state_machine/test/unit/event_test.rb +743 -0
  125. data/lib/branston/vendor/plugins/state_machine/test/unit/guard_test.rb +908 -0
  126. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/active_record_test.rb +1367 -0
  127. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/data_mapper_test.rb +962 -0
  128. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/sequel_test.rb +859 -0
  129. data/lib/branston/vendor/plugins/state_machine/test/unit/integrations_test.rb +42 -0
  130. data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_event_test.rb +7 -0
  131. data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_transition_test.rb +7 -0
  132. data/lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb +938 -0
  133. data/lib/branston/vendor/plugins/state_machine/test/unit/machine_test.rb +2004 -0
  134. data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_helpers_test.rb +37 -0
  135. data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_test.rb +155 -0
  136. data/lib/branston/vendor/plugins/state_machine/test/unit/node_collection_test.rb +207 -0
  137. data/lib/branston/vendor/plugins/state_machine/test/unit/state_collection_test.rb +280 -0
  138. data/lib/branston/vendor/plugins/state_machine/test/unit/state_machine_test.rb +31 -0
  139. data/lib/branston/vendor/plugins/state_machine/test/unit/state_test.rb +795 -0
  140. data/lib/branston/vendor/plugins/state_machine/test/unit/transition_test.rb +1212 -0
  141. metadata +81 -2
@@ -0,0 +1,230 @@
1
+ require 'state_machine/matcher'
2
+ require 'state_machine/eval_helpers'
3
+ require 'state_machine/assertions'
4
+
5
+ module StateMachine
6
+ # Represents a set of requirements that must be met in order for a transition
7
+ # or callback to occur. Guards verify that the event, from state, and to
8
+ # state of the transition match, in addition to if/unless conditionals for
9
+ # an object's state.
10
+ class Guard
11
+ include Assertions
12
+ include EvalHelpers
13
+
14
+ # The condition that must be met on an object
15
+ attr_reader :if_condition
16
+
17
+ # The condition that must *not* be met on an object
18
+ attr_reader :unless_condition
19
+
20
+ # The requirement for verifying the event being guarded
21
+ attr_reader :event_requirement
22
+
23
+ # One or more requirements for verifying the states being guarded. All
24
+ # requirements contain a mapping of {:from => matcher, :to => matcher}.
25
+ attr_reader :state_requirements
26
+
27
+ # The requirement for verifying the success of the event
28
+ attr_reader :success_requirement
29
+
30
+ # A list of all of the states known to this guard. This will pull states
31
+ # from the following options (in the same order):
32
+ # * +from+ / +except_from+
33
+ # * +to+ / +except_to+
34
+ attr_reader :known_states
35
+
36
+ # Creates a new guard
37
+ def initialize(options = {}) #:nodoc:
38
+ # Build conditionals
39
+ @if_condition = options.delete(:if)
40
+ @unless_condition = options.delete(:unless)
41
+
42
+ # Build event requirement
43
+ @event_requirement = build_matcher(options, :on, :except_on)
44
+
45
+ # Build success requirement
46
+ @success_requirement = options.delete(:include_failures) ? AllMatcher.instance : WhitelistMatcher.new([true])
47
+
48
+ if (options.keys - [:from, :to, :on, :except_from, :except_to, :except_on]).empty?
49
+ # Explicit from/to requirements specified
50
+ @state_requirements = [{:from => build_matcher(options, :from, :except_from), :to => build_matcher(options, :to, :except_to)}]
51
+ else
52
+ # Separate out the event requirement
53
+ options.delete(:on)
54
+ options.delete(:except_on)
55
+
56
+ # Implicit from/to requirements specified
57
+ @state_requirements = options.collect do |from, to|
58
+ from = WhitelistMatcher.new(from) unless from.is_a?(Matcher)
59
+ to = WhitelistMatcher.new(to) unless to.is_a?(Matcher)
60
+ {:from => from, :to => to}
61
+ end
62
+ end
63
+
64
+ # Track known states. The order that requirements are iterated is based
65
+ # on the priority in which tracked states should be added.
66
+ @known_states = []
67
+ @state_requirements.each do |state_requirement|
68
+ [:from, :to].each {|option| @known_states |= state_requirement[option].values}
69
+ end
70
+ end
71
+
72
+ # Determines whether the given object / query matches the requirements
73
+ # configured for this guard. In addition to matching the event, from state,
74
+ # and to state, this will also check whether the configured :if/:unless
75
+ # conditions pass on the given object.
76
+ #
77
+ # == Examples
78
+ #
79
+ # guard = StateMachine::Guard.new(:parked => :idling, :on => :ignite)
80
+ #
81
+ # # Successful
82
+ # guard.matches?(object, :on => :ignite) # => true
83
+ # guard.matches?(object, :from => nil) # => true
84
+ # guard.matches?(object, :from => :parked) # => true
85
+ # guard.matches?(object, :to => :idling) # => true
86
+ # guard.matches?(object, :from => :parked, :to => :idling) # => true
87
+ # guard.matches?(object, :on => :ignite, :from => :parked, :to => :idling) # => true
88
+ #
89
+ # # Unsuccessful
90
+ # guard.matches?(object, :on => :park) # => false
91
+ # guard.matches?(object, :from => :idling) # => false
92
+ # guard.matches?(object, :to => :first_gear) # => false
93
+ # guard.matches?(object, :from => :parked, :to => :first_gear) # => false
94
+ # guard.matches?(object, :on => :park, :from => :parked, :to => :idling) # => false
95
+ def matches?(object, query = {})
96
+ !match(object, query).nil?
97
+ end
98
+
99
+ # Attempts to match the given object / query against the set of requirements
100
+ # configured for this guard. In addition to matching the event, from state,
101
+ # and to state, this will also check whether the configured :if/:unless
102
+ # conditions pass on the given object.
103
+ #
104
+ # If a match is found, then the event/state requirements that the query
105
+ # passed successfully will be returned. Otherwise, nil is returned if there
106
+ # was no match.
107
+ #
108
+ # Query options:
109
+ # * <tt>:from</tt> - One or more states being transitioned from. If none
110
+ # are specified, then this will always match.
111
+ # * <tt>:to</tt> - One or more states being transitioned to. If none are
112
+ # specified, then this will always match.
113
+ # * <tt>:on</tt> - One or more events that fired the transition. If none
114
+ # are specified, then this will always match.
115
+ #
116
+ # == Examples
117
+ #
118
+ # guard = StateMachine::Guard.new(:parked => :idling, :on => :ignite)
119
+ #
120
+ # guard.match(object, :on => :ignite) # => {:to => ..., :from => ..., :on => ...}
121
+ # guard.match(object, :on => :park) # => nil
122
+ def match(object, query = {})
123
+ if (match = match_query(query)) && matches_conditions?(object)
124
+ match
125
+ end
126
+ end
127
+
128
+ # Draws a representation of this guard on the given graph. This will draw
129
+ # an edge between every state this guard matches *from* to either the
130
+ # configured to state or, if none specified, then a loopback to the from
131
+ # state.
132
+ #
133
+ # For example, if the following from states are configured:
134
+ # * +idling+
135
+ # * +first_gear+
136
+ # * +backing_up+
137
+ #
138
+ # ...and the to state is +parked+, then the following edges will be created:
139
+ # * +idling+ -> +parked+
140
+ # * +first_gear+ -> +parked+
141
+ # * +backing_up+ -> +parked+
142
+ #
143
+ # Each edge will be labeled with the name of the event that would cause the
144
+ # transition.
145
+ #
146
+ # The collection of edges generated on the graph will be returned.
147
+ def draw(graph, event, valid_states)
148
+ state_requirements.inject([]) do |edges, state_requirement|
149
+ # From states determined based on the known valid states
150
+ from_states = state_requirement[:from].filter(valid_states)
151
+
152
+ # If a to state is not specified, then it's a loopback and each from
153
+ # state maps back to itself
154
+ if state_requirement[:to].values.empty?
155
+ loopback = true
156
+ else
157
+ to_state = state_requirement[:to].values.first
158
+ to_state = to_state ? to_state.to_s : 'nil'
159
+ loopback = false
160
+ end
161
+
162
+ # Generate an edge between each from and to state
163
+ from_states.each do |from_state|
164
+ from_state = from_state ? from_state.to_s : 'nil'
165
+ edges << graph.add_edge(from_state, loopback ? from_state : to_state, :label => event.to_s)
166
+ end
167
+
168
+ edges
169
+ end
170
+ end
171
+
172
+ protected
173
+ # Builds a matcher strategy to use for the given options. If neither a
174
+ # whitelist nor a blacklist option is specified, then an AllMatcher is
175
+ # built.
176
+ def build_matcher(options, whitelist_option, blacklist_option)
177
+ assert_exclusive_keys(options, whitelist_option, blacklist_option)
178
+
179
+ if options.include?(whitelist_option)
180
+ WhitelistMatcher.new(options[whitelist_option])
181
+ elsif options.include?(blacklist_option)
182
+ BlacklistMatcher.new(options[blacklist_option])
183
+ else
184
+ AllMatcher.instance
185
+ end
186
+ end
187
+
188
+ # Verifies that all configured requirements (event and state) match the
189
+ # given query. If a match is found, then a hash containing the
190
+ # event/state requirements that passed will be returned; otherwise, nil.
191
+ def match_query(query)
192
+ query ||= {}
193
+
194
+ if match_success(query) && match_event(query) && (state_requirement = match_states(query))
195
+ state_requirement.merge(:on => event_requirement)
196
+ end
197
+ end
198
+
199
+ # Verifies that the success requirement matches the given query
200
+ def match_success(query)
201
+ matches_requirement?(query, :success, success_requirement)
202
+ end
203
+
204
+ # Verifies that the event requirement matches the given query
205
+ def match_event(query)
206
+ matches_requirement?(query, :on, event_requirement)
207
+ end
208
+
209
+ # Verifies that the state requirements match the given query. If a
210
+ # matching requirement is found, then it is returned.
211
+ def match_states(query)
212
+ state_requirements.detect do |state_requirement|
213
+ [:from, :to].all? {|option| matches_requirement?(query, option, state_requirement[option])}
214
+ end
215
+ end
216
+
217
+ # Verifies that an option in the given query matches the values required
218
+ # for that option
219
+ def matches_requirement?(query, option, requirement)
220
+ !query.include?(option) || requirement.matches?(query[option], query)
221
+ end
222
+
223
+ # Verifies that the conditionals for this guard evaluate to true for the
224
+ # given object
225
+ def matches_conditions?(object)
226
+ Array(if_condition).all? {|condition| evaluate_method(object, condition)} &&
227
+ !Array(unless_condition).any? {|condition| evaluate_method(object, condition)}
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,11 @@
1
+ {:en => {
2
+ :activerecord => {
3
+ :errors => {
4
+ :messages => {
5
+ :invalid => StateMachine::Machine.default_messages[:invalid],
6
+ :invalid_event => StateMachine::Machine.default_messages[:invalid_event] % ['{{state}}'],
7
+ :invalid_transition => StateMachine::Machine.default_messages[:invalid_transition] % ['{{event}}']
8
+ }
9
+ }
10
+ }
11
+ }}
@@ -0,0 +1,41 @@
1
+ module StateMachine
2
+ module Integrations #:nodoc:
3
+ module ActiveRecord
4
+ # Adds support for invoking callbacks on ActiveRecord observers with more
5
+ # than one argument (e.g. the record *and* the state transition). By
6
+ # default, ActiveRecord only supports passing the record into the
7
+ # callbacks.
8
+ #
9
+ # For example:
10
+ #
11
+ # class VehicleObserver < ActiveRecord::Observer
12
+ # # The default behavior: only pass in the record
13
+ # def after_save(vehicle)
14
+ # end
15
+ #
16
+ # # Custom behavior: allow the transition to be passed in as well
17
+ # def after_transition(vehicle, transition)
18
+ # Audit.log(vehicle, transition)
19
+ # end
20
+ # end
21
+ module Observer
22
+ def self.included(base) #:nodoc:
23
+ base.class_eval do
24
+ alias_method :update_without_multiple_args, :update
25
+ alias_method :update, :update_with_multiple_args
26
+ end
27
+ end
28
+
29
+ # Allows additional arguments other than the object to be passed to the
30
+ # observed methods
31
+ def update_with_multiple_args(observed_method, object, *args) #:nodoc:
32
+ send(observed_method, object, *args) if respond_to?(observed_method)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ ActiveRecord::Observer.class_eval do
40
+ include StateMachine::Integrations::ActiveRecord::Observer
41
+ end