Skip to content
Browse files

Fix a few bugs when trying to use Head standalone

  • Loading branch information...
1 parent 38d78f9 commit 8cb2cfbf71092f95090335cbdde0340cc74db748 @wycats wycats committed Oct 10, 2010
View
1 actionpack/lib/abstract_controller/base.rb
@@ -13,6 +13,7 @@ class ActionNotFound < StandardError; end
class Base
attr_internal :response_body
attr_internal :action_name
+ attr_internal :formats
include ActiveSupport::Configurable
extend ActiveSupport::DescendantsTracker
View
5 actionpack/lib/action_controller/metal.rb
@@ -119,6 +119,11 @@ def location=(url)
headers["Location"] = url
end
+ # basic url_for that can be overridden for more robust functionality
+ def url_for(string)
+ string
+ end
+
def status
@_status
end
View
6 actionpack/lib/action_controller/metal/head.rb
@@ -2,8 +2,6 @@ module ActionController
module Head
extend ActiveSupport::Concern
- include ActionController::UrlFor
-
# Return a response that has no content (merely headers). The options
# argument is interpreted to be a hash of header names and values.
# This allows you to easily return a response that consists only of
@@ -27,8 +25,8 @@ def head(status, options = {})
self.status = status
self.location = url_for(location) if location
- self.content_type = Mime[formats.first]
+ self.content_type = Mime[formats.first] if formats
self.response_body = " "
end
end
-end
+end
View
15 actionpack/test/controller/new_base/bare_metal_test.rb
@@ -24,4 +24,19 @@ class BareTest < ActiveSupport::TestCase
assert_equal "Hello world", string
end
end
+
+ class HeadController < ActionController::Metal
+ include ActionController::Head
+
+ def index
+ head :not_found
+ end
+ end
+
+ class HeadTest < ActiveSupport::TestCase
+ test "head works on its own" do
+ status, headers, body = HeadController.action(:index).call(Rack::MockRequest.env_for("/"))
+ assert_equal 404, status
+ end
+ end
end

0 comments on commit 8cb2cfb

Please sign in to comment.
Something went wrong with that request. Please try again.