From 628110d7eeb446fee7f9e043f113c083d24883c1 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Thu, 14 May 2009 17:42:20 -0700
Subject: Active Support dependencies
---
actionpack/test/abstract_controller/layouts_test.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb
index 6e1c2bf9e8..d3440c3de0 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/actionpack/test/abstract_controller/layouts_test.rb
@@ -1,4 +1,5 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'active_support/core_ext/class/removal'
module AbstractControllerTests
module Layouts
--
cgit v1.2.3
From 7f318c3ec535afe53733c55cd0ecaccc16a8b944 Mon Sep 17 00:00:00 2001
From: Bryan Helmkamp
Date: Sat, 16 May 2009 14:15:26 -0400
Subject: Instead of checking Rails.env.test? in Failsafe middleware, check
env["rails.raise_exceptions"]
---
actionpack/test/new_base/render_action_test.rb | 6 ++++--
actionpack/test/new_base/render_test.rb | 6 +++---
2 files changed, 7 insertions(+), 5 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index f25faee433..96666077d2 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -92,7 +92,7 @@ module RenderAction
test "raises an exception when requesting a layout and none exist" do
assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do
- get "/render_action/basic/hello_world_with_layout"
+ get "/render_action/basic/hello_world_with_layout", {}, "rails.raise_exceptions" => true
end
end
end
@@ -117,7 +117,9 @@ module RenderAction
describe "rendering a normal template with full path with layout => 'greetings'"
test "raises an exception when requesting a layout that does not exist" do
- assert_raise(ActionView::MissingTemplate) { get "/render_action/basic/hello_world_with_custom_layout" }
+ assert_raise(ActionView::MissingTemplate) do
+ get "/render_action/basic/hello_world_with_custom_layout", {}, "rails.raise_exceptions" => true
+ end
end
end
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
index b1867fdcc2..16578fbc82 100644
--- a/actionpack/test/new_base/render_test.rb
+++ b/actionpack/test/new_base/render_test.rb
@@ -48,7 +48,7 @@ module Render
test "raises an exception" do
assert_raises(AbstractController::DoubleRenderError) do
- get "/render/double_render"
+ get "/render/double_render", {}, "rails.raise_exceptions" => true
end
end
end
@@ -58,13 +58,13 @@ module Render
test "raises an exception when a method of Object is called" do
assert_raises(AbstractController::ActionNotFound) do
- get "/render/blank_render/clone"
+ get "/render/blank_render/clone", {}, "rails.raise_exceptions" => true
end
end
test "raises an exception when a private method is called" do
assert_raises(AbstractController::ActionNotFound) do
- get "/render/blank_render/secretz"
+ get "/render/blank_render/secretz", {}, "rails.raise_exceptions" => true
end
end
end
--
cgit v1.2.3
From 11bac700784efe232083f94e3d28d171957e667e Mon Sep 17 00:00:00 2001
From: Lance Ivy
Date: Wed, 15 Apr 2009 16:46:30 -0700
Subject: Ensure auto_link does not ignore multiple trailing punctuations
[#2504 state:resolved]
Signed-off-by: Pratik Naik
---
actionpack/test/template/text_helper_test.rb | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index be7163888e..a780bfc606 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -401,6 +401,13 @@ class TextHelperTest < ActionView::TestCase
auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
:link => :all, :html => { :class => "menu", :target => "_blank" })
end
+
+ def test_auto_link_with_multiple_trailing_punctuations
+ url = "http://youtube.com"
+ url_result = generate_result(url)
+ assert_equal url_result, auto_link(url)
+ assert_equal "(link: #{url_result}).", auto_link("(link: #{url}).")
+ end
def test_cycle_class
value = Cycle.new("one", 2, "3")
--
cgit v1.2.3
From 98eaa2c6834e418959f2a1a18421e4811167e03b Mon Sep 17 00:00:00 2001
From: Travis Briggs
Date: Wed, 18 Mar 2009 21:51:26 -0400
Subject: Ensure number_to_human_size does not strip zeros from the end [#1763
state:resolved]
Signed-off-by: Pratik Naik
---
actionpack/test/template/number_helper_test.rb | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index 29cb60fd73..b6542ef29d 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -118,6 +118,10 @@ class NumberHelperTest < ActionView::TestCase
assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2)
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4)
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4)
+ assert_equal '1 TB', number_to_human_size(1234567890123, :precision => 0)
+ assert_equal '500 MB', number_to_human_size(524288000, :precision=>0)
+ assert_equal '40 KB', number_to_human_size(41010, :precision => 0)
+ assert_equal '40 KB', number_to_human_size(41100, :precision => 0)
end
def test_number_to_human_size_with_custom_delimiter_and_separator
--
cgit v1.2.3
From c3319504f066c9362b4b30e1e15bbd1cadde8e25 Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sun, 17 May 2009 11:09:14 -0500
Subject: Rescue hack was supposed to be removed. Some how it crept back in.
---
actionpack/test/controller/filters_test.rb | 1 -
actionpack/test/controller/helper_test.rb | 3 ---
2 files changed, 4 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index 9ad49e9282..afefc6a77e 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -607,7 +607,6 @@ class FilterTest < Test::Unit::TestCase
def test_dynamic_dispatch
%w(foo bar baz).each do |action|
request = ActionController::TestRequest.new
- request.env["action_controller.rescue.request"] = request
request.query_parameters[:choose] = action
response = DynamicDispatchController.action.call(request.env).last
assert_equal action, response.body
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index 7b8096fccc..3bbda9eb3a 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -104,7 +104,6 @@ class HelperTest < Test::Unit::TestCase
def call_controller(klass, action)
request = ActionController::TestRequest.new
- request.env["action_controller.rescue.request"] = request
klass.action(action).call(request.env)
end
@@ -112,7 +111,6 @@ class HelperTest < Test::Unit::TestCase
assert_equal 'hello: Iz guuut!',
call_controller(Fun::GamesController, "render_hello_world").last.body
# request = ActionController::TestRequest.new
- # request.env["action_controller.rescue.request"] = request
#
# resp = Fun::GamesController.action(:render_hello_world).call(request.env)
# assert_equal 'hello: Iz guuut!', resp.last.body
@@ -217,7 +215,6 @@ class IsolatedHelpersTest < Test::Unit::TestCase
def call_controller(klass, action)
request = ActionController::TestRequest.new
- request.env["action_controller.rescue.request"] = request
klass.action(action).call(request.env)
end
--
cgit v1.2.3
From 8118fca9beec675fba19395e7d1027eaa4b5703a Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sun, 17 May 2009 12:24:42 -0500
Subject: Merge Failsafe middleware into ShowExceptions
---
actionpack/test/controller/rescue_test.rb | 14 ++++++++++++++
actionpack/test/dispatch/show_exceptions_test.rb | 5 +++++
actionpack/test/new_base/render_action_test.rb | 4 ++--
actionpack/test/new_base/render_test.rb | 6 +++---
4 files changed, 24 insertions(+), 5 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index f745926b20..490a4ff3b3 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -1,5 +1,19 @@
require 'abstract_unit'
+module ActionDispatch
+ class ShowExceptions
+ private
+ def public_path
+ "#{FIXTURE_LOAD_PATH}/public"
+ end
+
+ # Silence logger
+ def logger
+ nil
+ end
+ end
+end
+
class RescueController < ActionController::Base
class NotAuthorized < StandardError
end
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index f8f562e7c1..0c0c087340 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -6,6 +6,11 @@ module ActionDispatch
def public_path
"#{FIXTURE_LOAD_PATH}/public"
end
+
+ # Silence logger
+ def logger
+ nil
+ end
end
end
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index 96666077d2..626c7b3540 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -92,7 +92,7 @@ module RenderAction
test "raises an exception when requesting a layout and none exist" do
assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do
- get "/render_action/basic/hello_world_with_layout", {}, "rails.raise_exceptions" => true
+ get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false
end
end
end
@@ -118,7 +118,7 @@ module RenderAction
test "raises an exception when requesting a layout that does not exist" do
assert_raise(ActionView::MissingTemplate) do
- get "/render_action/basic/hello_world_with_custom_layout", {}, "rails.raise_exceptions" => true
+ get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false
end
end
end
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
index 16578fbc82..ef5e7d89c5 100644
--- a/actionpack/test/new_base/render_test.rb
+++ b/actionpack/test/new_base/render_test.rb
@@ -48,7 +48,7 @@ module Render
test "raises an exception" do
assert_raises(AbstractController::DoubleRenderError) do
- get "/render/double_render", {}, "rails.raise_exceptions" => true
+ get "/render/double_render", {}, "action_dispatch.show_exceptions" => false
end
end
end
@@ -58,13 +58,13 @@ module Render
test "raises an exception when a method of Object is called" do
assert_raises(AbstractController::ActionNotFound) do
- get "/render/blank_render/clone", {}, "rails.raise_exceptions" => true
+ get "/render/blank_render/clone", {}, "action_dispatch.show_exceptions" => false
end
end
test "raises an exception when a private method is called" do
assert_raises(AbstractController::ActionNotFound) do
- get "/render/blank_render/secretz", {}, "rails.raise_exceptions" => true
+ get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false
end
end
end
--
cgit v1.2.3
From edc9c226d11e6104d191ceeb6416c7062ceda54a Mon Sep 17 00:00:00 2001
From: Mike Breen
Date: Sun, 17 May 2009 19:48:15 +0200
Subject: Add tests for assert_template :template
Signed-off-by: Pratik Naik
---
.../test/controller/action_pack_assertions_test.rb | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 484d3c5ce7..c3c769919a 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -12,6 +12,9 @@ class ActionPackAssertionsController < ActionController::Base
# a standard template
def hello_xml_world() render :template => "test/hello_xml_world"; end
+ # a standard partial
+ def partial() render :partial => 'test/partial'; end
+
# a redirect to an internal location
def redirect_internal() redirect_to "/nothing"; end
@@ -331,6 +334,26 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
end
+ def test_assert_template_with_partial
+ get :partial
+ assert_template :partial => '_partial'
+ end
+
+ def test_assert_template_with_nil
+ get :nothing
+ assert_template nil
+ end
+
+ def test_assert_template_with_string
+ get :hello_world
+ assert_template 'hello_world'
+ end
+
+ def test_assert_template_with_symbol
+ get :hello_world
+ assert_template :hello_world
+ end
+
# check if we were rendered by a file-based template?
def test_rendered_action
process :nothing
--
cgit v1.2.3
From 092089015b79752c5e9d664b3eeefef9e2223e36 Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sun, 17 May 2009 13:39:44 -0500
Subject: Extract generic callbacks middleware from dispatcher
---
actionpack/test/controller/dispatcher_test.rb | 34 ++++++++++++++++-----------
1 file changed, 20 insertions(+), 14 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index b315232a7b..9fae1fcf63 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -6,20 +6,20 @@ class DispatcherTest < Test::Unit::TestCase
def setup
ENV['REQUEST_METHOD'] = 'GET'
- Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
- middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb"))
- middleware.instance_eval(File.read(middlewares))
- end
-
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
- Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
- Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
- Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ ActionDispatch::Callbacks.instance_variable_set("@prepare_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ ActionDispatch::Callbacks.instance_variable_set("@before_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ ActionDispatch::Callbacks.instance_variable_set("@after_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ @old_router, Dispatcher.router = Dispatcher.router, mock()
+ Dispatcher.router.stubs(:call).returns([200, {}, 'response'])
+ Dispatcher.router.stubs(:reload)
Dispatcher.stubs(:require_dependency)
end
def teardown
+ Dispatcher.router = @old_router
+ @dispatcher = nil
ENV.delete 'REQUEST_METHOD'
end
@@ -29,12 +29,12 @@ class DispatcherTest < Test::Unit::TestCase
end
def test_reloads_routes_before_dispatch_if_in_loading_mode
- ActionController::Routing::Routes.expects(:reload).once
+ Dispatcher.router.expects(:reload).once
dispatch(false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
- ActionController::Routing::Routes.expects(:reload).never
+ Dispatcher.router.expects(:reload).never
ActiveSupport::Dependencies.expects(:clear).never
dispatch
@@ -55,7 +55,7 @@ class DispatcherTest < Test::Unit::TestCase
assert_nil a || b || c
# Run callbacks
- Dispatcher.run_prepare_callbacks
+ dispatch
assert_equal 1, a
assert_equal 2, b
@@ -72,16 +72,22 @@ class DispatcherTest < Test::Unit::TestCase
Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 }
Dispatcher.to_prepare(:unique_id) { |*args| a = 2 }
- Dispatcher.run_prepare_callbacks
+ dispatch
assert_equal 2, a
assert_equal nil, b
end
private
def dispatch(cache_classes = true)
- ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
+ ActionController::Dispatcher.prepare_each_request = false
Dispatcher.define_dispatcher_callbacks(cache_classes)
- Dispatcher.new.call({'rack.input' => StringIO.new('')})
+ Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
+ middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb"))
+ middleware.instance_eval(File.read(middlewares))
+ end
+
+ @dispatcher ||= Dispatcher.new
+ @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false})
end
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
--
cgit v1.2.3
From 01d7acd11d631d980497870aad1af42a0c66115c Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sun, 17 May 2009 14:42:36 -0500
Subject: Fix reset_session with ActiveRecord store [#2200 state:resolved]
---
actionpack/test/activerecord/active_record_store_test.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb
index 663cd259c8..47f8496181 100644
--- a/actionpack/test/activerecord/active_record_store_test.rb
+++ b/actionpack/test/activerecord/active_record_store_test.rb
@@ -28,9 +28,9 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
end
def call_reset_session
- session[:bar]
+ session[:foo]
reset_session
- session[:bar] = "baz"
+ session[:foo] = "baz"
head :ok
end
@@ -91,7 +91,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
get '/get_session_value'
assert_response :success
- assert_equal 'foo: nil', response.body
+ assert_equal 'foo: "baz"', response.body
get '/get_session_id'
assert_response :success
--
cgit v1.2.3
From 195fadbfd31294d43634afb7bbf4f0ffc86b470a Mon Sep 17 00:00:00 2001
From: Pratik Naik
Date: Mon, 18 May 2009 16:59:37 +0200
Subject: Ensure HTTP Digest auth uses appropriate HTTP method [#2490
state:resolved] [Steve Madsen]
---
.../controller/http_digest_authentication_test.rb | 23 +++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb
index 7bebc8cd2a..b8a2205ce6 100644
--- a/actionpack/test/controller/http_digest_authentication_test.rb
+++ b/actionpack/test/controller/http_digest_authentication_test.rb
@@ -149,6 +149,16 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
assert_equal 'Definitely Maybe', @response.body
end
+ test "authentication request with _method" do
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :method => :post)
+ @request.env['rack.methodoverride.original_method'] = 'POST'
+ put :display
+
+ assert_response :success
+ assert assigns(:logged_in)
+ assert_equal 'Definitely Maybe', @response.body
+ end
+
private
def encode_credentials(options)
@@ -159,15 +169,22 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
# to prevent tampering of timestamp
ActionController::Base.session_options[:secret] = "session_options_secret"
- # Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
- get :index
+ # Perform unauthenticated request to retrieve digest parameters to use on subsequent request
+ method = options.delete(:method) || 'GET'
+
+ case method.to_s.upcase
+ when 'GET'
+ get :index
+ when 'POST'
+ post :index
+ end
assert_response :unauthorized
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
credentials.merge!(options)
credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
- ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
+ ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1])
end
def decode_credentials(header)
--
cgit v1.2.3
From 5e190ef138a034bf86419ce4f4c343ae16bfc77b Mon Sep 17 00:00:00 2001
From: Andy Stewart
Date: Wed, 28 Jan 2009 16:45:28 +0000
Subject: Truncate helper accepts a :separator for a more legible result [#1807
state:resolved]
Signed-off-by: Pratik Naik
---
actionpack/test/template/text_helper_test.rb | 3 +++
1 file changed, 3 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index a780bfc606..706b5085f4 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -49,6 +49,9 @@ class TextHelperTest < ActionView::TestCase
assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]")
assert_equal "Hello W...", truncate("Hello World!", :length => 10)
assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10)
+ assert_equal "Hello[...]", truncate("Hello Big World!", :omission => "[...]", :length => 13, :separator => ' ')
+ assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 14, :separator => ' ')
+ assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 15, :separator => ' ')
end
if RUBY_VERSION < '1.9.0'
--
cgit v1.2.3
From 07f733c6315980bde120c98c6b8a25e2773ee6bf Mon Sep 17 00:00:00 2001
From: Yehuda Katz + Carl Lerche
Date: Mon, 18 May 2009 16:15:43 -0700
Subject: Ported simple benchmarking in new base
---
actionpack/test/controller/logging_test.rb | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 1f3ff4ef52..75afa2d133 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -11,6 +11,11 @@ class LoggingTest < ActionController::TestCase
class MockLogger
attr_reader :logged
+ attr_accessor :level
+
+ def initialize
+ @level = Logger::DEBUG
+ end
def method_missing(method, *args)
@logged ||= []
--
cgit v1.2.3
From 4a6f4b92ad2f48dc7906d223fe4708d36624bd50 Mon Sep 17 00:00:00 2001
From: Pratik Naik
Date: Tue, 19 May 2009 23:48:05 +0200
Subject: Change integration test helpers to accept Rack environment instead of
just HTTP Headers.
Before : get '/path', {}, 'Accept' => 'text/javascript'
After : get '/path', {}, 'HTTP_ACCEPT' => 'text/javascript'
---
actionpack/test/controller/integration_test.rb | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index c616107324..a2b3ad2106 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -123,8 +123,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_get
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:get,path,params,headers_after_xhr)
@session.xml_http_request(:get,path,params,headers)
@@ -133,8 +133,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_post
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:post,path,params,headers_after_xhr)
@session.xml_http_request(:post,path,params,headers)
@@ -143,8 +143,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_put
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:put,path,params,headers_after_xhr)
@session.xml_http_request(:put,path,params,headers)
@@ -153,8 +153,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_delete
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:delete,path,params,headers_after_xhr)
@session.xml_http_request(:delete,path,params,headers)
@@ -163,17 +163,17 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_head
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:head,path,params,headers_after_xhr)
@session.xml_http_request(:head,path,params,headers)
end
def test_xml_http_request_override_accept
- path = "/index"; params = "blah"; headers = {:location => 'blah', "Accept" => "application/xml"}
+ path = "/index"; params = "blah"; headers = {:location => 'blah', "HTTP_ACCEPT" => "application/xml"}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"
)
@session.expects(:process).with(:post,path,params,headers_after_xhr)
@session.xml_http_request(:post,path,params,headers)
--
cgit v1.2.3
From d8fffe7b23acce42bc3941d7bba47e07a66aed67 Mon Sep 17 00:00:00 2001
From: Pratik Naik
Date: Wed, 20 May 2009 00:06:14 +0200
Subject: Replace ad hoc Rack::Test with ActionController::IntegrationTest
---
actionpack/test/new_base/test_helper.rb | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index ec7dbffaae..9401e692f1 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -20,8 +20,8 @@ require 'action_controller/abstract'
require 'action_controller/new_base'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
-require 'rubygems'
-require 'rack/test'
+require 'action_controller/testing/process'
+require 'action_controller/testing/integration'
module Rails
def self.env
@@ -32,9 +32,7 @@ module Rails
end
# Temporary base class
-class Rack::TestCase < ActiveSupport::TestCase
- include Rack::Test::Methods
-
+class Rack::TestCase < ActionController::IntegrationTest
setup do
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
@@ -82,7 +80,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_body(body)
- assert_equal body, Array.wrap(last_response.body).join
+ assert_equal body, Array.wrap(response.body).join
end
def self.assert_body(body)
@@ -92,7 +90,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_status(code)
- assert_equal code, last_response.status
+ assert_equal code, response.status
end
def self.assert_status(code)
@@ -110,7 +108,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_content_type(type)
- assert_equal type, last_response.headers["Content-Type"]
+ assert_equal type, response.headers["Content-Type"]
end
def self.assert_content_type(type)
@@ -120,7 +118,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_header(name, value)
- assert_equal value, last_response.headers[name]
+ assert_equal value, response.headers[name]
end
def self.assert_header(name, value)
--
cgit v1.2.3
From 0029d5e5943dd20d38485ac7127cc150659da9e5 Mon Sep 17 00:00:00 2001
From: Bryan Helmkamp
Date: Mon, 11 May 2009 23:04:39 -0400
Subject: Integrating Rack::MockSession (from Rack::Test)
---
actionpack/test/controller/integration_test.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index a2b3ad2106..eae6835714 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -253,7 +253,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
assert_response 200
assert_response :success
assert_response :ok
- assert_equal({}, cookies)
+ assert_equal({}, cookies.to_hash)
assert_equal "OK", body
assert_equal "OK", response.body
assert_kind_of HTML::Document, html_document
@@ -269,7 +269,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
assert_response 201
assert_response :success
assert_response :created
- assert_equal({}, cookies)
+ assert_equal({}, cookies.to_hash)
assert_equal "Created", body
assert_equal "Created", response.body
assert_kind_of HTML::Document, html_document
@@ -287,7 +287,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
assert_response 410
assert_response :gone
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
- assert_equal({"cookie_1"=>nil, "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
+ assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies.to_hash)
assert_equal "Gone", response.body
end
end
--
cgit v1.2.3
From c03b0ca7eb7e73587005e1440bf90cd01ed10aa5 Mon Sep 17 00:00:00 2001
From: Pratik Naik
Date: Wed, 20 May 2009 21:15:06 +0200
Subject: Replace the class level Rack::Test DSL with the regular integration
tests DSL
---
actionpack/test/new_base/base_test.rb | 80 ++---
actionpack/test/new_base/content_type_test.rb | 120 +++----
actionpack/test/new_base/etag_test.rb | 23 +-
actionpack/test/new_base/render_action_test.rb | 388 ++++++++++-----------
.../test/new_base/render_implicit_action_test.rb | 28 +-
actionpack/test/new_base/render_layout_test.rb | 64 ++--
actionpack/test/new_base/render_template_test.rb | 87 +++--
actionpack/test/new_base/render_test.rb | 45 ++-
actionpack/test/new_base/render_text_test.rb | 151 ++++----
actionpack/test/new_base/test_helper.rb | 55 +--
10 files changed, 477 insertions(+), 564 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb
index a32653f128..d9d552f9e5 100644
--- a/actionpack/test/new_base/base_test.rb
+++ b/actionpack/test/new_base/base_test.rb
@@ -10,78 +10,60 @@ module Dispatching
def modify_response_body
self.response_body = "success"
end
-
+
def modify_response_body_twice
ret = (self.response_body = "success")
self.response_body = "#{ret}!"
end
-
+
def modify_response_headers
-
end
end
-
- class TestSimpleDispatch < SimpleRouteCase
-
- get "/dispatching/simple/index"
-
- test "sets the body" do
+
+ class EmptyController < ActionController::Base ; end
+
+ module Submodule
+ class ContainedEmptyController < ActionController::Base ; end
+ end
+
+ class BaseTest < SimpleRouteCase
+ # :api: plugin
+ test "simple dispatching" do
+ get "/dispatching/simple/index"
+
assert_body "success"
- end
-
- test "sets the status code" do
assert_status 200
- end
-
- test "sets the content type" do
assert_content_type "text/html; charset=utf-8"
- end
-
- test "sets the content length" do
assert_header "Content-Length", "7"
end
-
- end
-
- # :api: plugin
- class TestDirectResponseMod < SimpleRouteCase
- get "/dispatching/simple/modify_response_body"
-
- test "sets the body" do
+
+ # :api: plugin
+ test "directly modifying response body" do
+ get "/dispatching/simple/modify_response_body"
+
assert_body "success"
+ assert_header "Content-Length", "7" # setting the body manually sets the content length
end
-
- test "setting the body manually sets the content length" do
- assert_header "Content-Length", "7"
- end
- end
-
- # :api: plugin
- class TestDirectResponseModTwice < SimpleRouteCase
- get "/dispatching/simple/modify_response_body_twice"
-
- test "self.response_body= returns the body being set" do
+
+ # :api: plugin
+ test "directly modifying response body twice" do
+ get "/dispatching/simple/modify_response_body_twice"
+
assert_body "success!"
- end
-
- test "updating the response body updates the content length" do
assert_header "Content-Length", "8"
end
- end
-
- class EmptyController < ActionController::Base ; end
- module Submodule
- class ContainedEmptyController < ActionController::Base ; end
- end
- class ControllerClassTests < Test::Unit::TestCase
- def test_controller_path
+ test "controller path" do
assert_equal 'dispatching/empty', EmptyController.controller_path
assert_equal EmptyController.controller_path, EmptyController.new.controller_path
+ end
+
+ test "namespaced controller path" do
assert_equal 'dispatching/submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
end
- def test_controller_name
+
+ test "controller name" do
assert_equal 'empty', EmptyController.controller_name
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
end
diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb
index a5c04e9cb6..82b817a5a3 100644
--- a/actionpack/test/new_base/content_type_test.rb
+++ b/actionpack/test/new_base/content_type_test.rb
@@ -5,107 +5,107 @@ module ContentType
def index
render :text => "Hello world!"
end
-
+
def set_on_response_obj
response.content_type = Mime::RSS
render :text => "Hello world!"
end
-
+
def set_on_render
render :text => "Hello world!", :content_type => Mime::RSS
end
end
-
- class TestDefault < SimpleRouteCase
- describe "a default response is HTML and UTF8"
-
- get "/content_type/base"
- assert_body "Hello world!"
- assert_header "Content-Type", "text/html; charset=utf-8"
- end
-
- class TestSetOnResponseObj < SimpleRouteCase
- describe "setting the content type of the response directly on the response object"
-
- get "/content_type/base/set_on_response_obj"
- assert_body "Hello world!"
- assert_header "Content-Type", "application/rss+xml; charset=utf-8"
- end
-
- class TestSetOnRender < SimpleRouteCase
- describe "setting the content type of the response as an option to render"
-
- get "/content_type/base/set_on_render"
- assert_body "Hello world!"
- assert_header "Content-Type", "application/rss+xml; charset=utf-8"
- end
-
+
class ImpliedController < ActionController::Base
+ # Template's mime type is used if no content_type is specified
+
self.view_paths = [ActionView::Template::FixturePath.new(
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
"content_type/implied/i_am_xml_erb.xml.erb" => "Hello world!",
"content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'",
"content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'"
)]
-
+
def i_am_html_erb() end
def i_am_xml_erb() end
def i_am_html_builder() end
def i_am_xml_builder() end
end
-
- class TestImpliedController < SimpleRouteCase
- describe "the template's mime type is used if no content_type is specified"
-
+
+ class CharsetController < ActionController::Base
+ def set_on_response_obj
+ response.charset = "utf-16"
+ render :text => "Hello world!"
+ end
+
+ def set_as_nil_on_response_obj
+ response.charset = nil
+ render :text => "Hello world!"
+ end
+ end
+
+ class ExplicitContentTypeTest < SimpleRouteCase
+ test "default response is HTML and UTF8" do
+ get "/content_type/base"
+
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-8"
+ end
+
+ test "setting the content type of the response directly on the response object" do
+ get "/content_type/base/set_on_response_obj"
+
+ assert_body "Hello world!"
+ assert_header "Content-Type", "application/rss+xml; charset=utf-8"
+ end
+
+ test "setting the content type of the response as an option to render" do
+ get "/content_type/base/set_on_render"
+
+ assert_body "Hello world!"
+ assert_header "Content-Type", "application/rss+xml; charset=utf-8"
+ end
+ end
+
+ class ImpliedContentTypeTest < SimpleRouteCase
test "sets Content-Type as text/html when rendering *.html.erb" do
get "/content_type/implied/i_am_html_erb"
+
assert_header "Content-Type", "text/html; charset=utf-8"
end
test "sets Content-Type as application/xml when rendering *.xml.erb" do
get "/content_type/implied/i_am_xml_erb"
+
assert_header "Content-Type", "application/xml; charset=utf-8"
end
test "sets Content-Type as text/html when rendering *.html.builder" do
get "/content_type/implied/i_am_html_builder"
+
assert_header "Content-Type", "text/html; charset=utf-8"
end
test "sets Content-Type as application/xml when rendering *.xml.builder" do
get "/content_type/implied/i_am_xml_builder"
+
assert_header "Content-Type", "application/xml; charset=utf-8"
end
-
end
-end
-module Charset
- class BaseController < ActionController::Base
- def set_on_response_obj
- response.charset = "utf-16"
- render :text => "Hello world!"
+ class ExplicitCharsetTest < SimpleRouteCase
+ test "setting the charset of the response directly on the response object" do
+ get "/content_type/charset/set_on_response_obj"
+
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-16"
end
-
- def set_as_nil_on_response_obj
- response.charset = nil
- render :text => "Hello world!"
+
+ test "setting the charset of the response as nil directly on the response object" do
+ get "/content_type/charset/set_as_nil_on_response_obj"
+
+ assert_body "Hello world!"
+ assert_header "Content-Type", "text/html; charset=utf-8"
end
end
-
- class TestSetOnResponseObj < SimpleRouteCase
- describe "setting the charset of the response directly on the response object"
-
- get "/charset/base/set_on_response_obj"
- assert_body "Hello world!"
- assert_header "Content-Type", "text/html; charset=utf-16"
- end
-
- class TestSetAsNilOnResponseObj < SimpleRouteCase
- describe "setting the charset of the response as nil directly on the response object"
-
- get "/charset/base/set_as_nil_on_response_obj"
- assert_body "Hello world!"
- assert_header "Content-Type", "text/html; charset=utf-8"
- end
-end
\ No newline at end of file
+end
diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb
index 7af5febfb3..c77636bb64 100644
--- a/actionpack/test/new_base/etag_test.rb
+++ b/actionpack/test/new_base/etag_test.rb
@@ -1,47 +1,46 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module Etags
-
class BasicController < ActionController::Base
-
self.view_paths = [ActionView::Template::FixturePath.new(
"etags/basic/base.html.erb" => "Hello from without_layout.html.erb",
"layouts/etags.html.erb" => "teh <%= yield %> tagz"
)]
-
+
def without_layout
render :action => "base"
end
-
+
def with_layout
render :action => "base", :layout => "etag"
end
-
end
-
- class TestBasic < SimpleRouteCase
+
+ class EtagTest < SimpleRouteCase
describe "Rendering without any special etag options returns an etag that is an MD5 hash of its text"
-
+
test "an action without a layout" do
get "/etags/basic/without_layout"
+
body = "Hello from without_layout.html.erb"
assert_body body
assert_header "Etag", etag_for(body)
assert_status 200
end
-
+
test "an action with a layout" do
get "/etags/basic/with_layout"
+
body = "teh Hello from without_layout.html.erb tagz"
assert_body body
assert_header "Etag", etag_for(body)
assert_status 200
end
-
+
+ private
+
def etag_for(text)
%("#{Digest::MD5.hexdigest(text)}")
end
end
-
-
end
\ No newline at end of file
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index 626c7b3540..4402eadf42 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -1,26 +1,24 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module RenderAction
-
# This has no layout and it works
class BasicController < ActionController::Base
-
self.view_paths = [ActionView::Template::FixturePath.new(
"render_action/basic/hello_world.html.erb" => "Hello world!"
)]
-
+
def hello_world
render :action => "hello_world"
end
-
+
def hello_world_as_string
render "hello_world"
end
-
+
def hello_world_as_string_with_options
render "hello_world", :status => 404
end
-
+
def hello_world_as_symbol
render :hello_world
end
@@ -28,107 +26,95 @@ module RenderAction
def hello_world_with_symbol
render :action => :hello_world
end
-
+
def hello_world_with_layout
render :action => "hello_world", :layout => true
end
-
+
def hello_world_with_layout_false
render :action => "hello_world", :layout => false
end
-
+
def hello_world_with_layout_nil
render :action => "hello_world", :layout => nil
end
-
+
def hello_world_with_custom_layout
render :action => "hello_world", :layout => "greetings"
end
-
- end
-
- class TestBasic < SimpleRouteCase
- describe "Rendering an action using :action => "
-
- get "/render_action/basic/hello_world"
- assert_body "Hello world!"
- assert_status 200
- end
-
- class TestWithString < SimpleRouteCase
- describe "Render an action using 'hello_world'"
-
- get "/render_action/basic/hello_world_as_string"
- assert_body "Hello world!"
- assert_status 200
- end
-
- class TestWithStringAndOptions < SimpleRouteCase
- describe "Render an action using 'hello_world'"
-
- get "/render_action/basic/hello_world_as_string_with_options"
- assert_body "Hello world!"
- assert_status 404
- end
-
- class TestAsSymbol < SimpleRouteCase
- describe "Render an action using :hello_world"
-
- get "/render_action/basic/hello_world_as_symbol"
- assert_body "Hello world!"
- assert_status 200
+
end
-
- class TestWithSymbol < SimpleRouteCase
- describe "Render an action using :action => :hello_world"
-
- get "/render_action/basic/hello_world_with_symbol"
- assert_body "Hello world!"
- assert_status 200
+
+ class RenderActionTest < SimpleRouteCase
+ test "rendering an action using :action => " do
+ get "/render_action/basic/hello_world"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering an action using ''" do
+ get "/render_action/basic/hello_world_as_string"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering an action using '' and options" do
+ get "/render_action/basic/hello_world_as_string_with_options"
+
+ assert_body "Hello world!"
+ assert_status 404
+ end
+
+ test "rendering an action using :action" do
+ get "/render_action/basic/hello_world_as_symbol"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering an action using :action => :hello_world" do
+ get "/render_action/basic/hello_world_with_symbol"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
end
-
- class TestLayoutTrue < SimpleRouteCase
- describe "rendering a normal template with full path with layout => true"
-
- test "raises an exception when requesting a layout and none exist" do
- assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do
+
+ class RenderLayoutTest < SimpleRouteCase
+ describe "Both .html.erb and application.html.erb are missing"
+
+ test "rendering with layout => true" do
+ assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do
get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false
end
end
- end
-
- class TestLayoutFalse < SimpleRouteCase
- describe "rendering a normal template with full path with layout => false"
-
- get "/render_action/basic/hello_world_with_layout_false"
- assert_body "Hello world!"
- assert_status 200
- end
-
- class TestLayoutNil < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :nil"
-
- get "/render_action/basic/hello_world_with_layout_nil"
- assert_body "Hello world!"
- assert_status 200
- end
-
- class TestCustomLayout < SimpleRouteCase
- describe "rendering a normal template with full path with layout => 'greetings'"
-
- test "raises an exception when requesting a layout that does not exist" do
+
+ test "rendering with layout => false" do
+ get "/render_action/basic/hello_world_with_layout_false"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :nil" do
+ get "/render_action/basic/hello_world_with_layout_nil"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering with layout => 'greetings'" do
assert_raise(ActionView::MissingTemplate) do
get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false
end
end
end
-
end
module RenderActionWithApplicationLayout
-
# # ==== Render actions with layouts ====
-
class BasicController < ::ApplicationController
# Set the view path to an application view structure with layouts
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
@@ -138,205 +124,197 @@ module RenderActionWithApplicationLayout
"layouts/greetings.html.erb" => "Greetings <%= yield %> Bai",
"layouts/builder.html.builder" => "xml.html do\n xml << yield\nend"
)]
-
+
def hello_world
render :action => "hello_world"
end
-
+
def hello_world_with_layout
render :action => "hello_world", :layout => true
end
-
+
def hello_world_with_layout_false
render :action => "hello_world", :layout => false
end
-
+
def hello_world_with_layout_nil
render :action => "hello_world", :layout => nil
end
-
+
def hello_world_with_custom_layout
render :action => "hello_world", :layout => "greetings"
end
-
+
def with_builder_and_layout
render :action => "hello", :layout => "builder"
end
end
-
- class TestDefaultLayout < SimpleRouteCase
- describe %(
- Render hello_world and implicitly use application.html.erb as a layout if
- no layout is specified and no controller layout is present
- )
-
- get "/render_action_with_application_layout/basic/hello_world"
- assert_body "OHAI Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutTrue < SimpleRouteCase
- describe "rendering a normal template with full path with layout => true"
-
- get "/render_action_with_application_layout/basic/hello_world_with_layout"
- assert_body "OHAI Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutFalse < SimpleRouteCase
- describe "rendering a normal template with full path with layout => false"
-
- get "/render_action_with_application_layout/basic/hello_world_with_layout_false"
- assert_body "Hello World!"
- assert_status 200
- end
-
- class TestLayoutNil < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :nil"
-
- get "/render_action_with_application_layout/basic/hello_world_with_layout_nil"
- assert_body "Hello World!"
- assert_status 200
- end
-
- class TestCustomLayout < SimpleRouteCase
- describe "rendering a normal template with full path with layout => 'greetings'"
-
- get "/render_action_with_application_layout/basic/hello_world_with_custom_layout"
- assert_body "Greetings Hello World! Bai"
- assert_status 200
+
+ class LayoutTest < SimpleRouteCase
+ describe "Only application.html.erb is present and .html.erb is missing"
+
+ test "rendering implicit application.html.erb as layout" do
+ get "/render_action_with_application_layout/basic/hello_world"
+
+ assert_body "OHAI Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => true" do
+ get "/render_action_with_application_layout/basic/hello_world_with_layout"
+
+ assert_body "OHAI Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => false" do
+ get "/render_action_with_application_layout/basic/hello_world_with_layout_false"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :nil" do
+ get "/render_action_with_application_layout/basic/hello_world_with_layout_nil"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
+
+ test "rendering with layout => 'greetings'" do
+ get "/render_action_with_application_layout/basic/hello_world_with_custom_layout"
+
+ assert_body "Greetings Hello World! Bai"
+ assert_status 200
+ end
end
-
+
class TestLayout < SimpleRouteCase
testing BasicController
-
+
test "builder works with layouts" do
get :with_builder_and_layout
assert_response "\n
Omg
\n\n"
end
end
-
+
end
module RenderActionWithControllerLayout
-
class BasicController < ActionController::Base
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
)]
-
+
def hello_world
render :action => "hello_world"
end
-
+
def hello_world_with_layout
render :action => "hello_world", :layout => true
end
-
+
def hello_world_with_layout_false
render :action => "hello_world", :layout => false
end
-
+
def hello_world_with_layout_nil
render :action => "hello_world", :layout => nil
end
-
+
def hello_world_with_custom_layout
render :action => "hello_world", :layout => "greetings"
end
end
-
- class TestControllerLayout < SimpleRouteCase
- describe "Render hello_world and implicitly use .html.erb as a layout."
- get "/render_action_with_controller_layout/basic/hello_world"
- assert_body "With Controller Layout! Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutTrue < SimpleRouteCase
- describe "rendering a normal template with full path with layout => true"
-
- get "/render_action_with_controller_layout/basic/hello_world_with_layout"
- assert_body "With Controller Layout! Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutFalse < SimpleRouteCase
- describe "rendering a normal template with full path with layout => false"
-
- get "/render_action_with_controller_layout/basic/hello_world_with_layout_false"
- assert_body "Hello World!"
- assert_status 200
- end
-
- class TestLayoutNil < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :nil"
-
- get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil"
- assert_body "Hello World!"
- assert_status 200
+ class ControllerLayoutTest < SimpleRouteCase
+ describe "Only .html.erb is present and application.html.erb is missing"
+
+ test "render hello_world and implicitly use .html.erb as a layout." do
+ get "/render_action_with_controller_layout/basic/hello_world"
+
+ assert_body "With Controller Layout! Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => true" do
+ get "/render_action_with_controller_layout/basic/hello_world_with_layout"
+
+ assert_body "With Controller Layout! Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => false" do
+ get "/render_action_with_controller_layout/basic/hello_world_with_layout_false"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :nil" do
+ get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
end
-
end
module RenderActionWithBothLayouts
-
class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new({
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
"layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
})]
-
+
def hello_world
render :action => "hello_world"
end
-
+
def hello_world_with_layout
render :action => "hello_world", :layout => true
end
-
+
def hello_world_with_layout_false
render :action => "hello_world", :layout => false
end
-
+
def hello_world_with_layout_nil
render :action => "hello_world", :layout => nil
end
end
-
- class TestControllerLayoutFirst < SimpleRouteCase
- describe "Render hello_world and implicitly use .html.erb over application.html.erb as a layout"
- get "/render_action_with_both_layouts/basic/hello_world"
- assert_body "With Controller Layout! Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutTrue < SimpleRouteCase
- describe "rendering a normal template with full path with layout => true"
-
- get "/render_action_with_both_layouts/basic/hello_world_with_layout"
- assert_body "With Controller Layout! Hello World! KTHXBAI"
- assert_status 200
- end
-
- class TestLayoutFalse < SimpleRouteCase
- describe "rendering a normal template with full path with layout => false"
-
- get "/render_action_with_both_layouts/basic/hello_world_with_layout_false"
- assert_body "Hello World!"
- assert_status 200
- end
-
- class TestLayoutNil < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :nil"
-
- get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil"
- assert_body "Hello World!"
- assert_status 200
+ class ControllerLayoutTest < SimpleRouteCase
+ describe "Both .html.erb and application.html.erb are present"
+
+ test "rendering implicitly use .html.erb over application.html.erb as a layout" do
+ get "/render_action_with_both_layouts/basic/hello_world"
+
+ assert_body "With Controller Layout! Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => true" do
+ get "/render_action_with_both_layouts/basic/hello_world_with_layout"
+
+ assert_body "With Controller Layout! Hello World! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering with layout => false" do
+ get "/render_action_with_both_layouts/basic/hello_world_with_layout_false"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :nil" do
+ get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil"
+
+ assert_body "Hello World!"
+ assert_status 200
+ end
end
-
end
\ No newline at end of file
diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb
index 58f5cec181..2846df48da 100644
--- a/actionpack/test/new_base/render_implicit_action_test.rb
+++ b/actionpack/test/new_base/render_implicit_action_test.rb
@@ -10,19 +10,19 @@ module RenderImplicitAction
def hello_world() end
end
- class TestImplicitRender < SimpleRouteCase
- describe "render a simple action with new explicit call to render"
-
- get "/render_implicit_action/simple/hello_world"
- assert_body "Hello world!"
- assert_status 200
- end
-
- class TestImplicitWithSpecialCharactersRender < SimpleRouteCase
- describe "render an action with a missing method and has special characters"
-
- get "/render_implicit_action/simple/hyphen-ated"
- assert_body "Hello hyphen-ated!"
- assert_status 200
+ class RenderImplicitActionTest < SimpleRouteCase
+ test "render a simple action with new explicit call to render" do
+ get "/render_implicit_action/simple/hello_world"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "render an action with a missing method and has special characters" do
+ get "/render_implicit_action/simple/hyphen-ated"
+
+ assert_body "Hello hyphen-ated!"
+ assert_status 200
+ end
end
end
\ No newline at end of file
diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb
index dc858b4f5c..76bd5175a3 100644
--- a/actionpack/test/new_base/render_layout_test.rb
+++ b/actionpack/test/new_base/render_layout_test.rb
@@ -2,69 +2,65 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module ControllerLayouts
class ImplicitController < ::ApplicationController
-
self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
"layouts/override.html.erb" => "Override! <%= yield %>",
"basic.html.erb" => "Hello world!",
"controller_layouts/implicit/layout_false.html.erb" => "hai(layout_false.html.erb)"
)]
-
+
def index
render :template => "basic"
end
-
+
def override
render :template => "basic", :layout => "override"
end
-
+
def layout_false
render :layout => false
end
-
+
def builder_override
-
end
end
-
- class TestImplicitLayout < SimpleRouteCase
- describe "rendering a normal template, but using the implicit layout"
-
- get "/controller_layouts/implicit/index"
- assert_body "OMG Hello world! KTHXBAI"
- assert_status 200
- end
-
+
class ImplicitNameController < ::ApplicationController
-
self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI",
"basic.html.erb" => "Hello world!"
)]
-
+
def index
render :template => "basic"
end
end
-
- class TestImplicitNamedLayout < SimpleRouteCase
- describe "rendering a normal template, but using an implicit NAMED layout"
-
- get "/controller_layouts/implicit_name/index"
- assert_body "OMGIMPLICIT Hello world! KTHXBAI"
- assert_status 200
- end
-
- class TestOverridingImplicitLayout < SimpleRouteCase
- describe "overriding an implicit layout with render :layout option"
-
- get "/controller_layouts/implicit/override"
- assert_body "Override! Hello world!"
+
+ class RenderLayoutTest < SimpleRouteCase
+ test "rendering a normal template, but using the implicit layout" do
+ get "/controller_layouts/implicit/index"
+
+ assert_body "OMG Hello world! KTHXBAI"
+ assert_status 200
+ end
+
+ test "rendering a normal template, but using an implicit NAMED layout" do
+ get "/controller_layouts/implicit_name/index"
+
+ assert_body "OMGIMPLICIT Hello world! KTHXBAI"
+ assert_status 200
+ end
+
+ test "overriding an implicit layout with render :layout option" do
+ get "/controller_layouts/implicit/override"
+ assert_body "Override! Hello world!"
+ end
+
end
-
- class TestLayoutOptions < SimpleRouteCase
+
+ class LayoutOptionsTest < SimpleRouteCase
testing ControllerLayouts::ImplicitController
-
+
test "rendering with :layout => false leaves out the implicit layout" do
get :layout_false
assert_response "hai(layout_false.html.erb)"
diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb
index 6c50ae4203..face5b7571 100644
--- a/actionpack/test/new_base/render_template_test.rb
+++ b/actionpack/test/new_base/render_template_test.rb
@@ -79,7 +79,6 @@ module RenderTemplate
end
class WithLayoutController < ::ApplicationController
-
self.view_paths = [ActionView::Template::FixturePath.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica",
@@ -108,46 +107,45 @@ module RenderTemplate
end
end
- class TestTemplateRenderWithLayout < SimpleRouteCase
- describe "rendering a normal template with full path with layout"
-
- get "/render_template/with_layout"
- assert_body "Hello from basic.html.erb, I'm here!"
- assert_status 200
- end
-
- class TestTemplateRenderWithLayoutTrue < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :true"
-
- get "/render_template/with_layout/with_layout"
- assert_body "Hello from basic.html.erb, I'm here!"
- assert_status 200
- end
-
- class TestTemplateRenderWithLayoutFalse < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :false"
-
- get "/render_template/with_layout/with_layout_false"
- assert_body "Hello from basic.html.erb"
- assert_status 200
- end
-
- class TestTemplateRenderWithLayoutNil < SimpleRouteCase
- describe "rendering a normal template with full path with layout => :nil"
-
- get "/render_template/with_layout/with_layout_nil"
- assert_body "Hello from basic.html.erb"
- assert_status 200
- end
-
- class TestTemplateRenderWithCustomLayout < SimpleRouteCase
- describe "rendering a normal template with full path with layout => 'greetings'"
-
- get "/render_template/with_layout/with_custom_layout"
- assert_body "Hello from basic.html.erb, I wish thee well."
- assert_status 200
+ class TestWithLayout < SimpleRouteCase
+ describe "Rendering with :template using implicit or explicit layout"
+
+ test "rendering with implicit layout" do
+ get "/render_template/with_layout"
+
+ assert_body "Hello from basic.html.erb, I'm here!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :true" do
+ get "/render_template/with_layout/with_layout"
+
+ assert_body "Hello from basic.html.erb, I'm here!"
+ assert_status 200
+ end
+
+ test "rendering with layout => :false" do
+ get "/render_template/with_layout/with_layout_false"
+
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+
+ test "rendering with layout => :nil" do
+ get "/render_template/with_layout/with_layout_nil"
+
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+
+ test "rendering layout => 'greetings'" do
+ get "/render_template/with_layout/with_custom_layout"
+
+ assert_body "Hello from basic.html.erb, I wish thee well."
+ assert_status 200
+ end
end
-
+
module Compatibility
class WithoutLayoutController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new(
@@ -161,11 +159,12 @@ module RenderTemplate
end
class TestTemplateRenderWithForwardSlash < SimpleRouteCase
- describe "rendering a normal template with full path starting with a leading slash"
+ test "rendering a normal template with full path starting with a leading slash" do
+ get "/render_template/compatibility/without_layout/with_forward_slash"
- get "/render_template/compatibility/without_layout/with_forward_slash"
- assert_body "Hello from basic.html.erb"
- assert_status 200
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
end
end
end
\ No newline at end of file
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
index ef5e7d89c5..ed3d50fa0b 100644
--- a/actionpack/test/new_base/render_test.rb
+++ b/actionpack/test/new_base/render_test.rb
@@ -8,60 +8,57 @@ module Render
"render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>",
"render/blank_render/access_controller_name.html.erb" => "Controller Name: <%= controller_name %>"
)]
-
+
def index
render
end
-
+
def access_request
render :action => "access_request"
end
-
+
def render_action_name
render :action => "access_action_name"
end
-
- private
-
+
+ private
+
def secretz
render :text => "FAIL WHALE!"
end
end
-
- class TestBlankRender < SimpleRouteCase
- describe "Render with blank"
- get "/render/blank_render"
- assert_body "Hello world!"
- assert_status 200
- end
-
class DoubleRenderController < ActionController::Base
def index
render :text => "hello"
render :text => "world"
end
end
-
- class TestBasic < SimpleRouteCase
- describe "Rendering more than once"
-
- test "raises an exception" do
+
+ class RenderTest < SimpleRouteCase
+ test "render with blank" do
+ get "/render/blank_render"
+
+ assert_body "Hello world!"
+ assert_status 200
+ end
+
+ test "rendering more than once raises an exception" do
assert_raises(AbstractController::DoubleRenderError) do
get "/render/double_render", {}, "action_dispatch.show_exceptions" => false
end
end
end
-
+
class TestOnlyRenderPublicActions < SimpleRouteCase
describe "Only public methods on actual controllers are callable actions"
-
+
test "raises an exception when a method of Object is called" do
assert_raises(AbstractController::ActionNotFound) do
get "/render/blank_render/clone", {}, "action_dispatch.show_exceptions" => false
end
end
-
+
test "raises an exception when a private method is called" do
assert_raises(AbstractController::ActionNotFound) do
get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false
@@ -74,12 +71,12 @@ module Render
get "/render/blank_render/access_request"
assert_body "The request: GET"
end
-
+
test "The action_name is accessible in the view" do
get "/render/blank_render/render_action_name"
assert_body "Action Name: render_action_name"
end
-
+
test "The controller_name is accessible in the view" do
get "/render/blank_render/access_controller_name"
assert_body "Controller Name: blank_render"
diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb
index 39f2f7abbf..69594e4b64 100644
--- a/actionpack/test/new_base/render_text_test.rb
+++ b/actionpack/test/new_base/render_text_test.rb
@@ -11,15 +11,7 @@ module RenderText
render :text => "hello david"
end
end
-
- 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
self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
@@ -73,76 +65,77 @@ module RenderText
end
end
- class TestSimpleTextRenderWithLayout < SimpleRouteCase
- describe "Rendering text from a action with default options renders the text without the layout"
-
- get "/render_text/with_layout"
- assert_body "hello david"
- assert_status 200
- end
-
- class TestTextRenderWithStatus < SimpleRouteCase
- describe "Rendering text, while also providing a custom status code"
-
- get "/render_text/with_layout/custom_code"
- assert_body "hello world"
- assert_status 404
- end
-
- class TestTextRenderWithNil < SimpleRouteCase
- describe "Rendering text with nil returns a single space character"
-
- get "/render_text/with_layout/with_nil"
- 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"
-
- get "/render_text/with_layout/with_nil_and_status"
- assert_body " "
- assert_status 403
- end
-
- class TestTextRenderWithFalse < SimpleRouteCase
- describe "Rendering text with false returns the string 'false'"
-
- get "/render_text/with_layout/with_false"
- assert_body "false"
- assert_status 200
- end
-
- class TestTextRenderWithLayoutTrue < SimpleRouteCase
- describe "Rendering text with :layout => true"
-
- get "/render_text/with_layout/with_layout_true"
- assert_body "hello world, I'm here!"
- assert_status 200
- end
-
- class TestTextRenderWithCustomLayout < SimpleRouteCase
- describe "Rendering text with :layout => 'greetings'"
-
- get "/render_text/with_layout/with_custom_layout"
- assert_body "hello world, I wish thee well."
- assert_status 200
- end
-
- class TestTextRenderWithLayoutFalse < SimpleRouteCase
- describe "Rendering text with :layout => false"
-
- get "/render_text/with_layout/with_layout_false"
- assert_body "hello world"
- assert_status 200
- end
-
- class TestTextRenderWithLayoutNil < SimpleRouteCase
- describe "Rendering text with :layout => nil"
-
- get "/render_text/with_layout/with_layout_nil"
- assert_body "hello world"
- assert_status 200
+ class RenderTextTest < SimpleRouteCase
+ describe "Rendering text using render :text"
+
+ test "rendering text from a action with default options renders the text with the layout" do
+ get "/render_text/simple"
+ assert_body "hello david"
+ assert_status 200
+ end
+
+ test "rendering text from a action with default options renders the text without the layout" do
+ get "/render_text/with_layout"
+
+ assert_body "hello david"
+ assert_status 200
+ 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
+
+ test "rendering text with nil returns a single space character" do
+ get "/render_text/with_layout/with_nil"
+
+ assert_body " "
+ assert_status 200
+ end
+
+ test "Rendering text with nil and custom status code returns a single space character with the status" do
+ 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
end
end
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index 9401e692f1..89c1290063 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -36,13 +36,13 @@ class Rack::TestCase < ActionController::IntegrationTest
setup do
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
-
+
controllers = ActionController::Base.subclasses.map do |k|
k.underscore.sub(/_controller$/, '')
end
-
+
ActionController::Routing.use_controllers!(controllers)
-
+
# Move into a bootloader
ActionController::Base.subclasses.each do |klass|
klass = klass.constantize
@@ -50,13 +50,13 @@ class Rack::TestCase < ActionController::IntegrationTest
klass.class_eval do
_write_layout_method
end
- end
+ end
end
-
+
def app
@app ||= ActionController::Dispatcher.new
end
-
+
def self.testing(klass = nil)
if klass
@testing = "/#{klass.name.underscore}".sub!(/_controller$/, '')
@@ -64,13 +64,7 @@ class Rack::TestCase < ActionController::IntegrationTest
@testing
end
end
-
- def self.get(url)
- setup do |test|
- test.get url
- end
- end
-
+
def get(thing, *args)
if thing.is_a?(Symbol)
super("#{self.class.testing}/#{thing}")
@@ -78,27 +72,15 @@ class Rack::TestCase < ActionController::IntegrationTest
super
end
end
-
+
def assert_body(body)
assert_equal body, Array.wrap(response.body).join
end
-
- def self.assert_body(body)
- test "body is set to '#{body}'" do
- assert_body body
- end
- end
-
+
def assert_status(code)
assert_equal code, response.status
end
-
- def self.assert_status(code)
- test "status code is set to #{code}" do
- assert_status code
- end
- end
-
+
def assert_response(body, status = 200, headers = {})
assert_body body
assert_status status
@@ -106,27 +88,14 @@ class Rack::TestCase < ActionController::IntegrationTest
assert_header header, value
end
end
-
+
def assert_content_type(type)
assert_equal type, response.headers["Content-Type"]
end
-
- def self.assert_content_type(type)
- test "content type is set to #{type}" do
- assert_content_type(type)
- end
- end
-
+
def assert_header(name, value)
assert_equal value, response.headers[name]
end
-
- def self.assert_header(name, value)
- test "'#{name}' header is set to #{value.inspect}" do
- assert_header(name, value)
- end
- end
-
end
class ::ApplicationController < ActionController::Base
--
cgit v1.2.3
From 01f032f256f96f65e154061b582fbb4b32e4a692 Mon Sep 17 00:00:00 2001
From: Yehuda Katz + Carl Lerche
Date: Wed, 20 May 2009 15:33:08 -0700
Subject: Added responds_to to new base.
---
actionpack/test/controller/caching_test.rb | 2 ++
actionpack/test/controller/mime_responds_test.rb | 24 +++++++++++++++---------
2 files changed, 17 insertions(+), 9 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 560c09509b..c286976315 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -48,6 +48,8 @@ class PageCachingTest < ActionController::TestCase
super
ActionController::Base.perform_caching = true
+ ActionController::Routing::Routes.clear!
+
ActionController::Routing::Routes.draw do |map|
map.main '', :controller => 'posts'
map.formatted_posts 'posts.:format', :controller => 'posts'
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 7cd5145a2f..3b8babb84c 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -437,7 +437,7 @@ class MimeControllerTest < ActionController::TestCase
@controller.instance_eval do
def render(*args)
unless args.empty?
- @action = args.first[:action]
+ @action = args.first[:action] || action_name
end
response.body = "#{@action} - #{@template.formats}"
end
@@ -490,14 +490,15 @@ class PostController < AbstractPostController
end
end
- protected
- def with_iphone
- Mime::Type.register_alias("text/html", :iphone)
- request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
- yield
- ensure
- Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
- end
+protected
+
+ def with_iphone
+ Mime::Type.register_alias("text/html", :iphone)
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
+ yield
+ ensure
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
+ end
end
class SuperPostController < PostController
@@ -509,6 +510,11 @@ class SuperPostController < PostController
end
end
+if ENV["new_base"]
+ PostController._write_layout_method
+ SuperPostController._write_layout_method
+end
+
class MimeControllerLayoutsTest < ActionController::TestCase
tests PostController
--
cgit v1.2.3
From 205cfe2163d9eb6ee801a23f550e960136b5680e Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Wed, 20 May 2009 16:23:55 -0700
Subject: Massage setup for old tests on new base
---
actionpack/test/abstract_unit.rb | 4 -
actionpack/test/abstract_unit2.rb | 139 -----------------------------
actionpack/test/new_base/abstract_unit.rb | 141 ++++++++++++++++++++++++++++++
3 files changed, 141 insertions(+), 143 deletions(-)
delete mode 100644 actionpack/test/abstract_unit2.rb
create mode 100644 actionpack/test/new_base/abstract_unit.rb
(limited to 'actionpack/test')
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 7982f06545..f6f62bcf83 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -1,6 +1,3 @@
-if ENV["new_base"]
- require "abstract_unit2"
-else
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
@@ -41,4 +38,3 @@ ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
ActionController::Base.view_paths = FIXTURE_LOAD_PATH
-end
\ No newline at end of file
diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb
deleted file mode 100644
index 519e6bea36..0000000000
--- a/actionpack/test/abstract_unit2.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/lib')
-
-
-require 'test/unit'
-require 'active_support'
-require 'active_support/test_case'
-require 'action_controller/abstract'
-require 'action_controller/new_base'
-require 'fixture_template'
-require 'action_controller/testing/process2'
-require 'action_view/test_case'
-require 'action_controller/testing/integration'
-require 'active_support/dependencies'
-
-ActiveSupport::Dependencies.hook!
-
-FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
-
-module ActionController
- Base.session = {
- :key => '_testing_session',
- :secret => '8273f16463985e2b3747dc25e30f2528'
-}
-
- class ActionControllerError < StandardError #:nodoc:
- end
-
- class SessionRestoreError < ActionControllerError #:nodoc:
- end
-
- class RenderError < ActionControllerError #:nodoc:
- end
-
- class RoutingError < ActionControllerError #:nodoc:
- attr_reader :failures
- def initialize(message, failures=[])
- super(message)
- @failures = failures
- end
- end
-
- class MethodNotAllowed < ActionControllerError #:nodoc:
- attr_reader :allowed_methods
-
- def initialize(*allowed_methods)
- super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
- @allowed_methods = allowed_methods
- end
-
- def allowed_methods_header
- allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
- end
-
- def handle_response!(response)
- response.headers['Allow'] ||= allowed_methods_header
- end
- end
-
- class NotImplemented < MethodNotAllowed #:nodoc:
- end
-
- class UnknownController < ActionControllerError #:nodoc:
- end
-
- class MissingFile < ActionControllerError #:nodoc:
- end
-
- class RenderError < ActionControllerError #:nodoc:
- end
-
- class SessionOverflowError < ActionControllerError #:nodoc:
- DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.'
-
- def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
- end
- end
-
- class UnknownHttpMethod < ActionControllerError #:nodoc:
- end
-
- class Base
- include ActionController::Testing
- end
-
- Base.view_paths = FIXTURE_LOAD_PATH
-
- class TestCase
- include TestProcess
- setup do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- end
- end
-
- def assert_template(options = {}, message = nil)
- validate_request!
-
- hax = @controller._action_view.instance_variable_get(:@_rendered)
-
- case options
- when NilClass, String
- rendered = (hax[:template] || []).map { |t| t.identifier }
- msg = build_message(message,
- "expecting > but rendering with >",
- options, rendered.join(', '))
- assert_block(msg) do
- if options.nil?
- hax[:template].blank?
- else
- rendered.any? { |t| t.match(options) }
- end
- end
- when Hash
- if expected_partial = options[:partial]
- partials = hax[:partials]
- if expected_count = options[:count]
- found = partials.detect { |p, _| p.identifier.match(expected_partial) }
- actual_count = found.nil? ? 0 : found.second
- msg = build_message(message,
- "expecting ? to be rendered ? time(s) but rendered ? time(s)",
- expected_partial, expected_count, actual_count)
- assert(actual_count == expected_count.to_i, msg)
- else
- msg = build_message(message,
- "expecting partial > but action rendered >",
- options[:partial], partials.keys)
- assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg)
- end
- else
- assert hax[:partials].empty?,
- "Expected no partials to be rendered"
- end
- end
- end
- end
-end
diff --git a/actionpack/test/new_base/abstract_unit.rb b/actionpack/test/new_base/abstract_unit.rb
new file mode 100644
index 0000000000..e72165ee67
--- /dev/null
+++ b/actionpack/test/new_base/abstract_unit.rb
@@ -0,0 +1,141 @@
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+
+ENV['new_base'] = "true"
+$stderr.puts "Running old tests on new_base"
+
+require 'test/unit'
+require 'active_support'
+require 'active_support/test_case'
+require 'action_controller/abstract'
+require 'action_controller/new_base'
+require 'fixture_template'
+require 'action_controller/testing/process2'
+require 'action_view/test_case'
+require 'action_controller/testing/integration'
+require 'active_support/dependencies'
+
+ActiveSupport::Dependencies.hook!
+
+FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), '../fixtures')
+
+module ActionController
+ Base.session = {
+ :key => '_testing_session',
+ :secret => '8273f16463985e2b3747dc25e30f2528'
+}
+
+ class ActionControllerError < StandardError #:nodoc:
+ end
+
+ class SessionRestoreError < ActionControllerError #:nodoc:
+ end
+
+ class RenderError < ActionControllerError #:nodoc:
+ end
+
+ class RoutingError < ActionControllerError #:nodoc:
+ attr_reader :failures
+ def initialize(message, failures=[])
+ super(message)
+ @failures = failures
+ end
+ end
+
+ class MethodNotAllowed < ActionControllerError #:nodoc:
+ attr_reader :allowed_methods
+
+ def initialize(*allowed_methods)
+ super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
+ @allowed_methods = allowed_methods
+ end
+
+ def allowed_methods_header
+ allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
+ end
+
+ def handle_response!(response)
+ response.headers['Allow'] ||= allowed_methods_header
+ end
+ end
+
+ class NotImplemented < MethodNotAllowed #:nodoc:
+ end
+
+ class UnknownController < ActionControllerError #:nodoc:
+ end
+
+ class MissingFile < ActionControllerError #:nodoc:
+ end
+
+ class RenderError < ActionControllerError #:nodoc:
+ end
+
+ class SessionOverflowError < ActionControllerError #:nodoc:
+ DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.'
+
+ def initialize(message = nil)
+ super(message || DEFAULT_MESSAGE)
+ end
+ end
+
+ class UnknownHttpMethod < ActionControllerError #:nodoc:
+ end
+
+ class Base
+ include ActionController::Testing
+ end
+
+ Base.view_paths = FIXTURE_LOAD_PATH
+
+ class TestCase
+ include TestProcess
+ setup do
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
+ end
+
+ def assert_template(options = {}, message = nil)
+ validate_request!
+
+ hax = @controller._action_view.instance_variable_get(:@_rendered)
+
+ case options
+ when NilClass, String
+ rendered = (hax[:template] || []).map { |t| t.identifier }
+ msg = build_message(message,
+ "expecting > but rendering with >",
+ options, rendered.join(', '))
+ assert_block(msg) do
+ if options.nil?
+ hax[:template].blank?
+ else
+ rendered.any? { |t| t.match(options) }
+ end
+ end
+ when Hash
+ if expected_partial = options[:partial]
+ partials = hax[:partials]
+ if expected_count = options[:count]
+ found = partials.detect { |p, _| p.identifier.match(expected_partial) }
+ actual_count = found.nil? ? 0 : found.second
+ msg = build_message(message,
+ "expecting ? to be rendered ? time(s) but rendered ? time(s)",
+ expected_partial, expected_count, actual_count)
+ assert(actual_count == expected_count.to_i, msg)
+ else
+ msg = build_message(message,
+ "expecting partial > but action rendered >",
+ options[:partial], partials.keys)
+ assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg)
+ end
+ else
+ assert hax[:partials].empty?,
+ "Expected no partials to be rendered"
+ end
+ end
+ end
+ end
+end
--
cgit v1.2.3
From 8e7a87d299483fce6af3be89e50deae43055a96f Mon Sep 17 00:00:00 2001
From: Pratik Naik
Date: Thu, 21 May 2009 01:38:48 +0200
Subject: Make ActionController::Flash work with new_base
---
actionpack/test/controller/flash_test.rb | 49 ++++++++++++++++----------------
1 file changed, 25 insertions(+), 24 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index ef60cae0ff..84e27d7779 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -60,6 +60,7 @@ class FlashTest < ActionController::TestCase
def std_action
@flash_copy = {}.update(flash)
+ render :nothing => true
end
def filter_halting_action
@@ -79,64 +80,64 @@ class FlashTest < ActionController::TestCase
get :set_flash
get :use_flash
- assert_equal "hello", @controller.template.assigns["flash_copy"]["that"]
- assert_equal "hello", @controller.template.assigns["flashy"]
+ assert_equal "hello", assigns["flash_copy"]["that"]
+ assert_equal "hello", assigns["flashy"]
get :use_flash
- assert_nil @controller.template.assigns["flash_copy"]["that"], "On second flash"
+ assert_nil assigns["flash_copy"]["that"], "On second flash"
end
def test_keep_flash
get :set_flash
get :use_flash_and_keep_it
- assert_equal "hello", @controller.template.assigns["flash_copy"]["that"]
- assert_equal "hello", @controller.template.assigns["flashy"]
+ assert_equal "hello", assigns["flash_copy"]["that"]
+ assert_equal "hello", assigns["flashy"]
get :use_flash
- assert_equal "hello", @controller.template.assigns["flash_copy"]["that"], "On second flash"
+ assert_equal "hello", assigns["flash_copy"]["that"], "On second flash"
get :use_flash
- assert_nil @controller.template.assigns["flash_copy"]["that"], "On third flash"
+ assert_nil assigns["flash_copy"]["that"], "On third flash"
end
def test_flash_now
get :set_flash_now
- assert_equal "hello", @controller.template.assigns["flash_copy"]["that"]
- assert_equal "bar" , @controller.template.assigns["flash_copy"]["foo"]
- assert_equal "hello", @controller.template.assigns["flashy"]
+ assert_equal "hello", assigns["flash_copy"]["that"]
+ assert_equal "bar" , assigns["flash_copy"]["foo"]
+ assert_equal "hello", assigns["flashy"]
get :attempt_to_use_flash_now
- assert_nil @controller.template.assigns["flash_copy"]["that"]
- assert_nil @controller.template.assigns["flash_copy"]["foo"]
- assert_nil @controller.template.assigns["flashy"]
+ assert_nil assigns["flash_copy"]["that"]
+ assert_nil assigns["flash_copy"]["foo"]
+ assert_nil assigns["flashy"]
end
def test_update_flash
get :set_flash
get :use_flash_and_update_it
- assert_equal "hello", @controller.template.assigns["flash_copy"]["that"]
- assert_equal "hello again", @controller.template.assigns["flash_copy"]["this"]
+ assert_equal "hello", assigns["flash_copy"]["that"]
+ assert_equal "hello again", assigns["flash_copy"]["this"]
get :use_flash
- assert_nil @controller.template.assigns["flash_copy"]["that"], "On second flash"
- assert_equal "hello again", @controller.template.assigns["flash_copy"]["this"], "On second flash"
+ assert_nil assigns["flash_copy"]["that"], "On second flash"
+ assert_equal "hello again", assigns["flash_copy"]["this"], "On second flash"
end
def test_flash_after_reset_session
get :use_flash_after_reset_session
- assert_equal "hello", @controller.template.assigns["flashy_that"]
- assert_equal "good-bye", @controller.template.assigns["flashy_this"]
- assert_nil @controller.template.assigns["flashy_that_reset"]
+ assert_equal "hello", assigns["flashy_that"]
+ assert_equal "good-bye", assigns["flashy_this"]
+ assert_nil assigns["flashy_that_reset"]
end
def test_sweep_after_halted_filter_chain
get :std_action
- assert_nil @controller.template.assigns["flash_copy"]["foo"]
+ assert_nil assigns["flash_copy"]["foo"]
get :filter_halting_action
- assert_equal "bar", @controller.template.assigns["flash_copy"]["foo"]
+ assert_equal "bar", assigns["flash_copy"]["foo"]
get :std_action # follow redirection
- assert_equal "bar", @controller.template.assigns["flash_copy"]["foo"]
+ assert_equal "bar", assigns["flash_copy"]["foo"]
get :std_action
- assert_nil @controller.template.assigns["flash_copy"]["foo"]
+ assert_nil assigns["flash_copy"]["foo"]
end
end
--
cgit v1.2.3
From c4a6109286909c394e8c5bfc471a1eb9de245d2b Mon Sep 17 00:00:00 2001
From: Yehuda Katz + Carl Lerche
Date: Wed, 20 May 2009 16:52:56 -0700
Subject: Got controller/mime_responds_test.rb running on the new base
---
actionpack/test/abstract_unit.rb | 2 ++
actionpack/test/controller/mime_responds_test.rb | 26 ++++++++++++++----------
actionpack/test/new_base/abstract_unit.rb | 3 +++
3 files changed, 20 insertions(+), 11 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index f6f62bcf83..5ae54d097a 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -23,6 +23,8 @@ require 'action_controller'
require 'action_controller/testing/process'
require 'action_view/test_case'
+$tags[:old_base] = true
+
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 3b8babb84c..56b49251c6 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -375,9 +375,11 @@ class MimeControllerTest < ActionController::TestCase
end
def test_rjs_type_skips_layout
- @request.accept = "text/javascript"
- get :all_types_with_layout
- assert_equal 'RJS for all_types_with_layout', @response.body
+ pending(:new_base) do
+ @request.accept = "text/javascript"
+ get :all_types_with_layout
+ assert_equal 'RJS for all_types_with_layout', @response.body
+ end
end
def test_html_type_with_layout
@@ -510,7 +512,7 @@ class SuperPostController < PostController
end
end
-if ENV["new_base"]
+if defined?(ActionController::Http)
PostController._write_layout_method
SuperPostController._write_layout_method
end
@@ -532,14 +534,16 @@ class MimeControllerLayoutsTest < ActionController::TestCase
assert_equal 'Hello iPhone', @response.body
end
- def test_format_with_inherited_layouts
- @controller = SuperPostController.new
+ for_tag(:old_base) do
+ def test_format_with_inherited_layouts
+ @controller = SuperPostController.new
- get :index
- assert_equal 'Super Firefox', @response.body
+ get :index
+ assert_equal 'Super Firefox', @response.body
- @request.accept = "text/iphone"
- get :index
- assert_equal '
"))
- assert_equal("Weirdos", sanitizer.sanitize("Wei<a onclick='alert(document.cookie);'/>rdos"))
- assert_equal("This is a test.", sanitizer.sanitize("This is a test."))
- assert_equal(
- %{This is a test.\n\n\nIt no longer contains any HTML.\n}, sanitizer.sanitize(
- %{This is a test.\n\n\n\n
It no longer contains any HTML.
\n}))
- assert_equal "This has a here.", sanitizer.sanitize("This has a here.")
- assert_equal "This has a here.", sanitizer.sanitize("This has a ]]> here.")
- assert_equal "This has an unclosed ", sanitizer.sanitize("This has an unclosed ]] here...")
- [nil, '', ' '].each { |blank| assert_equal blank, sanitizer.sanitize(blank) }
- end
-
- def test_strip_links
- sanitizer = HTML::LinkSanitizer.new
- assert_equal "Dont touch me", sanitizer.sanitize("Dont touch me")
- assert_equal "on my mind\nall day long", sanitizer.sanitize("on my mind\nall day long")
- assert_equal "0wn3d", sanitizer.sanitize("0wn3d")
- assert_equal "Magic", sanitizer.sanitize("Magic")
- assert_equal "FrrFox", sanitizer.sanitize("FrrFox")
- assert_equal "My mind\nall day long", sanitizer.sanitize("My mind\nall day long")
- assert_equal "all day long", sanitizer.sanitize("<a href='hello'>all day long</a>")
-
- assert_equal "", ''
- end
-
- def test_sanitize_plaintext
- raw = "foo"
- assert_sanitized raw, "foo"
- end
-
- def test_sanitize_script
- assert_sanitized "a b cd e f", "a b cd e f"
- end
-
- # fucked
- def test_sanitize_js_handlers
- raw = %{onthis="do that" hello}
- assert_sanitized raw, %{onthis="do that" hello}
- end
-
- def test_sanitize_javascript_href
- raw = %{href="javascript:bang" foo, bar}
- assert_sanitized raw, %{href="javascript:bang" foo, bar}
- end
-
- def test_sanitize_image_src
- raw = %{src="javascript:bang" foo, bar}
- assert_sanitized raw, %{src="javascript:bang" foo, bar}
- end
-
- HTML::WhiteListSanitizer.allowed_tags.each do |tag_name|
- define_method "test_should_allow_#{tag_name}_tag" do
- assert_sanitized "start <#{tag_name} title=\"1\" onclick=\"foo\">foo bar baz#{tag_name}> end", %(start <#{tag_name} title="1">foo bar baz#{tag_name}> end)
- end
- end
-
- def test_should_allow_anchors
- assert_sanitized %(), %()
- end
-
- # RFC 3986, sec 4.2
- def test_allow_colons_in_path_component
- assert_sanitized("foo")
- end
-
- %w(src width height alt).each do |img_attr|
- define_method "test_should_allow_image_#{img_attr}_attribute" do
- assert_sanitized %(), %()
- end
- end
-
- def test_should_handle_non_html
- assert_sanitized 'abc'
- end
-
- def test_should_handle_blank_text
- assert_sanitized nil
- assert_sanitized ''
- end
-
- def test_should_allow_custom_tags
- text = "foo"
- sanitizer = HTML::WhiteListSanitizer.new
- assert_equal(text, sanitizer.sanitize(text, :tags => %w(u)))
- end
-
- def test_should_allow_only_custom_tags
- text = "foo with bar"
- sanitizer = HTML::WhiteListSanitizer.new
- assert_equal("foo with bar", sanitizer.sanitize(text, :tags => %w(u)))
- end
-
- def test_should_allow_custom_tags_with_attributes
- text = %(
foo
)
- sanitizer = HTML::WhiteListSanitizer.new
- assert_equal(text, sanitizer.sanitize(text))
- end
-
- def test_should_allow_custom_tags_with_custom_attributes
- text = %(
Lorem ipsum
)
- sanitizer = HTML::WhiteListSanitizer.new
- assert_equal(text, sanitizer.sanitize(text, :attributes => ['foo']))
- end
-
- [%w(img src), %w(a href)].each do |(tag, attr)|
- define_method "test_should_strip_#{attr}_attribute_in_#{tag}_with_bad_protocols" do
- assert_sanitized %(<#{tag} #{attr}="javascript:bang" title="1">boo#{tag}>), %(<#{tag} title="1">boo#{tag}>)
- end
- end
-
- def test_should_flag_bad_protocols
- sanitizer = HTML::WhiteListSanitizer.new
- %w(about chrome data disk hcp help javascript livescript lynxcgi lynxexec ms-help ms-its mhtml mocha opera res resource shell vbscript view-source vnd.ms.radio wysiwyg).each do |proto|
- assert sanitizer.send(:contains_bad_protocols?, 'src', "#{proto}://bad")
- end
- end
-
- def test_should_accept_good_protocols
- sanitizer = HTML::WhiteListSanitizer.new
- HTML::WhiteListSanitizer.allowed_protocols.each do |proto|
- assert !sanitizer.send(:contains_bad_protocols?, 'src', "#{proto}://good")
- end
- end
-
- def test_should_reject_hex_codes_in_protocol
- assert_sanitized %(1), "1"
- assert @sanitizer.send(:contains_bad_protocols?, 'src', "%6A%61%76%61%73%63%72%69%70%74%3A%61%6C%65%72%74%28%22%58%53%53%22%29")
- end
-
- def test_should_block_script_tag
- assert_sanitized %(), ""
- end
-
- [%(),
- %(),
- %(),
- %(">),
- %(),
- %(),
- %(),
- %(),
- %(),
- %(),
- %(),
- %(),
- %(),
- %(),
- %()].each_with_index do |img_hack, i|
- define_method "test_should_not_fall_for_xss_image_hack_#{i+1}" do
- assert_sanitized img_hack, ""
- end
- end
-
- def test_should_sanitize_tag_broken_up_by_null
- assert_sanitized %(alert(\"XSS\")), "alert(\"XSS\")"
- end
-
- def test_should_sanitize_invalid_script_tag
- assert_sanitized %(), ""
- end
-
- def test_should_sanitize_script_tag_with_multiple_open_brackets
- assert_sanitized %(<), "<"
- assert_sanitized %(