Browse files

Had an issue with asserts_response not being included in child contex…

…ts of ActionController specific trees
  • Loading branch information...
1 parent 9ef9d83 commit f556c74e203c0ca8d46f5d30ca75df00589186be @gus gus committed Jun 19, 2010
View
6 CHANGELOG
@@ -1,4 +1,8 @@
-*0.2.0.pre.1*
+*0.2.0.pre.3*
+
+* ISSUE: Whelp, needed to account for parent contexts being ActionController handlers. Fixed [jaknowlden]
+
+*0.2.0.pre.2*
* When rails does redirects, it does not set action_controller.instance as you might expect; users should still have access to the response, though. This fixes that [jaknowlden]
View
2 VERSION
@@ -1 +1 @@
-0.2.0.pre.2
+0.2.0.pre.3
View
21 lib/riot/action_controller/context_middleware.rb
@@ -3,22 +3,25 @@ class ActionControllerMiddleware < Riot::ContextMiddleware
register
def call(context)
- if handle?(context)
- setup_context_macros(context)
- setup_situation(context)
- end
+ setup_situation(context) if handle?(context.description)
+ setup_context_macros(context) if nested_handle?(context)
middleware.call(context)
end
private
- def handle?(context)
- description = context.description
+ def handle?(description)
description.kind_of?(Class) && description.ancestors.include?(::ActionController::Base)
end
+ # Walking the description chain looking to see if any of them are serviceable
+ #
+ # TODO: see if we can't define a method on the context to observe instead of calling
+ # action_controller_description? each time
+ def nested_handle?(context)
+ (handle?(context.description) || nested_handle?(context.parent)) if context.respond_to?(:description)
+ end
+
def setup_context_macros(context)
- context.class_eval do
- include RiotRails::ActionController::AssertsResponse
- end
+ context.class_eval { include RiotRails::ActionController::AssertsResponse }
end
def setup_situation(context)
View
9 test/action_controller/context_macros/asserts_response_test.rb
@@ -32,4 +32,13 @@
asserts(:to_s).equals("asserts response #status")
asserts("output of running the test") { topic.run(situation).first }.equals(:pass)
end
+
+ context "used in the child context of an ActionController context" do
+ setup do
+ child_context = topic.context("child") {}
+ child_context.asserts_response.run(situation)
+ end
+
+ asserts_topic.equals([:pass, ""])
+ end # used in the child context of an ActionController context
end # An asserts_response context macro

0 comments on commit f556c74

Please sign in to comment.