1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Pending tests for AD Response

This commit is contained in:
Joshua Peek 2009-12-17 22:10:06 -06:00
parent 3b44f35e24
commit 2419fae092
2 changed files with 125 additions and 13 deletions

View file

@ -145,18 +145,6 @@ module ActionDispatch # :nodoc:
cattr_accessor(:default_charset) { "utf-8" } cattr_accessor(:default_charset) { "utf-8" }
def assign_default_content_type_and_charset!
return if headers[CONTENT_TYPE].present?
@content_type ||= Mime::HTML
@charset ||= self.class.default_charset
type = @content_type.to_s.dup
type << "; charset=#{@charset}" unless @sending_file
headers[CONTENT_TYPE] = type
end
def to_a def to_a
assign_default_content_type_and_charset! assign_default_content_type_and_charset!
handle_conditional_get! handle_conditional_get!
@ -259,6 +247,18 @@ module ActionDispatch # :nodoc:
!@blank && @body.respond_to?(:all?) && @body.all? { |part| part.is_a?(String) } !@blank && @body.respond_to?(:all?) && @body.all? { |part| part.is_a?(String) }
end end
def assign_default_content_type_and_charset!
return if headers[CONTENT_TYPE].present?
@content_type ||= Mime::HTML
@charset ||= self.class.default_charset
type = @content_type.to_s.dup
type << "; charset=#{@charset}" unless @sending_file
headers[CONTENT_TYPE] = type
end
DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate" DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate"
def set_conditional_cache_control! def set_conditional_cache_control!
@ -280,7 +280,6 @@ module ActionDispatch # :nodoc:
headers["Cache-Control"] = options.join(", ") headers["Cache-Control"] = options.join(", ")
end end
end end
end end
end end

View file

@ -117,4 +117,117 @@ class ResponseTest < ActiveSupport::TestCase
assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"] assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"]
assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies)
end end
test "read cache control" do
resp = ActionDispatch::Response.new.tap { |resp|
resp.cache_control[:public] = true
resp.etag = '123'
resp.body = 'Hello'
}
resp.to_a
assert_equal('"202cb962ac59075b964b07152d234b70"', resp.etag)
assert_equal({:public => true}, resp.cache_control)
assert_equal('public', resp.headers['Cache-Control'])
assert_equal('"202cb962ac59075b964b07152d234b70"', resp.headers['ETag'])
end
test "read charset and content type" do
resp = ActionDispatch::Response.new.tap { |resp|
resp.charset = 'utf-16'
resp.content_type = Mime::XML
resp.body = 'Hello'
}
resp.to_a
assert_equal('utf-16', resp.charset)
assert_equal(Mime::XML, resp.content_type)
assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type'])
end
end
class ResponseIntegrationTest < ActionDispatch::IntegrationTest
def app
@app
end
test "response cache control from railsish app" do
@app = lambda { |env|
ActionDispatch::Response.new.tap { |resp|
resp.cache_control[:public] = true
resp.etag = '123'
resp.body = 'Hello'
}.to_a
}
get '/'
assert_response :success
assert_equal('public', @response.headers['Cache-Control'])
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag'])
pending do
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag)
assert_equal({:public => true}, @response.cache_control)
end
end
test "response cache control from rackish app" do
@app = lambda { |env|
[200,
{'ETag' => '"202cb962ac59075b964b07152d234b70"',
'Cache-Control' => 'public'}, 'Hello']
}
get '/'
assert_response :success
assert_equal('public', @response.headers['Cache-Control'])
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag'])
pending do
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag)
assert_equal({:public => true}, @response.cache_control)
end
end
test "response charset and content type from railsish app" do
@app = lambda { |env|
ActionDispatch::Response.new.tap { |resp|
resp.charset = 'utf-16'
resp.content_type = Mime::XML
resp.body = 'Hello'
}.to_a
}
get '/'
assert_response :success
pending do
assert_equal('utf-16', @response.charset)
assert_equal(Mime::XML, @response.content_type)
end
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
end
test "response charset and content type from rackish app" do
@app = lambda { |env|
[200,
{'Content-Type' => 'application/xml; charset=utf-16'},
'Hello']
}
get '/'
assert_response :success
pending do
assert_equal('utf-16', @response.charset)
assert_equal(Mime::XML, @response.content_type)
end
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
end
end end