mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
1310231c15
* request.formats is much simpler now * For XHRs or Accept headers with a single item, we use the Accept header * For other requests, we use params[:format] or fallback to HTML * This is primarily to work around the fact that browsers provide completely broken Accept headers, so we have to whitelist the few cases we can specifically isolate and treat other requests as coming from the browser * For APIs, we can support single-item Accept headers, which disambiguates from the browsers * Requests to an action that only has an XML template from the browser will no longer find the template. This worked previously because most browsers provide a catch-all */*, but this was mostly accidental behavior. If you want to serve XML, either use the :xml format in links, or explicitly specify the XML template: render "template.xml".
39 lines
No EOL
893 B
Ruby
39 lines
No EOL
893 B
Ruby
require 'abstract_unit'
|
|
require 'controller/fake_models'
|
|
require 'pathname'
|
|
|
|
class TestController < ActionController::Base
|
|
protect_from_forgery
|
|
|
|
def render_vanilla_js_hello
|
|
render :js => "alert('hello')"
|
|
end
|
|
|
|
def greeting
|
|
# let's just rely on the template
|
|
end
|
|
|
|
def show_partial
|
|
render :partial => 'partial'
|
|
end
|
|
end
|
|
|
|
class RenderTest < ActionController::TestCase
|
|
tests TestController
|
|
|
|
def test_render_vanilla_js
|
|
get :render_vanilla_js_hello
|
|
assert_equal "alert('hello')", @response.body
|
|
assert_equal "text/javascript", @response.content_type
|
|
end
|
|
|
|
def test_render_with_default_from_accept_header
|
|
xhr :get, :greeting
|
|
assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
|
|
end
|
|
|
|
def test_should_render_js_partial
|
|
xhr :get, :show_partial, :format => 'js'
|
|
assert_equal 'partial js', @response.body
|
|
end
|
|
end |