2009-03-18 18:58:47 -04:00
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
class ApplicationController < ActionController::Base
|
2009-03-23 21:06:47 -04:00
|
|
|
end
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
module RenderText
|
2009-05-01 20:27:44 -04:00
|
|
|
class SimpleController < ActionController::Base
|
2009-04-27 21:21:26 -04:00
|
|
|
self.view_paths = [ActionView::Template::FixturePath.new]
|
2009-03-20 21:38:03 -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-04-29 14:42:27 -04:00
|
|
|
class TestSimpleTextRenderWithNoLayout < SimpleRouteCase
|
|
|
|
describe "Rendering text from a action with default options renders the text with the layout"
|
|
|
|
|
|
|
|
get "/render_text/simple"
|
|
|
|
assert_body "hello david"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class WithLayoutController < ::ApplicationController
|
2009-04-27 21:21:26 -04:00
|
|
|
self.view_paths = [ActionView::Template::FixturePath.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 %>"
|
2009-03-23 21:06:47 -04:00
|
|
|
)]
|
2009-03-20 19:13:13 -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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
def with_nil
|
2009-03-18 18:58:47 -04:00
|
|
|
render :text => nil
|
|
|
|
end
|
|
|
|
|
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
|
2009-03-20 19:13:13 -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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
2009-03-20 21:38:03 -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-03-20 21:38:03 -04:00
|
|
|
class TestSimpleTextRenderWithLayout < SimpleRouteCase
|
2009-03-20 19:13:13 -04:00
|
|
|
describe "Rendering text from a action with default options renders the text without the layout"
|
2009-03-18 18:58:47 -04:00
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout"
|
2009-03-18 18:58:47 -04:00
|
|
|
assert_body "hello david"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithStatus < SimpleRouteCase
|
|
|
|
describe "Rendering text, while also providing a custom status code"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/custom_code"
|
2009-03-18 18:58:47 -04:00
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 404
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithNil < SimpleRouteCase
|
|
|
|
describe "Rendering text with nil returns a single space character"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_nil"
|
2009-03-18 18:58:47 -04:00
|
|
|
assert_body " "
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithNilAndStatus < SimpleRouteCase
|
|
|
|
describe "Rendering text with nil and custom status code returns a single space character with the status"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_nil_and_status"
|
2009-03-18 18:58:47 -04:00
|
|
|
assert_body " "
|
|
|
|
assert_status 403
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithFalse < SimpleRouteCase
|
|
|
|
describe "Rendering text with false returns the string 'false'"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_false"
|
2009-03-18 18:58:47 -04:00
|
|
|
assert_body "false"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-20 19:13:13 -04:00
|
|
|
|
|
|
|
class TestTextRenderWithLayoutTrue < SimpleRouteCase
|
|
|
|
describe "Rendering text with :layout => true"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_layout_true"
|
2009-03-20 19:13:13 -04:00
|
|
|
assert_body "hello world, I'm here!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithCustomLayout < SimpleRouteCase
|
|
|
|
describe "Rendering text with :layout => 'greetings'"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_custom_layout"
|
2009-03-20 19:13:13 -04:00
|
|
|
assert_body "hello world, I wish thee well."
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-20 19:50:51 -04:00
|
|
|
|
|
|
|
class TestTextRenderWithLayoutFalse < SimpleRouteCase
|
|
|
|
describe "Rendering text with :layout => false"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_layout_false"
|
2009-03-20 19:50:51 -04:00
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTextRenderWithLayoutNil < SimpleRouteCase
|
|
|
|
describe "Rendering text with :layout => nil"
|
|
|
|
|
2009-04-29 14:42:27 -04:00
|
|
|
get "/render_text/with_layout/with_layout_nil"
|
2009-03-20 19:50:51 -04:00
|
|
|
assert_body "hello world"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-23 21:06:47 -04:00
|
|
|
end
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
ActionController::Base.app_loaded!
|