2009-09-19 13:10:41 -04:00
|
|
|
require 'abstract_unit'
|
2009-03-18 18:58:47 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
module RenderText
|
2009-05-01 20:27:44 -04:00
|
|
|
class SimpleController < ActionController::Base
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new]
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def index
|
2009-03-20 21:38:03 -04:00
|
|
|
render :text => "hello david"
|
|
|
|
end
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
class WithLayoutController < ::ApplicationController
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2009-03-20 19:13:13 -04:00
|
|
|
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
|
2009-04-29 14:42:27 -04:00
|
|
|
"layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.",
|
|
|
|
"layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>"
|
2010-08-14 01:13:00 -04:00
|
|
|
)]
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def index
|
2009-03-20 19:13:13 -04:00
|
|
|
render :text => "hello david"
|
2009-03-18 18:58:47 -04:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def custom_code
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => "hello world", :status => 404
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_custom_code_as_string
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => "hello world", :status => "404 Not Found"
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_nil
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => nil
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_nil_and_status
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => nil, :status => 403
|
|
|
|
end
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_false
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => false
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_layout_true
|
2009-03-20 19:13:13 -04:00
|
|
|
render :text => "hello world", :layout => true
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_layout_false
|
2009-03-20 19:50:51 -04:00
|
|
|
render :text => "hello world", :layout => false
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_layout_nil
|
2009-03-20 19:50:51 -04:00
|
|
|
render :text => "hello world", :layout => nil
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_custom_layout
|
2009-03-20 19:13:13 -04:00
|
|
|
render :text => "hello world", :layout => "greetings"
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_ivar_in_layout
|
|
|
|
@ivar = "hello world"
|
|
|
|
render :text => "hello world", :layout => "ivar"
|
|
|
|
end
|
2009-03-20 21:38:03 -04:00
|
|
|
end
|
2009-04-29 14:42:27 -04:00
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class RenderTextTest < Rack::TestCase
|
2009-05-20 15:15:06 -04:00
|
|
|
describe "Rendering text using render :text"
|
|
|
|
|
|
|
|
test "rendering text from a action with default options renders the text with the layout" do
|
2010-08-06 11:57:58 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw { match ':controller', :action => 'index' }
|
|
|
|
|
|
|
|
get "/render_text/simple"
|
|
|
|
assert_body "hello david"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text from a action with default options renders the text without the layout" do
|
2010-08-06 11:57:58 -04:00
|
|
|
with_routing do |set|
|
|
|
|
set.draw { match ':controller', :action => 'index' }
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2010-08-06 11:57:58 -04:00
|
|
|
get "/render_text/with_layout"
|
|
|
|
|
|
|
|
assert_body "hello david"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text, while also providing a custom status code" do
|
|
|
|
get "/render_text/with_layout/custom_code"
|
|
|
|
|
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 404
|
|
|
|
end
|
|
|
|
|
2009-05-21 23:22:18 -04:00
|
|
|
test "rendering text with nil returns an empty body padded for Safari" do
|
2009-05-20 15:15:06 -04:00
|
|
|
get "/render_text/with_layout/with_nil"
|
|
|
|
|
|
|
|
assert_body " "
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
2009-05-21 23:22:18 -04:00
|
|
|
test "Rendering text with nil and custom status code returns an empty body padded for Safari and the status" do
|
2009-05-20 15:15:06 -04:00
|
|
|
get "/render_text/with_layout/with_nil_and_status"
|
|
|
|
|
|
|
|
assert_body " "
|
|
|
|
assert_status 403
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text with false returns the string 'false'" do
|
|
|
|
get "/render_text/with_layout/with_false"
|
|
|
|
|
|
|
|
assert_body "false"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text with :layout => true" do
|
|
|
|
get "/render_text/with_layout/with_layout_true"
|
|
|
|
|
|
|
|
assert_body "hello world, I'm here!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text with :layout => 'greetings'" do
|
|
|
|
get "/render_text/with_layout/with_custom_layout"
|
|
|
|
|
|
|
|
assert_body "hello world, I wish thee well."
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text with :layout => false" do
|
|
|
|
get "/render_text/with_layout/with_layout_false"
|
|
|
|
|
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering text with :layout => nil" do
|
|
|
|
get "/render_text/with_layout/with_layout_nil"
|
|
|
|
|
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-20 19:50:51 -04:00
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|