From f4f68885efd0e1135217433cafd368902b1fd58a Mon Sep 17 00:00:00 2001
From: Taryn East
Date: Fri, 2 Oct 2009 10:13:01 -0500
Subject: update_attribute(s) added to Active Resource
Signed-off-by: Joshua Peek
---
activeresource/lib/active_resource/base.rb | 30 +++++++++++++++++
activeresource/test/cases/base_test.rb | 53 ++++++++++++++++++++++++++++--
2 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index e5b8589fb3..8fc0999c70 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -1099,6 +1099,36 @@ module ActiveResource
self
end
+ # Updates a single attribute and then saves the object.
+ #
+ # Note: Unlike ActiveRecord::Base.update_attribute, this method is
+ # subject to normal validation routines as an update sends the whole body
+ # of the resource in the request. (See Validations).
+ #
+ # As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
+ #
+ # If the saving fails because of a connection or remote service error, an
+ # exception will be raised. If saving fails because the resource is
+ # invalid then false will be returned.
+ def update_attribute(name, value)
+ self.send("#{name}=".to_sym, value)
+ self.save
+ end
+
+
+ # Updates this resource with all the attributes from the passed-in Hash
+ # and requests that the record be saved.
+ #
+ # If the saving fails because of a connection or remote service error, an
+ # exception will be raised. If saving fails because the resource is
+ # invalid then false will be returned.
+ #
+ # Note: Though this request can be made with a partial set of the
+ # resource's attributes, the full body of the request will still be sent
+ # in the save request to the remote service.
+ def update_attributes(attributes)
+ load(attributes) && save
+ end
# For checking respond_to? without searching the attributes (which is faster).
alias_method :respond_to_without_attributes?, :respond_to?
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index 8c0217aad6..96fc6fc2fe 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -11,12 +11,12 @@ class BaseTest < Test::Unit::TestCase
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
@david = { :id => 2, :name => 'David' }.to_xml(:root => 'person')
@greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person')
- @addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address')
+ @addy = { :id => 1, :street => '12345 Street', :country => 'Australia' }.to_xml(:root => 'address')
@default_request_headers = { 'Content-Type' => 'application/xml' }
@rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person")
@people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people')
@people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people')
- @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses')
+ @addresses = [{ :id => 1, :street => '12345 Street', :country => 'Australia' }].to_xml(:root => 'addresses')
# - deep nested resource -
# - Luis (Customer)
@@ -813,6 +813,55 @@ class BaseTest < Test::Unit::TestCase
assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save }
end
+
+ ######
+ # update_attribute(s)(!)
+
+ def test_update_attribute_as_symbol
+ matz = Person.first
+ matz.expects(:save).returns(true)
+
+ assert_equal "Matz", matz.name
+ assert matz.update_attribute(:name, "David")
+ assert_equal "David", matz.name
+ end
+
+ def test_update_attribute_as_string
+ matz = Person.first
+ matz.expects(:save).returns(true)
+
+ assert_equal "Matz", matz.name
+ assert matz.update_attribute('name', "David")
+ assert_equal "David", matz.name
+ end
+
+
+ def test_update_attributes_as_symbols
+ addy = StreetAddress.first(:params => {:person_id => 1})
+ addy.expects(:save).returns(true)
+
+ assert_equal "12345 Street", addy.street
+ assert_equal "Australia", addy.country
+ assert addy.update_attributes(:street => '54321 Street', :country => 'USA')
+ assert_equal "54321 Street", addy.street
+ assert_equal "USA", addy.country
+ end
+
+ def test_update_attributes_as_strings
+ addy = StreetAddress.first(:params => {:person_id => 1})
+ addy.expects(:save).returns(true)
+
+ assert_equal "12345 Street", addy.street
+ assert_equal "Australia", addy.country
+ assert addy.update_attributes('street' => '54321 Street', 'country' => 'USA')
+ assert_equal "54321 Street", addy.street
+ assert_equal "USA", addy.country
+ end
+
+
+ #####
+ # Mayhem and destruction
+
def test_destroy
assert Person.find(1).destroy
ActiveResource::HttpMock.respond_to do |mock|
--
cgit v1.2.3
From 8377646d68b32de362fefad0d752a923f6b36da6 Mon Sep 17 00:00:00 2001
From: Taryn East
Date: Fri, 2 Oct 2009 10:13:40 -0500
Subject: add indifferent access to the attributes
Signed-off-by: Joshua Peek
---
activeresource/lib/active_resource/base.rb | 3 ++-
activeresource/test/cases/base/load_test.rb | 13 +++++++++++++
activeresource/test/cases/base_test.rb | 15 +++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 8fc0999c70..3a07811f26 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -1,6 +1,7 @@
require 'active_support'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/module/attr_accessor_with_default'
require 'active_support/core_ext/module/delegation'
@@ -770,7 +771,7 @@ module ActiveResource
# my_other_course = Course.new(:name => "Philosophy: Reason and Being", :lecturer => "Ralph Cling")
# my_other_course.save
def initialize(attributes = {})
- @attributes = {}
+ @attributes = {}.with_indifferent_access
@prefix_options = {}
load(attributes)
end
diff --git a/activeresource/test/cases/base/load_test.rb b/activeresource/test/cases/base/load_test.rb
index 1952f5b5f0..53fa94d07f 100644
--- a/activeresource/test/cases/base/load_test.rb
+++ b/activeresource/test/cases/base/load_test.rb
@@ -68,6 +68,19 @@ class BaseLoadTest < Test::Unit::TestCase
assert_equal @matz.stringify_keys, @person.load(@matz).attributes
end
+ def test_after_load_attributes_are_accessible
+ assert_equal Hash.new, @person.attributes
+ assert_equal @matz.stringify_keys, @person.load(@matz).attributes
+ assert_equal @matz[:name], @person.attributes['name']
+ end
+
+ def test_after_load_attributes_are_accessible_via_indifferent_access
+ assert_equal Hash.new, @person.attributes
+ assert_equal @matz.stringify_keys, @person.load(@matz).attributes
+ assert_equal @matz[:name], @person.attributes['name']
+ assert_equal @matz[:name], @person.attributes[:name]
+ end
+
def test_load_one_with_existing_resource
address = @person.load(:street_address => @first_address).street_address
assert_kind_of StreetAddress, address
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index 96fc6fc2fe..fc366430d4 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -102,6 +102,9 @@ class BaseTest < Test::Unit::TestCase
Person.password = nil
end
+ ########################################################################
+ # Tests relating to setting up the API-connection configuration
+ ########################################################################
def test_site_accessor_accepts_uri_or_string_argument
site = URI.parse('http://localhost')
@@ -509,6 +512,11 @@ class BaseTest < Test::Unit::TestCase
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
end
+
+ ########################################################################
+ # Tests for setting up remote URLs for a given model (including adding
+ # parameters appropriately)
+ ########################################################################
def test_collection_name
assert_equal "people", Person.collection_name
end
@@ -637,6 +645,10 @@ class BaseTest < Test::Unit::TestCase
assert_equal [:person_id].to_set, StreetAddress.__send__(:prefix_parameters)
end
+
+ ########################################################################
+ # Tests basic CRUD functions (find/save/create etc)
+ ########################################################################
def test_respond_to
matz = Person.find(1)
assert matz.respond_to?(:name)
@@ -910,6 +922,9 @@ class BaseTest < Test::Unit::TestCase
assert_raise(ActiveResource::ResourceGone) { Person.find(1) }
end
+ ########################################################################
+ # Tests the more miscelaneous helper methods
+ ########################################################################
def test_exists
# Class method.
assert !Person.exists?(nil)
--
cgit v1.2.3
From 89630a7c2c3d0f625742e2b84ec28479ff3ecef9 Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Fri, 2 Oct 2009 10:19:30 -0500
Subject: Cleanup whitespace introduced in 8377646 and f4f6888
---
activeresource/lib/active_resource/base.rb | 69 ++++++++++++++---------------
activeresource/test/cases/base/load_test.rb | 25 ++++-------
activeresource/test/cases/base_test.rb | 8 ++--
3 files changed, 47 insertions(+), 55 deletions(-)
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 3a07811f26..b21d8db613 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -156,7 +156,7 @@ module ActiveResource
#
# 404 is just one of the HTTP error response codes that Active Resource will handle with its own exception. The
# following HTTP response codes will also result in these exceptions:
- #
+ #
# * 200..399 - Valid response, no exception (other than 301, 302)
# * 301, 302 - ActiveResource::Redirection
# * 400 - ActiveResource::BadRequest
@@ -415,7 +415,7 @@ module ActiveResource
attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
attr_accessor_with_default(:primary_key, 'id') #:nodoc:
-
+
# Gets the \prefix for a resource's nested URL (e.g., prefix/collectionname/1.xml)
# This method is regenerated at runtime based on what the \prefix is set to.
def prefix(options={})
@@ -916,7 +916,7 @@ module ActiveResource
def save
new? ? create : update
end
-
+
# Saves the resource.
#
# If the resource is new, it is created via +POST+, otherwise the
@@ -925,7 +925,7 @@ module ActiveResource
# With save! validations always run. If any of them fail
# ActiveResource::ResourceInvalid gets raised, and nothing is POSTed to
# the remote system.
- # See ActiveResource::Validations for more information.
+ # See ActiveResource::Validations for more information.
#
# There's a series of callbacks associated with save!. If any
# of the before_* callbacks return +false+ the action is
@@ -1100,36 +1100,36 @@ module ActiveResource
self
end
- # Updates a single attribute and then saves the object.
- #
- # Note: Unlike ActiveRecord::Base.update_attribute, this method is
- # subject to normal validation routines as an update sends the whole body
- # of the resource in the request. (See Validations).
- #
- # As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
- #
- # If the saving fails because of a connection or remote service error, an
- # exception will be raised. If saving fails because the resource is
- # invalid then false will be returned.
- def update_attribute(name, value)
- self.send("#{name}=".to_sym, value)
- self.save
- end
-
-
- # Updates this resource with all the attributes from the passed-in Hash
- # and requests that the record be saved.
- #
- # If the saving fails because of a connection or remote service error, an
- # exception will be raised. If saving fails because the resource is
- # invalid then false will be returned.
- #
- # Note: Though this request can be made with a partial set of the
- # resource's attributes, the full body of the request will still be sent
- # in the save request to the remote service.
- def update_attributes(attributes)
- load(attributes) && save
- end
+ # Updates a single attribute and then saves the object.
+ #
+ # Note: Unlike ActiveRecord::Base.update_attribute, this method is
+ # subject to normal validation routines as an update sends the whole body
+ # of the resource in the request. (See Validations).
+ #
+ # As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
+ #
+ # If the saving fails because of a connection or remote service error, an
+ # exception will be raised. If saving fails because the resource is
+ # invalid then false will be returned.
+ def update_attribute(name, value)
+ self.send("#{name}=".to_sym, value)
+ self.save
+ end
+
+ # Updates this resource with all the attributes from the passed-in Hash
+ # and requests that the record be saved.
+ #
+ # If the saving fails because of a connection or remote service error, an
+ # exception will be raised. If saving fails because the resource is
+ # invalid then false will be returned.
+ #
+ # Note: Though this request can be made with a partial set of the
+ # resource's attributes, the full body of the request will still be sent
+ # in the save request to the remote service.
+ def update_attributes(attributes)
+ load(attributes) && save
+ end
+
# For checking respond_to? without searching the attributes (which is faster).
alias_method :respond_to_without_attributes?, :respond_to?
@@ -1150,7 +1150,6 @@ module ActiveResource
super
end
-
protected
def connection(refresh = false)
self.class.connection(refresh)
diff --git a/activeresource/test/cases/base/load_test.rb b/activeresource/test/cases/base/load_test.rb
index 53fa94d07f..189a4d81fe 100644
--- a/activeresource/test/cases/base/load_test.rb
+++ b/activeresource/test/cases/base/load_test.rb
@@ -15,26 +15,21 @@ module Highrise
module Deeply
module Nested
-
class Note < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
end
- class Comment < ActiveResource::Base
- self.site = "http://37s.sunrise.i:3000"
- end
-
- module TestDifferentLevels
-
- class Note < ActiveResource::Base
- self.site = "http://37s.sunrise.i:3000"
- end
-
- end
+ class Comment < ActiveResource::Base
+ self.site = "http://37s.sunrise.i:3000"
+ end
+ module TestDifferentLevels
+ class Note < ActiveResource::Base
+ self.site = "http://37s.sunrise.i:3000"
+ end
+ end
end
end
-
end
@@ -156,7 +151,7 @@ class BaseLoadTest < Test::Unit::TestCase
assert_kind_of String, places.first
assert_equal @deep[:street][:state][:places].first, places.first
end
-
+
def test_nested_collections_within_the_same_namespace
n = Highrise::Note.new(:comments => [{ :name => "1" }])
assert_kind_of Highrise::Comment, n.comments.first
@@ -171,6 +166,4 @@ class BaseLoadTest < Test::Unit::TestCase
n = Highrise::Deeply::Nested::TestDifferentLevels::Note.new(:comments => [{ :name => "1" }])
assert_kind_of Highrise::Deeply::Nested::Comment, n.comments.first
end
-
-
end
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index fc366430d4..1593e25595 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -828,7 +828,7 @@ class BaseTest < Test::Unit::TestCase
######
# update_attribute(s)(!)
-
+
def test_update_attribute_as_symbol
matz = Person.first
matz.expects(:save).returns(true)
@@ -837,7 +837,7 @@ class BaseTest < Test::Unit::TestCase
assert matz.update_attribute(:name, "David")
assert_equal "David", matz.name
end
-
+
def test_update_attribute_as_string
matz = Person.first
matz.expects(:save).returns(true)
@@ -847,7 +847,7 @@ class BaseTest < Test::Unit::TestCase
assert_equal "David", matz.name
end
-
+
def test_update_attributes_as_symbols
addy = StreetAddress.first(:params => {:person_id => 1})
addy.expects(:save).returns(true)
@@ -913,7 +913,7 @@ class BaseTest < Test::Unit::TestCase
end
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
end
-
+
def test_delete_with_410_gone
assert Person.delete(1)
ActiveResource::HttpMock.respond_to do |mock|
--
cgit v1.2.3
From 84e94551f62d3bcbc71f1c6f3fda738342d984e2 Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sat, 3 Oct 2009 20:45:49 -0500
Subject: Add custom "with_routing" to internal tests to fix reseting session
after using with_routing. This only affects our internal AP tests.
---
actionpack/test/abstract_unit.rb | 33 ++++++++++++++++++----
.../test/activerecord/active_record_store_test.rb | 1 -
actionpack/test/controller/integration_test.rb | 5 +---
actionpack/test/controller/rescue_test.rb | 1 -
actionpack/test/controller/webservice_test.rb | 1 -
.../dispatch/request/json_params_parsing_test.rb | 1 -
.../request/multipart_params_parsing_test.rb | 1 -
.../dispatch/request/query_string_parsing_test.rb | 1 -
.../request/url_encoded_params_parsing_test.rb | 1 -
.../dispatch/request/xml_params_parsing_test.rb | 1 -
.../test/dispatch/session/cookie_store_test.rb | 1 -
.../test/dispatch/session/mem_cache_store_test.rb | 1 -
actionpack/test/lib/controller/fake_controllers.rb | 1 +
actionpack/test/view/test_case_test.rb | 1 +
14 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index aef3dd6165..b72dd4dd0f 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -53,12 +53,33 @@ ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
class ActionController::IntegrationTest < ActiveSupport::TestCase
- @@app = ActionDispatch::MiddlewareStack.new { |middleware|
- middleware.use "ActionDispatch::ShowExceptions"
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "Rack::Head"
- }.build(ActionController::Routing::Routes)
+ def self.build_app(routes = nil)
+ ActionDispatch::MiddlewareStack.new { |middleware|
+ middleware.use "ActionDispatch::ShowExceptions"
+ middleware.use "ActionDispatch::Callbacks"
+ middleware.use "ActionDispatch::ParamsParser"
+ middleware.use "Rack::Head"
+ }.build(routes || ActionController::Routing::Routes)
+ end
+
+ self.app = build_app
+
+ def with_routing(&block)
+ real_routes = ActionController::Routing::Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+
+ temporary_routes = ActionController::Routing::RouteSet.new
+ self.class.app = self.class.build_app(temporary_routes)
+ ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
+
+ yield temporary_routes
+ ensure
+ if ActionController::Routing.const_defined? :Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+ end
+ ActionController::Routing.const_set(:Routes, real_routes) if real_routes
+ self.class.app = self.class.build_app
+ end
end
module ActionView
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb
index 102b9cffdd..c6c079f88c 100644
--- a/actionpack/test/activerecord/active_record_store_test.rb
+++ b/actionpack/test/activerecord/active_record_store_test.rb
@@ -158,7 +158,6 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
map.connect "/:action", :controller => "active_record_store_test/test"
end
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
- reset!
yield
end
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 0e4ca21143..508364d0b5 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -372,11 +372,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
- c.connect "/:action"
- end
+ map.connect "/:action", :controller => "integration_process_test/integration"
end
- reset!
yield
end
end
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 6ad708bba1..689359166f 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -347,7 +347,6 @@ class RescueTest < ActionController::IntegrationTest
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
- reset!
yield
end
end
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index c04d20fbad..0514c098bf 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -259,7 +259,6 @@ class WebServiceTest < ActionController::IntegrationTest
c.connect "/", :action => "assign_parameters"
end
end
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb
index 995f36bb29..db6cf7b330 100644
--- a/actionpack/test/dispatch/request/json_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -59,7 +59,6 @@ class JsonParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "json_params_parsing_test/test"
end
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
index d4ee4362eb..301080842e 100644
--- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
@@ -153,7 +153,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "multipart_params_parsing_test/test"
end
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb
index 2261934e45..a31e326ddf 100644
--- a/actionpack/test/dispatch/request/query_string_parsing_test.rb
+++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb
@@ -111,7 +111,6 @@ class QueryStringParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "query_string_parsing_test/test"
end
- reset!
get "/parse", actual
assert_response :ok
diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
index 6c9967d26e..7167cdafac 100644
--- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
@@ -132,7 +132,6 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
end
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
index 2f2dd695c4..521002b519 100644
--- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -86,7 +86,6 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "xml_params_parsing_test/test"
end
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 6241c79829..ab5fabde65 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -223,7 +223,6 @@ class CookieStoreTest < ActionController::IntegrationTest
end
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
@app = ActionDispatch::Session::CookieStore.new(set, options)
- reset!
yield
end
end
diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb
index c2d40ae24a..c7435bd06b 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -115,7 +115,6 @@ class MemCacheStoreTest < ActionController::IntegrationTest
map.connect "/:action", :controller => "mem_cache_store_test/test"
end
@app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
- reset!
yield
end
end
diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb
index 5dcca2e148..2e8c5090ca 100644
--- a/actionpack/test/lib/controller/fake_controllers.rb
+++ b/actionpack/test/lib/controller/fake_controllers.rb
@@ -18,6 +18,7 @@ class HiController < ActionController::Base; end
class BraveController < ActionController::Base; end
class ImageController < ActionController::Base; end
class WeblogController < ActionController::Base; end
+class BarController < ActionController::Base; end
# For speed test
class SpeedController < ActionController::Base; end
diff --git a/actionpack/test/view/test_case_test.rb b/actionpack/test/view/test_case_test.rb
index 3e974b87f7..5db42c4d68 100644
--- a/actionpack/test/view/test_case_test.rb
+++ b/actionpack/test/view/test_case_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'controller/fake_controllers'
module ActionView
class TestCase
--
cgit v1.2.3
From 018b79dd36d054d87fdc408d38dc9ac7f1b1500d Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sat, 3 Oct 2009 21:05:51 -0500
Subject: File extra test folders into controller, dispatch, or template
---
actionpack/Rakefile | 2 +-
actionpack/test/controller/new_base/base_test.rb | 68 +++++
.../new_base/content_negotiation_test.rb | 18 ++
.../test/controller/new_base/content_type_test.rb | 111 +++++++
actionpack/test/controller/new_base/etag_test.rb | 46 +++
actionpack/test/controller/new_base/metal_test.rb | 43 +++
.../test/controller/new_base/middleware_test.rb | 77 +++++
.../test/controller/new_base/render_action_test.rb | 320 +++++++++++++++++++++
.../test/controller/new_base/render_file_test.rb | 110 +++++++
.../new_base/render_implicit_action_test.rb | 28 ++
.../test/controller/new_base/render_layout_test.rb | 101 +++++++
.../controller/new_base/render_partial_test.rb | 27 ++
.../test/controller/new_base/render_rjs_test.rb | 50 ++++
.../controller/new_base/render_template_test.rb | 170 +++++++++++
actionpack/test/controller/new_base/render_test.rb | 85 ++++++
.../test/controller/new_base/render_text_test.rb | 137 +++++++++
.../test/controller/new_base/render_xml_test.rb | 11 +
actionpack/test/html-scanner/cdata_node_test.rb | 15 -
actionpack/test/html-scanner/document_test.rb | 148 ----------
actionpack/test/html-scanner/node_test.rb | 89 ------
actionpack/test/html-scanner/sanitizer_test.rb | 273 ------------------
actionpack/test/html-scanner/tag_node_test.rb | 238 ---------------
actionpack/test/html-scanner/text_node_test.rb | 50 ----
actionpack/test/html-scanner/tokenizer_test.rb | 131 ---------
actionpack/test/javascript/ajax_test.rb | 115 --------
actionpack/test/new_base/base_test.rb | 68 -----
.../test/new_base/content_negotiation_test.rb | 18 --
actionpack/test/new_base/content_type_test.rb | 111 -------
actionpack/test/new_base/etag_test.rb | 46 ---
actionpack/test/new_base/metal_test.rb | 43 ---
actionpack/test/new_base/middleware_test.rb | 77 -----
actionpack/test/new_base/render_action_test.rb | 320 ---------------------
actionpack/test/new_base/render_file_test.rb | 110 -------
.../test/new_base/render_implicit_action_test.rb | 28 --
actionpack/test/new_base/render_layout_test.rb | 101 -------
actionpack/test/new_base/render_partial_test.rb | 27 --
actionpack/test/new_base/render_rjs_test.rb | 50 ----
actionpack/test/new_base/render_template_test.rb | 170 -----------
actionpack/test/new_base/render_test.rb | 85 ------
actionpack/test/new_base/render_text_test.rb | 137 ---------
actionpack/test/new_base/render_xml_test.rb | 11 -
actionpack/test/template/ajax_test.rb | 114 ++++++++
.../test/template/html-scanner/cdata_node_test.rb | 15 +
.../test/template/html-scanner/document_test.rb | 148 ++++++++++
actionpack/test/template/html-scanner/node_test.rb | 89 ++++++
.../test/template/html-scanner/sanitizer_test.rb | 273 ++++++++++++++++++
.../test/template/html-scanner/tag_node_test.rb | 238 +++++++++++++++
.../test/template/html-scanner/text_node_test.rb | 50 ++++
.../test/template/html-scanner/tokenizer_test.rb | 131 +++++++++
actionpack/test/template/test_case_test.rb | 172 +++++++++++
actionpack/test/view/test_case_test.rb | 172 -----------
51 files changed, 2633 insertions(+), 2634 deletions(-)
create mode 100644 actionpack/test/controller/new_base/base_test.rb
create mode 100644 actionpack/test/controller/new_base/content_negotiation_test.rb
create mode 100644 actionpack/test/controller/new_base/content_type_test.rb
create mode 100644 actionpack/test/controller/new_base/etag_test.rb
create mode 100644 actionpack/test/controller/new_base/metal_test.rb
create mode 100644 actionpack/test/controller/new_base/middleware_test.rb
create mode 100644 actionpack/test/controller/new_base/render_action_test.rb
create mode 100644 actionpack/test/controller/new_base/render_file_test.rb
create mode 100644 actionpack/test/controller/new_base/render_implicit_action_test.rb
create mode 100644 actionpack/test/controller/new_base/render_layout_test.rb
create mode 100644 actionpack/test/controller/new_base/render_partial_test.rb
create mode 100644 actionpack/test/controller/new_base/render_rjs_test.rb
create mode 100644 actionpack/test/controller/new_base/render_template_test.rb
create mode 100644 actionpack/test/controller/new_base/render_test.rb
create mode 100644 actionpack/test/controller/new_base/render_text_test.rb
create mode 100644 actionpack/test/controller/new_base/render_xml_test.rb
delete mode 100644 actionpack/test/html-scanner/cdata_node_test.rb
delete mode 100644 actionpack/test/html-scanner/document_test.rb
delete mode 100644 actionpack/test/html-scanner/node_test.rb
delete mode 100644 actionpack/test/html-scanner/sanitizer_test.rb
delete mode 100644 actionpack/test/html-scanner/tag_node_test.rb
delete mode 100644 actionpack/test/html-scanner/text_node_test.rb
delete mode 100644 actionpack/test/html-scanner/tokenizer_test.rb
delete mode 100644 actionpack/test/javascript/ajax_test.rb
delete mode 100644 actionpack/test/new_base/base_test.rb
delete mode 100644 actionpack/test/new_base/content_negotiation_test.rb
delete mode 100644 actionpack/test/new_base/content_type_test.rb
delete mode 100644 actionpack/test/new_base/etag_test.rb
delete mode 100644 actionpack/test/new_base/metal_test.rb
delete mode 100644 actionpack/test/new_base/middleware_test.rb
delete mode 100644 actionpack/test/new_base/render_action_test.rb
delete mode 100644 actionpack/test/new_base/render_file_test.rb
delete mode 100644 actionpack/test/new_base/render_implicit_action_test.rb
delete mode 100644 actionpack/test/new_base/render_layout_test.rb
delete mode 100644 actionpack/test/new_base/render_partial_test.rb
delete mode 100644 actionpack/test/new_base/render_rjs_test.rb
delete mode 100644 actionpack/test/new_base/render_template_test.rb
delete mode 100644 actionpack/test/new_base/render_test.rb
delete mode 100644 actionpack/test/new_base/render_text_test.rb
delete mode 100644 actionpack/test/new_base/render_xml_test.rb
create mode 100644 actionpack/test/template/ajax_test.rb
create mode 100644 actionpack/test/template/html-scanner/cdata_node_test.rb
create mode 100644 actionpack/test/template/html-scanner/document_test.rb
create mode 100644 actionpack/test/template/html-scanner/node_test.rb
create mode 100644 actionpack/test/template/html-scanner/sanitizer_test.rb
create mode 100644 actionpack/test/template/html-scanner/tag_node_test.rb
create mode 100644 actionpack/test/template/html-scanner/text_node_test.rb
create mode 100644 actionpack/test/template/html-scanner/tokenizer_test.rb
create mode 100644 actionpack/test/template/test_case_test.rb
delete mode 100644 actionpack/test/view/test_case_test.rb
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index af39175047..547e74b5a1 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -34,7 +34,7 @@ end
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration]
-TESTS_GLOB = "test/{abstract,controller,dispatch,new_base,template,html-scanner,view}/**/*_test.rb"
+TESTS_GLOB = "test/{abstract,controller,dispatch,template}/**/*_test.rb"
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << 'test'
diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb
new file mode 100644
index 0000000000..effde324bc
--- /dev/null
+++ b/actionpack/test/controller/new_base/base_test.rb
@@ -0,0 +1,68 @@
+require 'abstract_unit'
+
+# Tests the controller dispatching happy path
+module Dispatching
+ class SimpleController < ActionController::Base
+ def index
+ render :text => "success"
+ end
+
+ 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 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"
+ assert_status 200
+ assert_content_type "text/html; charset=utf-8"
+ end
+
+ # :api: plugin
+ test "directly modifying response body" do
+ get "/dispatching/simple/modify_response_body"
+
+ assert_body "success"
+ end
+
+ # :api: plugin
+ test "directly modifying response body twice" do
+ get "/dispatching/simple/modify_response_body_twice"
+
+ assert_body "success!"
+ end
+
+ 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
+
+ test "controller name" do
+ assert_equal 'empty', EmptyController.controller_name
+ assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/content_negotiation_test.rb b/actionpack/test/controller/new_base/content_negotiation_test.rb
new file mode 100644
index 0000000000..c43cb677f8
--- /dev/null
+++ b/actionpack/test/controller/new_base/content_negotiation_test.rb
@@ -0,0 +1,18 @@
+require 'abstract_unit'
+
+module ContentNegotiation
+
+ # This has no layout and it works
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "content_negotiation/basic/hello.html.erb" => "Hello world <%= request.formats %>!"
+ )]
+ end
+
+ class TestContentNegotiation < SimpleRouteCase
+ test "A */* Accept header will return HTML" do
+ get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*"
+ assert_body "Hello world */*!"
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb
new file mode 100644
index 0000000000..898d0bb9f3
--- /dev/null
+++ b/actionpack/test/controller/new_base/content_type_test.rb
@@ -0,0 +1,111 @@
+require 'abstract_unit'
+
+module ContentType
+ class BaseController < ActionController::Base
+ 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 ImpliedController < ActionController::Base
+ # Template's mime type is used if no content_type is specified
+
+ self.view_paths = [ActionView::FixtureResolver.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 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", "format" => "xml"
+
+ 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", "format" => "xml"
+
+ assert_header "Content-Type", "application/xml; charset=utf-8"
+ end
+ end
+
+ 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
+
+ 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
+end
diff --git a/actionpack/test/controller/new_base/etag_test.rb b/actionpack/test/controller/new_base/etag_test.rb
new file mode 100644
index 0000000000..d5b7942ab6
--- /dev/null
+++ b/actionpack/test/controller/new_base/etag_test.rb
@@ -0,0 +1,46 @@
+require 'abstract_unit'
+
+module Etags
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.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 => "etags"
+ end
+ end
+
+ 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
diff --git a/actionpack/test/controller/new_base/metal_test.rb b/actionpack/test/controller/new_base/metal_test.rb
new file mode 100644
index 0000000000..e1d46b906e
--- /dev/null
+++ b/actionpack/test/controller/new_base/metal_test.rb
@@ -0,0 +1,43 @@
+require 'abstract_unit'
+
+module MetalTest
+ class MetalMiddleware < ActionController::Middleware
+ def call(env)
+ if env["PATH_INFO"] =~ /authed/
+ app.call(env)
+ else
+ [401, headers, "Not authed!"]
+ end
+ end
+ end
+
+ class Endpoint
+ def call(env)
+ [200, {}, "Hello World"]
+ end
+ end
+
+ class TestMiddleware < ActiveSupport::TestCase
+ def setup
+ @app = Rack::Builder.new do
+ use MetalMiddleware
+ run Endpoint.new
+ end.to_app
+ end
+
+ test "it can call the next app by using @app" do
+ env = Rack::MockRequest.env_for("/authed")
+ response = @app.call(env)
+
+ assert_equal "Hello World", response[2]
+ end
+
+ test "it can return a response using the normal AC::Metal techniques" do
+ env = Rack::MockRequest.env_for("/")
+ response = @app.call(env)
+
+ assert_equal "Not authed!", response[2]
+ assert_equal 401, response[0]
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb
new file mode 100644
index 0000000000..ada0215b1a
--- /dev/null
+++ b/actionpack/test/controller/new_base/middleware_test.rb
@@ -0,0 +1,77 @@
+require 'abstract_unit'
+
+module MiddlewareTest
+ class MyMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Test"] = "Success"
+ result[1]["Middleware-Order"] = "First"
+ result
+ end
+ end
+
+ class ExclaimerMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Order"] << "!"
+ result
+ end
+ end
+
+ class MyController < ActionController::Metal
+ use MyMiddleware
+
+ middleware.insert_before MyMiddleware, ExclaimerMiddleware
+
+ def index
+ self.response_body = "Hello World"
+ end
+ end
+
+ class InheritedController < MyController
+ end
+
+ module MiddlewareTests
+ extend ActiveSupport::Testing::Declarative
+
+ test "middleware that is 'use'd is called as part of the Rack application" do
+ result = @app.call(env_for("/"))
+ assert_equal "Hello World", result[2]
+ assert_equal "Success", result[1]["Middleware-Test"]
+ end
+
+ test "the middleware stack is exposed as 'middleware' in the controller" do
+ result = @app.call(env_for("/"))
+ assert_equal "First!", result[1]["Middleware-Order"]
+ end
+ end
+
+ class TestMiddleware < ActiveSupport::TestCase
+ include MiddlewareTests
+
+ def setup
+ @app = MyController.action(:index)
+ end
+
+ def env_for(url)
+ Rack::MockRequest.env_for(url)
+ end
+ end
+
+ class TestInheritedMiddleware < TestMiddleware
+ def setup
+ @app = InheritedController.action(:index)
+ end
+
+ test "middleware inherits" do
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/render_action_test.rb b/actionpack/test/controller/new_base/render_action_test.rb
new file mode 100644
index 0000000000..d5896c1ebd
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_action_test.rb
@@ -0,0 +1,320 @@
+require 'abstract_unit'
+
+module RenderAction
+ # This has no layout and it works
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.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
+
+ 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 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 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
+
+ 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::FixtureResolver.new(
+ "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
+ "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'",
+ "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
+ "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 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::FixtureResolver.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 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::FixtureResolver.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 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
diff --git a/actionpack/test/controller/new_base/render_file_test.rb b/actionpack/test/controller/new_base/render_file_test.rb
new file mode 100644
index 0000000000..1c52d2b37d
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_file_test.rb
@@ -0,0 +1,110 @@
+require 'abstract_unit'
+
+module RenderFile
+
+ class BasicController < ActionController::Base
+ self.view_paths = File.dirname(__FILE__)
+
+ def index
+ render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
+ end
+
+ def with_instance_variables
+ @secret = 'in the sauce'
+ render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
+ end
+
+ def without_file_key
+ render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
+ end
+
+ def without_file_key_with_instance_variable
+ @secret = 'in the sauce'
+ render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
+ end
+
+ def relative_path
+ @secret = 'in the sauce'
+ render :file => '../../fixtures/test/render_file_with_ivar'
+ end
+
+ def relative_path_with_dot
+ @secret = 'in the sauce'
+ render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
+ end
+
+ def pathname
+ @secret = 'in the sauce'
+ render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
+ end
+
+ def with_locals
+ path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
+ render :file => path, :locals => {:secret => 'in the sauce'}
+ end
+
+ def without_file_key_with_locals
+ path = File.expand_path('../../fixtures/test/render_file_with_locals.erb')
+ render path, :locals => {:secret => 'in the sauce'}
+ end
+ end
+
+ class TestBasic < SimpleRouteCase
+ testing RenderFile::BasicController
+
+ def setup
+ @old_pwd = Dir.pwd
+ Dir.chdir(File.dirname(__FILE__))
+ end
+
+ def teardown
+ Dir.chdir(@old_pwd)
+ end
+
+ test "rendering simple template" do
+ get :index
+ assert_response "Hello world!"
+ end
+
+ test "rendering template with ivar" do
+ get :with_instance_variables
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering path without specifying the :file key" do
+ get :without_file_key
+ assert_response "Hello world!"
+ end
+
+ test "rendering path without specifying the :file key with ivar" do
+ get :without_file_key_with_instance_variable
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering a relative path" do
+ get :relative_path
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering a relative path with dot" do
+ get :relative_path_with_dot
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering a Pathname" do
+ get :pathname
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering file with locals" do
+ get :with_locals
+ assert_response "The secret is in the sauce\n"
+ end
+
+ test "rendering path without specifying the :file key with locals" do
+ get :without_file_key_with_locals
+ assert_response "The secret is in the sauce\n"
+ end
+ end
+
+end
diff --git a/actionpack/test/controller/new_base/render_implicit_action_test.rb b/actionpack/test/controller/new_base/render_implicit_action_test.rb
new file mode 100644
index 0000000000..2b78fa7d4f
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_implicit_action_test.rb
@@ -0,0 +1,28 @@
+require 'abstract_unit'
+
+module RenderImplicitAction
+ class SimpleController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
+ "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!"
+ )]
+
+ def hello_world() end
+ end
+
+ 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
diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb
new file mode 100644
index 0000000000..f840a47ecf
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_layout_test.rb
@@ -0,0 +1,101 @@
+require 'abstract_unit'
+
+module ControllerLayouts
+ class ImplicitController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.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 ImplicitNameController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI",
+ "basic.html.erb" => "Hello world!"
+ )]
+
+ def index
+ render :template => "basic"
+ end
+ end
+
+ 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 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)"
+ end
+ end
+
+ class MismatchFormatController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "layouts/application.html.erb" => "<%= yield %>",
+ "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg",
+ "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg"
+ )]
+
+ def explicit
+ render :layout => "application"
+ end
+ end
+
+ class MismatchFormatTest < SimpleRouteCase
+ testing ControllerLayouts::MismatchFormatController
+
+ test "if JS is selected, an HTML template is not also selected" do
+ get :index, "format" => "js"
+ assert_response "$(\"test\").omg();"
+ end
+
+ test "if JS is implicitly selected, an HTML template is not also selected" do
+ get :implicit
+ assert_response "$(\"test\").omg();"
+ end
+
+ test "if an HTML template is explicitly provides for a JS template, an error is raised" do
+ assert_raises ActionView::MissingTemplate do
+ get :explicit, {}, "action_dispatch.show_exceptions" => false
+ end
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/render_partial_test.rb b/actionpack/test/controller/new_base/render_partial_test.rb
new file mode 100644
index 0000000000..7c2c20e1c7
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_partial_test.rb
@@ -0,0 +1,27 @@
+require 'abstract_unit'
+
+module RenderPartial
+
+ class BasicController < ActionController::Base
+
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_partial/basic/_basic.html.erb" => "OMG!",
+ "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>"
+ )]
+
+ def changing
+ @test_unchanged = 'hello'
+ render :action => "basic"
+ end
+ end
+
+ class TestPartial < SimpleRouteCase
+ testing BasicController
+
+ test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do
+ get :changing
+ assert_response("goodbyeOMG!goodbye")
+ end
+ end
+
+end
diff --git a/actionpack/test/controller/new_base/render_rjs_test.rb b/actionpack/test/controller/new_base/render_rjs_test.rb
new file mode 100644
index 0000000000..7b76c54ab9
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_rjs_test.rb
@@ -0,0 +1,50 @@
+require 'abstract_unit'
+
+module RenderRjs
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')",
+ "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.js.erb" => "JS Partial",
+ "render_rjs/basic/_customer.html.erb" => "HTML Partial",
+ "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial",
+ "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial"
+ )]
+
+ def index
+ render
+ end
+
+ def index_locale
+ old_locale, I18n.locale = I18n.locale, :da
+ end
+ end
+
+ class TestBasic < SimpleRouteCase
+ testing BasicController
+
+ def setup
+ @old_locale = I18n.locale
+ end
+
+ def teardown
+ I18n.locale = @old_locale
+ end
+
+ test "rendering a partial in an RJS template should pick the JS template over the HTML one" do
+ get :index, "format" => "js"
+ assert_response("$(\"customer\").update(\"JS Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do
+ get :index_html, "format" => "js"
+ assert_response("$(\"customer\").update(\"HTML Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do
+ get :index_locale, "format" => "js"
+ assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/render_template_test.rb b/actionpack/test/controller/new_base/render_template_test.rb
new file mode 100644
index 0000000000..3b24c2d75a
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_template_test.rb
@@ -0,0 +1,170 @@
+require 'abstract_unit'
+
+module RenderTemplate
+ class WithoutLayoutController < ActionController::Base
+
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica",
+ "locals.html.erb" => "The secret is <%= secret %>",
+ "xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend"
+ )]
+
+ def index
+ render :template => "test/basic"
+ end
+
+ def index_without_key
+ render "test/basic"
+ end
+
+ def in_top_directory
+ render :template => 'shared'
+ end
+
+ def in_top_directory_with_slash
+ render :template => '/shared'
+ end
+
+ def in_top_directory_with_slash_without_key
+ render '/shared'
+ end
+
+ def with_locals
+ render :template => "locals", :locals => { :secret => 'area51' }
+ end
+
+ def builder_template
+ render :template => "xml_template"
+ end
+ end
+
+ class TestWithoutLayout < SimpleRouteCase
+ testing RenderTemplate::WithoutLayoutController
+
+ test "rendering a normal template with full path without layout" do
+ get :index
+ assert_response "Hello from basic.html.erb"
+ end
+
+ test "rendering a normal template with full path without layout without key" do
+ get :index_without_key
+ assert_response "Hello from basic.html.erb"
+ end
+
+ test "rendering a template not in a subdirectory" do
+ get :in_top_directory
+ assert_response "Elastica"
+ end
+
+ test "rendering a template not in a subdirectory with a leading slash" do
+ get :in_top_directory_with_slash
+ assert_response "Elastica"
+ end
+
+ test "rendering a template not in a subdirectory with a leading slash without key" do
+ get :in_top_directory_with_slash_without_key
+ assert_response "Elastica"
+ end
+
+ test "rendering a template with local variables" do
+ get :with_locals
+ assert_response "The secret is area51"
+ end
+
+ test "rendering a builder template" do
+ get :builder_template, "format" => "xml"
+ assert_response "\n
Hello
\n\n"
+ end
+ end
+
+ class WithLayoutController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica",
+ "layouts/application.html.erb" => "<%= yield %>, I'm here!",
+ "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well."
+ )]
+
+ def index
+ render :template => "test/basic"
+ end
+
+ def with_layout
+ render :template => "test/basic", :layout => true
+ end
+
+ def with_layout_false
+ render :template => "test/basic", :layout => false
+ end
+
+ def with_layout_nil
+ render :template => "test/basic", :layout => nil
+ end
+
+ def with_custom_layout
+ render :template => "test/basic", :layout => "greetings"
+ end
+ end
+
+ 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::FixtureResolver.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica"
+ )]
+
+ def with_forward_slash
+ render :template => "/test/basic"
+ end
+ end
+
+ class TestTemplateRenderWithForwardSlash < SimpleRouteCase
+ test "rendering a normal template with full path starting with a leading slash" do
+ get "/render_template/compatibility/without_layout/with_forward_slash"
+
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/render_test.rb b/actionpack/test/controller/new_base/render_test.rb
new file mode 100644
index 0000000000..804be79d17
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_test.rb
@@ -0,0 +1,85 @@
+require 'abstract_unit'
+
+module Render
+ class BlankRenderController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render/blank_render/index.html.erb" => "Hello world!",
+ "render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
+ "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
+
+ def secretz
+ render :text => "FAIL WHALE!"
+ end
+ end
+
+ class DoubleRenderController < ActionController::Base
+ def index
+ render :text => "hello"
+ render :text => "world"
+ end
+ end
+
+ 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
+ end
+ end
+ end
+
+ class TestVariousObjectsAvailableInView < SimpleRouteCase
+ test "The request object is accessible in the view" do
+ 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"
+ end
+ end
+end
diff --git a/actionpack/test/controller/new_base/render_text_test.rb b/actionpack/test/controller/new_base/render_text_test.rb
new file mode 100644
index 0000000000..f5839ee16f
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_text_test.rb
@@ -0,0 +1,137 @@
+require 'abstract_unit'
+
+module RenderText
+ class SimpleController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new]
+
+ def index
+ render :text => "hello david"
+ end
+ end
+
+ class WithLayoutController < ::ApplicationController
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "layouts/application.html.erb" => "<%= yield %>, I'm here!",
+ "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.",
+ "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>"
+ )]
+
+ def index
+ render :text => "hello david"
+ end
+
+ def custom_code
+ render :text => "hello world", :status => 404
+ end
+
+ def with_custom_code_as_string
+ render :text => "hello world", :status => "404 Not Found"
+ end
+
+ def with_nil
+ render :text => nil
+ end
+
+ def with_nil_and_status
+ render :text => nil, :status => 403
+ end
+
+ def with_false
+ render :text => false
+ end
+
+ def with_layout_true
+ render :text => "hello world", :layout => true
+ end
+
+ def with_layout_false
+ render :text => "hello world", :layout => false
+ end
+
+ def with_layout_nil
+ render :text => "hello world", :layout => nil
+ end
+
+ def with_custom_layout
+ render :text => "hello world", :layout => "greetings"
+ end
+
+ def with_ivar_in_layout
+ @ivar = "hello world"
+ render :text => "hello world", :layout => "ivar"
+ end
+ end
+
+ 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 an empty body padded for Safari" do
+ get "/render_text/with_layout/with_nil"
+
+ assert_body " "
+ assert_status 200
+ end
+
+ test "Rendering text with nil and custom status code returns an empty body padded for Safari and 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/controller/new_base/render_xml_test.rb b/actionpack/test/controller/new_base/render_xml_test.rb
new file mode 100644
index 0000000000..d044738a78
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_xml_test.rb
@@ -0,0 +1,11 @@
+require 'abstract_unit'
+
+module RenderXml
+
+ # This has no layout and it works
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_xml/basic/with_render_erb" => "Hello world!"
+ )]
+ end
+end
diff --git a/actionpack/test/html-scanner/cdata_node_test.rb b/actionpack/test/html-scanner/cdata_node_test.rb
deleted file mode 100644
index 1822cc565a..0000000000
--- a/actionpack/test/html-scanner/cdata_node_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'abstract_unit'
-
-class CDATANodeTest < Test::Unit::TestCase
- def setup
- @node = HTML::CDATA.new(nil, 0, 0, "
"))
- 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 %(