Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added proper getters and setters for content type and charset [DHH] A…
…dded utf-8 as the default charset for all renders. You can change this default using ActionController::Base.default_charset=(encoding) [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5129 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
11 changed files
with
158 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
require File.dirname(__FILE__) + '/../abstract_unit' | ||
|
||
class ContentTypeController < ActionController::Base | ||
def render_content_type_from_body | ||
response.content_type = Mime::RSS | ||
render :text => "hello world!" | ||
end | ||
|
||
def render_defaults | ||
render :text => "hello world!" | ||
end | ||
|
||
def render_content_type_from_render | ||
render :text => "hello world!", :content_type => Mime::RSS | ||
end | ||
|
||
def render_charset_from_body | ||
response.charset = "utf-16" | ||
render :text => "hello world!" | ||
end | ||
|
||
def render_default_for_rhtml | ||
end | ||
|
||
def render_default_for_rxml | ||
end | ||
|
||
def render_change_for_rxml | ||
response.content_type = Mime::HTML | ||
render :action => "render_default_for_rxml" | ||
end | ||
|
||
def rescue_action(e) raise end | ||
end | ||
|
||
ContentTypeController.template_root = File.dirname(__FILE__) + "/../fixtures/" | ||
|
||
class ContentTypeTest < Test::Unit::TestCase | ||
def setup | ||
@controller = ContentTypeController.new | ||
|
||
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get | ||
# a more accurate simulation of what happens in "real life". | ||
@controller.logger = Logger.new(nil) | ||
|
||
@request = ActionController::TestRequest.new | ||
@response = ActionController::TestResponse.new | ||
end | ||
|
||
def test_render_defaults | ||
get :render_defaults | ||
assert_equal "utf-8", @response.charset | ||
assert_equal Mime::HTML, @response.content_type | ||
end | ||
|
||
def test_render_changed_charset_default | ||
ContentTypeController.default_charset = "utf-16" | ||
get :render_defaults | ||
assert_equal "utf-16", @response.charset | ||
assert_equal Mime::HTML, @response.content_type | ||
ContentTypeController.default_charset = "utf-8" | ||
end | ||
|
||
def test_content_type_from_body | ||
get :render_content_type_from_body | ||
assert_equal "application/rss+xml", @response.content_type | ||
assert_equal "utf-8", @response.charset | ||
end | ||
|
||
def test_content_type_from_render | ||
get :render_content_type_from_render | ||
assert_equal "application/rss+xml", @response.content_type | ||
assert_equal "utf-8", @response.charset | ||
end | ||
|
||
def test_charset_from_body | ||
get :render_charset_from_body | ||
assert_equal "utf-16", @response.charset | ||
assert_equal Mime::HTML, @response.content_type | ||
end | ||
|
||
def test_default_for_rhtml | ||
get :render_default_for_rhtml | ||
assert_equal Mime::HTML, @response.content_type | ||
assert_equal "utf-8", @response.charset | ||
end | ||
|
||
def test_default_for_rxml | ||
get :render_default_for_rxml | ||
assert_equal Mime::XML, @response.content_type | ||
assert_equal "utf-8", @response.charset | ||
end | ||
|
||
def test_change_for_rxml | ||
get :render_change_for_rxml | ||
assert_equal Mime::HTML, @response.content_type | ||
assert_equal "utf-8", @response.charset | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= 'hello world!' %> |
1 change: 1 addition & 0 deletions
1
actionpack/test/fixtures/content_type/render_default_for_rxml.rxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xml.p "Hello world!" |