aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-04-20 18:31:22 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-04-20 18:31:40 -0700
commit685a53a360d0d8fc4a9f3b49f900621c940a71f2 (patch)
treefa6b38f75a873a21c3e380f1acbab3d019293363 /actionpack/test/controller
parentdb05c73fb6e2294c576ef9889c70940891682c32 (diff)
parent164a94d0bc8c9124ab820506e5ad79496395c026 (diff)
downloadrails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.tar.gz
rails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.tar.bz2
rails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.zip
Merge branch 'master' into cherry
Conflicts: activesupport/CHANGELOG activesupport/lib/active_support/core_ext/class/delegating_attributes.rb activesupport/lib/active_support/core_ext/hash/conversions.rb activesupport/lib/active_support/core_ext/module/attribute_accessors.rb activesupport/lib/active_support/core_ext/string/multibyte.rb activesupport/lib/active_support/core_ext/time/calculations.rb activesupport/lib/active_support/deprecation.rb
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb2
-rw-r--r--actionpack/test/controller/addresses_render_test.rb1
-rw-r--r--actionpack/test/controller/assert_select_test.rb2
-rw-r--r--actionpack/test/controller/base_test.rb2
-rw-r--r--actionpack/test/controller/benchmark_test.rb1
-rw-r--r--actionpack/test/controller/caching_test.rb4
-rw-r--r--actionpack/test/controller/capture_test.rb1
-rw-r--r--actionpack/test/controller/content_type_test.rb3
-rw-r--r--actionpack/test/controller/cookie_test.rb11
-rw-r--r--actionpack/test/controller/dispatcher_test.rb8
-rw-r--r--actionpack/test/controller/header_test.rb14
-rw-r--r--actionpack/test/controller/layout_test.rb48
-rw-r--r--actionpack/test/controller/logging_test.rb5
-rw-r--r--actionpack/test/controller/middleware_stack_test.rb90
-rw-r--r--actionpack/test/controller/mime_responds_test.rb9
-rw-r--r--actionpack/test/controller/mime_type_test.rb93
-rw-r--r--actionpack/test/controller/rack_test.rb294
-rw-r--r--actionpack/test/controller/render_test.rb45
-rw-r--r--actionpack/test/controller/request/json_params_parsing_test.rb45
-rw-r--r--actionpack/test/controller/request/multipart_params_parsing_test.rb223
-rw-r--r--actionpack/test/controller/request/query_string_parsing_test.rb120
-rw-r--r--actionpack/test/controller/request/test_request_test.rb35
-rw-r--r--actionpack/test/controller/request/url_encoded_params_parsing_test.rb184
-rw-r--r--actionpack/test/controller/request/xml_params_parsing_test.rb88
-rw-r--r--actionpack/test/controller/request_forgery_protection_test.rb11
-rw-r--r--actionpack/test/controller/request_test.rb407
-rw-r--r--actionpack/test/controller/rescue_test.rb9
-rw-r--r--actionpack/test/controller/send_file_test.rb2
-rw-r--r--actionpack/test/controller/session/cookie_store_test.rb43
-rw-r--r--actionpack/test/controller/session/mem_cache_store_test.rb2
-rw-r--r--actionpack/test/controller/test_test.rb12
-rw-r--r--actionpack/test/controller/view_paths_test.rb4
32 files changed, 189 insertions, 1629 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index cb7922efd2..96f7a42c9b 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -168,11 +168,13 @@ end
class ActionPackAssertionsControllerTest < ActionController::TestCase
# let's get this party started
def setup
+ super
ActionController::Routing::Routes.reload
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
end
def teardown
+ super
ActionController::Routing::Routes.reload
end
diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb
index 556b0593ea..2f092b6731 100644
--- a/actionpack/test/controller/addresses_render_test.rb
+++ b/actionpack/test/controller/addresses_render_test.rb
@@ -23,6 +23,7 @@ class AddressesTest < ActionController::TestCase
tests AddressesTestController
def setup
+ super
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
@controller.logger = Logger.new(nil)
diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb
index 298c7e4db3..ad17d1288b 100644
--- a/actionpack/test/controller/assert_select_test.rb
+++ b/actionpack/test/controller/assert_select_test.rb
@@ -66,12 +66,14 @@ class AssertSelectTest < ActionController::TestCase
tests AssertSelectController
def setup
+ super
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
def teardown
+ super
ActionMailer::Base.deliveries.clear
end
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 9523189f41..f4517d06c4 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -170,6 +170,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase
tests DefaultUrlOptionsController
def setup
+ super
@request.host = 'www.example.com'
rescue_action_in_public!
end
@@ -193,6 +194,7 @@ class EmptyUrlOptionsTest < ActionController::TestCase
tests NonEmptyController
def setup
+ super
@request.host = 'www.example.com'
rescue_action_in_public!
end
diff --git a/actionpack/test/controller/benchmark_test.rb b/actionpack/test/controller/benchmark_test.rb
index f9100a2313..66ebfcf20a 100644
--- a/actionpack/test/controller/benchmark_test.rb
+++ b/actionpack/test/controller/benchmark_test.rb
@@ -20,6 +20,7 @@ class BenchmarkTest < ActionController::TestCase
end
def setup
+ super
# benchmark doesn't do anything unless a logger is set
@controller.logger = MockLogger.new
@request.host = "test.actioncontroller.i"
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 86dafd9221..b61a58dd09 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -44,6 +44,7 @@ end
class PageCachingTest < ActionController::TestCase
def setup
+ super
ActionController::Base.perform_caching = true
ActionController::Routing::Routes.draw do |map|
@@ -222,6 +223,7 @@ end
class ActionCacheTest < ActionController::TestCase
def setup
+ super
reset!
FileUtils.mkdir_p(FILE_STORE_PATH)
@path_class = ActionController::Caching::Actions::ActionCachePath
@@ -483,6 +485,7 @@ end
class FragmentCachingTest < ActionController::TestCase
def setup
+ super
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
ActionController::Base.cache_store = @store
@@ -615,6 +618,7 @@ end
class FunctionalFragmentCachingTest < ActionController::TestCase
def setup
+ super
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
ActionController::Base.cache_store = @store
diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb
index 6dfa0995eb..9a0976ca9f 100644
--- a/actionpack/test/controller/capture_test.rb
+++ b/actionpack/test/controller/capture_test.rb
@@ -27,6 +27,7 @@ class CaptureTest < ActionController::TestCase
tests CaptureController
def setup
+ super
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
@controller.logger = Logger.new(nil)
diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb
index 32c1757ef9..7377546631 100644
--- a/actionpack/test/controller/content_type_test.rb
+++ b/actionpack/test/controller/content_type_test.rb
@@ -54,6 +54,7 @@ class ContentTypeTest < ActionController::TestCase
tests ContentTypeController
def setup
+ super
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
@controller.logger = Logger.new(nil)
@@ -136,10 +137,12 @@ class AcceptBasedContentTypeTest < ActionController::TestCase
tests ContentTypeController
def setup
+ super
ActionController::Base.use_accept_header = true
end
def teardown
+ super
ActionController::Base.use_accept_header = false
end
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 657be3c4e4..c861982698 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -6,6 +6,10 @@ class CookieTest < ActionController::TestCase
cookies["user_name"] = "david"
end
+ def set_with_with_escapable_characters
+ cookies["that & guy"] = "foo & bar => baz"
+ end
+
def authenticate_for_fourteen_days
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
end
@@ -44,6 +48,7 @@ class CookieTest < ActionController::TestCase
tests TestController
def setup
+ super
@request.host = "www.nextangle.com"
end
@@ -53,6 +58,12 @@ class CookieTest < ActionController::TestCase
assert_equal({"user_name" => "david"}, @response.cookies)
end
+ def test_setting_with_escapable_characters
+ get :set_with_with_escapable_characters
+ assert_equal ["that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"], @response.headers["Set-Cookie"]
+ assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
+ end
+
def test_setting_cookie_for_fourteen_days
get :authenticate_for_fourteen_days
assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index 7887b7110c..721bcf6136 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -6,8 +6,8 @@ class DispatcherTest < Test::Unit::TestCase
def setup
ENV['REQUEST_METHOD'] = 'GET'
- Dispatcher.middleware = ActionController::MiddlewareStack.new do |middleware|
- middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/middlewares.rb"))
+ 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
@@ -46,8 +46,8 @@ class DispatcherTest < Test::Unit::TestCase
end
def test_failsafe_response
- Dispatcher.any_instance.expects(:dispatch).raises('b00m')
- ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
+ Dispatcher.any_instance.expects(:_call).raises('b00m')
+ ActionDispatch::Failsafe.any_instance.expects(:log_failsafe_exception)
assert_nothing_raised do
assert_equal [
diff --git a/actionpack/test/controller/header_test.rb b/actionpack/test/controller/header_test.rb
deleted file mode 100644
index 33c14a187c..0000000000
--- a/actionpack/test/controller/header_test.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require 'abstract_unit'
-
-class HeaderTest < Test::Unit::TestCase
- def setup
- @headers = ActionController::Http::Headers.new("HTTP_CONTENT_TYPE"=>"text/plain")
- end
-
- def test_content_type_works
- assert_equal "text/plain", @headers["Content-Type"]
- assert_equal "text/plain", @headers["content-type"]
- assert_equal "text/plain", @headers["CONTENT_TYPE"]
- assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
- end
-end
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 1575674e18..f2721e274d 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -37,6 +37,7 @@ end
class LayoutAutoDiscoveryTest < ActionController::TestCase
def setup
+ super
@request.host = "www.nextangle.com"
end
@@ -55,7 +56,7 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase
def test_third_party_template_library_auto_discovers_layout
@controller = ThirdPartyTemplateLibraryController.new
get :hello
- assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout.to_s
+ assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout(true).to_s
assert_equal 'layouts/third_party_template_library', @response.layout
assert_response :success
assert_equal 'Mab', @response.body
@@ -64,14 +65,14 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase
def test_namespaced_controllers_auto_detect_layouts
@controller = ControllerNameSpace::NestedController.new
get :hello
- assert_equal 'layouts/controller_name_space/nested', @controller.active_layout.to_s
+ assert_equal 'layouts/controller_name_space/nested', @controller.active_layout(true).to_s
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
end
def test_namespaced_controllers_auto_detect_layouts
@controller = MultipleExtensions.new
get :hello
- assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout.to_s
+ assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout(true).to_s
assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
end
end
@@ -94,6 +95,14 @@ class PrependsViewPathController < LayoutTest
end
end
+class OnlyLayoutController < LayoutTest
+ layout 'item', :only => "hello"
+end
+
+class ExceptLayoutController < LayoutTest
+ layout 'item', :except => "goodbye"
+end
+
class SetsLayoutInRenderController < LayoutTest
def hello
render :layout => 'third_party_template_library'
@@ -118,6 +127,30 @@ class LayoutSetInResponseTest < ActionController::TestCase
get :hello
assert_equal 'layouts/item', @response.layout
end
+
+ def test_layout_only_exception_when_included
+ @controller = OnlyLayoutController.new
+ get :hello
+ assert_equal 'layouts/item', @response.layout
+ end
+
+ def test_layout_only_exception_when_excepted
+ @controller = OnlyLayoutController.new
+ get :goodbye
+ assert_equal nil, @response.layout
+ end
+
+ def test_layout_except_exception_when_included
+ @controller = ExceptLayoutController.new
+ get :hello
+ assert_equal 'layouts/item', @response.layout
+ end
+
+ def test_layout_except_exception_when_excepted
+ @controller = ExceptLayoutController.new
+ get :goodbye
+ assert_equal nil, @response.layout
+ end
def test_layout_set_when_using_render
@controller = SetsLayoutInRenderController.new
@@ -143,9 +176,11 @@ class LayoutSetInResponseTest < ActionController::TestCase
end
def test_layout_is_picked_from_the_controller_instances_view_path
- @controller = PrependsViewPathController.new
- get :hello
- assert_equal 'layouts/alt', @response.layout
+ pending do
+ @controller = PrependsViewPathController.new
+ get :hello
+ assert_equal 'layouts/alt', @response.layout
+ end
end
def test_absolute_pathed_layout
@@ -201,4 +236,3 @@ unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
end
end
end
-
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 3c936854dd..1f3ff4ef52 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -18,7 +18,10 @@ class LoggingTest < ActionController::TestCase
end
end
- setup :set_logger
+ def setup
+ super
+ set_logger
+ end
def test_logging_without_parameters
get :show
diff --git a/actionpack/test/controller/middleware_stack_test.rb b/actionpack/test/controller/middleware_stack_test.rb
deleted file mode 100644
index 918231013a..0000000000
--- a/actionpack/test/controller/middleware_stack_test.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-require 'abstract_unit'
-
-class MiddlewareStackTest < ActiveSupport::TestCase
- class FooMiddleware; end
- class BarMiddleware; end
- class BazMiddleware; end
-
- def setup
- @stack = ActionController::MiddlewareStack.new
- @stack.use FooMiddleware
- @stack.use BarMiddleware
- end
-
- test "use should push middleware as class onto the stack" do
- assert_difference "@stack.size" do
- @stack.use BazMiddleware
- end
- assert_equal BazMiddleware, @stack.last.klass
- end
-
- test "use should push middleware as a string onto the stack" do
- assert_difference "@stack.size" do
- @stack.use "MiddlewareStackTest::BazMiddleware"
- end
- assert_equal BazMiddleware, @stack.last.klass
- end
-
- test "use should push middleware as a symbol onto the stack" do
- assert_difference "@stack.size" do
- @stack.use :"MiddlewareStackTest::BazMiddleware"
- end
- assert_equal BazMiddleware, @stack.last.klass
- end
-
- test "use should push middleware class with arguments onto the stack" do
- assert_difference "@stack.size" do
- @stack.use BazMiddleware, true, :foo => "bar"
- end
- assert_equal BazMiddleware, @stack.last.klass
- assert_equal([true, {:foo => "bar"}], @stack.last.args)
- end
-
- test "insert inserts middleware at the integer index" do
- @stack.insert(1, BazMiddleware)
- assert_equal BazMiddleware, @stack[1].klass
- end
-
- test "insert_after inserts middleware after the integer index" do
- @stack.insert_after(1, BazMiddleware)
- assert_equal BazMiddleware, @stack[2].klass
- end
-
- test "insert_before inserts middleware before another middleware class" do
- @stack.insert_before(BarMiddleware, BazMiddleware)
- assert_equal BazMiddleware, @stack[1].klass
- end
-
- test "insert_after inserts middleware after another middleware class" do
- @stack.insert_after(BarMiddleware, BazMiddleware)
- assert_equal BazMiddleware, @stack[2].klass
- end
-
- test "swaps one middleware out for another" do
- assert_equal FooMiddleware, @stack[0].klass
- @stack.swap(FooMiddleware, BazMiddleware)
- assert_equal BazMiddleware, @stack[0].klass
- end
-
- test "active returns all only enabled middleware" do
- assert_no_difference "@stack.active.size" do
- assert_difference "@stack.size" do
- @stack.use BazMiddleware, :if => lambda { false }
- end
- end
- end
-
- test "lazy evaluates middleware class" do
- assert_difference "@stack.size" do
- @stack.use lambda { BazMiddleware }
- end
- assert_equal BazMiddleware, @stack.last.klass
- end
-
- test "lazy evaluates middleware arguments" do
- assert_difference "@stack.size" do
- @stack.use BazMiddleware, lambda { :foo }
- end
- assert_equal [:foo], @stack.last.send(:build_args)
- end
-end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index edd7162325..7cd5145a2f 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -166,11 +166,13 @@ class MimeControllerTest < ActionController::TestCase
tests RespondToController
def setup
+ super
ActionController::Base.use_accept_header = true
@request.host = "www.example.com"
end
def teardown
+ super
ActionController::Base.use_accept_header = false
end
@@ -437,15 +439,15 @@ class MimeControllerTest < ActionController::TestCase
unless args.empty?
@action = args.first[:action]
end
- response.body = "#{@action} - #{@template.template_format}"
+ response.body = "#{@action} - #{@template.formats}"
end
end
get :using_defaults
- assert_equal "using_defaults - html", @response.body
+ assert_equal "using_defaults - #{[:html].to_s}", @response.body
get :using_defaults, :format => "xml"
- assert_equal "using_defaults - xml", @response.body
+ assert_equal "using_defaults - #{[:xml].to_s}", @response.body
end
def test_format_with_custom_response_type
@@ -511,6 +513,7 @@ class MimeControllerLayoutsTest < ActionController::TestCase
tests PostController
def setup
+ super
@request.host = "www.example.com"
end
diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb
deleted file mode 100644
index c7faa621d9..0000000000
--- a/actionpack/test/controller/mime_type_test.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-require 'abstract_unit'
-
-class MimeTypeTest < Test::Unit::TestCase
- Mime::Type.register "image/png", :png
- Mime::Type.register "application/pdf", :pdf
-
- def test_parse_single
- Mime::LOOKUP.keys.each do |mime_type|
- assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type)
- end
- end
-
- def test_parse_without_q
- accept = "text/xml,application/xhtml+xml,text/yaml,application/xml,text/html,image/png,text/plain,application/pdf,*/*"
- expect = [Mime::HTML, Mime::XML, Mime::YAML, Mime::PNG, Mime::TEXT, Mime::PDF, Mime::ALL]
- assert_equal expect, Mime::Type.parse(accept)
- end
-
- def test_parse_with_q
- accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2"
- expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL]
- assert_equal expect, Mime::Type.parse(accept)
- end
-
- # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP)
- def test_parse_crappy_broken_acceptlines
- accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5"
- expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
- assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
- end
-
- # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
- def test_parse_crappy_broken_acceptlines2
- accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
- expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
- assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
- end
-
- def test_custom_type
- Mime::Type.register("image/gif", :gif)
- assert_nothing_raised do
- Mime::GIF
- assert_equal Mime::GIF, Mime::SET.last
- end
- ensure
- Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
- end
-
- def test_type_should_be_equal_to_symbol
- assert_equal Mime::HTML, 'application/xhtml+xml'
- assert_equal Mime::HTML, :html
- end
-
- def test_type_convenience_methods
- # Don't test Mime::ALL, since it Mime::ALL#html? == true
- types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
-
- # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
- types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
-
- types.each do |type|
- mime = Mime.const_get(type.to_s.upcase)
- assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
- invalid_types = types - [type]
- invalid_types.delete(:html) if Mime::Type.html_types.include?(type)
- invalid_types.each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
- end
- end
-
- def test_mime_all_is_html
- assert Mime::ALL.all?, "Mime::ALL is not all?"
- assert Mime::ALL.html?, "Mime::ALL is not html?"
- end
-
- def test_verifiable_mime_types
- all_types = Mime::SET.to_a.map(&:to_sym)
- all_types.uniq!
- # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
- all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
- verified, unverified = all_types.partition { |type| Mime::Type.browser_generated_types.include? type }
- assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
- assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
- end
-
- def test_regexp_matcher
- assert Mime::JS =~ "text/javascript"
- assert Mime::JS =~ "application/javascript"
- assert Mime::JS !~ "text/html"
- assert !(Mime::JS !~ "text/javascript")
- assert !(Mime::JS !~ "application/javascript")
- assert Mime::HTML =~ 'application/xhtml+xml'
- end
-end
diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb
deleted file mode 100644
index 89bf4fdacc..0000000000
--- a/actionpack/test/controller/rack_test.rb
+++ /dev/null
@@ -1,294 +0,0 @@
-require 'abstract_unit'
-
-class BaseRackTest < Test::Unit::TestCase
- def setup
- @env = {
- "HTTP_MAX_FORWARDS" => "10",
- "SERVER_NAME" => "glu.ttono.us",
- "FCGI_ROLE" => "RESPONDER",
- "AUTH_TYPE" => "Basic",
- "HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
- "HTTP_ACCEPT_CHARSET" => "UTF-8",
- "HTTP_ACCEPT_ENCODING" => "gzip, deflate",
- "HTTP_CACHE_CONTROL" => "no-cache, max-age=0",
- "HTTP_PRAGMA" => "no-cache",
- "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)",
- "PATH_INFO" => "/homepage/",
- "HTTP_ACCEPT_LANGUAGE" => "en",
- "HTTP_NEGOTIATE" => "trans",
- "HTTP_HOST" => "glu.ttono.us:8007",
- "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us",
- "HTTP_FROM" => "googlebot",
- "SERVER_PROTOCOL" => "HTTP/1.1",
- "REDIRECT_URI" => "/dispatch.fcgi",
- "SCRIPT_NAME" => "/dispatch.fcgi",
- "SERVER_ADDR" => "207.7.108.53",
- "REMOTE_ADDR" => "207.7.108.53",
- "REMOTE_HOST" => "google.com",
- "REMOTE_IDENT" => "kevin",
- "REMOTE_USER" => "kevin",
- "SERVER_SOFTWARE" => "lighttpd/1.4.5",
- "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes",
- "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us",
- "REQUEST_URI" => "/admin",
- "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public",
- "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/",
- "SERVER_PORT" => "8007",
- "QUERY_STRING" => "",
- "REMOTE_PORT" => "63137",
- "GATEWAY_INTERFACE" => "CGI/1.1",
- "HTTP_X_FORWARDED_FOR" => "65.88.180.234",
- "HTTP_ACCEPT" => "*/*",
- "SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi",
- "REDIRECT_STATUS" => "200",
- "REQUEST_METHOD" => "GET"
- }
- @request = ActionController::Request.new(@env)
- # some Nokia phone browsers omit the space after the semicolon separator.
- # some developers have grown accustomed to using comma in cookie values.
- @alt_cookie_fmt_request = ActionController::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}))
- end
-
- def default_test; end
-
- private
-
- def set_content_data(data)
- @request.env['REQUEST_METHOD'] = 'POST'
- @request.env['CONTENT_LENGTH'] = data.length
- @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
- @request.env['rack.input'] = StringIO.new(data)
- end
-end
-
-class RackRequestTest < BaseRackTest
- def test_proxy_request
- assert_equal 'glu.ttono.us', @request.host_with_port
- end
-
- def test_http_host
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env['HTTP_HOST'] = "rubyonrails.org:8080"
- assert_equal "rubyonrails.org", @request.host
- assert_equal "rubyonrails.org:8080", @request.host_with_port
-
- @env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
- assert_equal "www.secondhost.org", @request.host
- end
-
- def test_http_host_with_default_port_overrides_server_port
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env['HTTP_HOST'] = "rubyonrails.org"
- assert_equal "rubyonrails.org", @request.host_with_port
- end
-
- def test_host_with_port_defaults_to_server_name_if_no_host_headers
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env.delete "HTTP_HOST"
- assert_equal "glu.ttono.us:8007", @request.host_with_port
- end
-
- def test_host_with_port_falls_back_to_server_addr_if_necessary
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env.delete "HTTP_HOST"
- @env.delete "SERVER_NAME"
- assert_equal "207.7.108.53", @request.host
- assert_equal 8007, @request.port
- assert_equal "207.7.108.53:8007", @request.host_with_port
- end
-
- def test_host_with_port_if_http_standard_port_is_specified
- @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
- assert_equal "glu.ttono.us", @request.host_with_port
- end
-
- def test_host_with_port_if_https_standard_port_is_specified
- @env['HTTP_X_FORWARDED_PROTO'] = "https"
- @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
- assert_equal "glu.ttono.us", @request.host_with_port
- end
-
- def test_host_if_ipv6_reference
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
- end
-
- def test_host_if_ipv6_reference_with_port
- @env.delete "HTTP_X_FORWARDED_HOST"
- @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
- end
-
- def test_cgi_environment_variables
- assert_equal "Basic", @request.auth_type
- assert_equal 0, @request.content_length
- assert_equal nil, @request.content_type
- assert_equal "CGI/1.1", @request.gateway_interface
- assert_equal "*/*", @request.accept
- assert_equal "UTF-8", @request.accept_charset
- assert_equal "gzip, deflate", @request.accept_encoding
- assert_equal "en", @request.accept_language
- assert_equal "no-cache, max-age=0", @request.cache_control
- assert_equal "googlebot", @request.from
- assert_equal "glu.ttono.us", @request.host
- assert_equal "trans", @request.negotiate
- assert_equal "no-cache", @request.pragma
- assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer
- assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent
- assert_equal "/homepage/", @request.path_info
- assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated
- assert_equal "", @request.query_string
- assert_equal "207.7.108.53", @request.remote_addr
- assert_equal "google.com", @request.remote_host
- assert_equal "kevin", @request.remote_ident
- assert_equal "kevin", @request.remote_user
- assert_equal :get, @request.request_method
- assert_equal "/dispatch.fcgi", @request.script_name
- assert_equal "glu.ttono.us", @request.server_name
- assert_equal 8007, @request.server_port
- assert_equal "HTTP/1.1", @request.server_protocol
- assert_equal "lighttpd", @request.server_software
- end
-
- def test_cookie_syntax_resilience
- cookies = @request.cookies
- assert_equal "c84ace84796670c052c6ceb2451fb0f2", cookies["_session_id"], cookies.inspect
- assert_equal "yes", cookies["is_admin"], cookies.inspect
-
- alt_cookies = @alt_cookie_fmt_request.cookies
- #assert_equal "c84ace847,96670c052c6ceb2451fb0f2", alt_cookies["_session_id"], alt_cookies.inspect
- assert_equal "yes", alt_cookies["is_admin"], alt_cookies.inspect
- end
-end
-
-class RackRequestParamsParsingTest < BaseRackTest
- def test_doesnt_break_when_content_type_has_charset
- set_content_data 'flamenco=love'
-
- assert_equal({"flamenco"=> "love"}, @request.request_parameters)
- end
-
- def test_doesnt_interpret_request_uri_as_query_string_when_missing
- @request.env['REQUEST_URI'] = 'foo'
- assert_equal({}, @request.query_parameters)
- end
-end
-
-class RackRequestContentTypeTest < BaseRackTest
- def test_html_content_type_verification
- @request.env['CONTENT_TYPE'] = Mime::HTML.to_s
- assert @request.content_type.verify_request?
- end
-
- def test_xml_content_type_verification
- @request.env['CONTENT_TYPE'] = Mime::XML.to_s
- assert !@request.content_type.verify_request?
- end
-end
-
-class RackRequestNeedsRewoundTest < BaseRackTest
- def test_body_should_be_rewound
- data = 'foo'
- @env['rack.input'] = StringIO.new(data)
- @env['CONTENT_LENGTH'] = data.length
- @env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
-
- # Read the request body by parsing params.
- request = ActionController::Request.new(@env)
- request.request_parameters
-
- # Should have rewound the body.
- assert_equal 0, request.body.pos
- end
-end
-
-class RackResponseTest < BaseRackTest
- def setup
- super
- @response = ActionController::Response.new
- end
-
- def test_simple_output
- @response.body = "Hello, World!"
- @response.prepare!
-
- status, headers, body = @response.to_a
- assert_equal 200, status
- assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "private, max-age=0, must-revalidate",
- "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
- "Set-Cookie" => "",
- "Content-Length" => "13"
- }, headers)
-
- parts = []
- body.each { |part| parts << part }
- assert_equal ["Hello, World!"], parts
- end
-
- def test_utf8_output
- @response.body = [1090, 1077, 1089, 1090].pack("U*")
- @response.prepare!
-
- status, headers, body = @response.to_a
- assert_equal 200, status
- assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "private, max-age=0, must-revalidate",
- "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
- "Set-Cookie" => "",
- "Content-Length" => "8"
- }, headers)
- end
-
- def test_streaming_block
- @response.body = Proc.new do |response, output|
- 5.times { |n| output.write(n) }
- end
- @response.prepare!
-
- status, headers, body = @response.to_a
- assert_equal 200, status
- assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "no-cache",
- "Set-Cookie" => ""
- }, headers)
-
- parts = []
- body.each { |part| parts << part.to_s }
- assert_equal ["0", "1", "2", "3", "4"], parts
- end
-end
-
-class RackResponseHeadersTest < BaseRackTest
- def setup
- super
- @response = ActionController::Response.new
- @response.status = "200 OK"
- end
-
- def test_content_type
- [204, 304].each do |c|
- @response.status = c.to_s
- assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
- end
-
- [200, 302, 404, 500].each do |c|
- @response.status = c.to_s
- assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
- end
- end
-
- def test_status
- assert !response_headers.has_key?('Status')
- end
-
- private
- def response_headers
- @response.prepare!
- @response.to_a[1]
- end
-end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index a52931565d..9a34bcebe6 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -315,13 +315,6 @@ class TestController < ActionController::Base
def render_implicit_html_template_from_xhr_request
end
- def render_implicit_js_template_without_layout
- end
-
- def render_html_explicit_template_and_layout
- render :template => 'test/render_implicit_html_template_from_xhr_request', :layout => 'layouts/default_html'
- end
-
def formatted_html_erb
end
@@ -390,7 +383,7 @@ class TestController < ActionController::Base
end
def accessing_params_in_template_with_layout
- render :layout => nil, :inline => "Hello: <%= params[:name] %>"
+ render :layout => true, :inline => "Hello: <%= params[:name] %>"
end
def render_with_explicit_template
@@ -737,8 +730,6 @@ class TestController < ActionController::Base
"delete_with_js", "update_page", "update_page_with_instance_variables"
"layouts/standard"
- when "render_implicit_js_template_without_layout"
- "layouts/default_html"
when "action_talk_to_layout", "layout_overriding_layout"
"layouts/talk_from_action"
when "render_implicit_html_template_from_xhr_request"
@@ -753,6 +744,7 @@ class RenderTest < ActionController::TestCase
def setup
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
+ super
@controller.logger = Logger.new(nil)
@request.host = "www.nextangle.com"
@@ -836,11 +828,6 @@ class RenderTest < ActionController::TestCase
assert_equal "<html>hello world, I'm here!</html>", @response.body
end
- def test_xhr_with_render_text_and_layout
- xhr :get, :render_text_hello_world_with_layout
- assert_equal "<html>hello world, I'm here!</html>", @response.body
- end
-
def test_do_with_render_action_and_layout_false
get :hello_world_with_layout_false
assert_equal 'Hello world!', @response.body
@@ -1081,18 +1068,17 @@ class RenderTest < ActionController::TestCase
end
def test_should_implicitly_render_html_template_from_xhr_request
- xhr :get, :render_implicit_html_template_from_xhr_request
- assert_equal "XHR!\nHello HTML!", @response.body
- end
-
- def test_should_render_explicit_html_template_with_html_layout
- xhr :get, :render_html_explicit_template_and_layout
- assert_equal "<html>Hello HTML!</html>\n", @response.body
+ pending do
+ xhr :get, :render_implicit_html_template_from_xhr_request
+ assert_equal "XHR!\nHello HTML!", @response.body
+ end
end
def test_should_implicitly_render_js_template_without_layout
- get :render_implicit_js_template_without_layout, :format => :js
- assert_no_match /<html>/, @response.body
+ pending do
+ get :render_implicit_js_template_without_layout, :format => :js
+ assert_no_match %r{<html>}, @response.body
+ end
end
def test_should_render_formatted_template
@@ -1308,7 +1294,7 @@ class RenderTest < ActionController::TestCase
assert !@response.headers.include?('Content-Length')
assert_response :no_content
- ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
+ ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
get :head_with_symbolic_status, :status => status.to_s
assert_equal code, @response.response_code
assert_response status
@@ -1316,7 +1302,7 @@ class RenderTest < ActionController::TestCase
end
def test_head_with_integer_status
- ActionController::StatusCodes::STATUS_CODES.each do |code, message|
+ ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message|
get :head_with_integer_status, :status => code.to_s
assert_equal message, @response.message
end
@@ -1574,6 +1560,7 @@ class EtagRenderTest < ActionController::TestCase
tests TestController
def setup
+ super
@request.host = "www.nextangle.com"
@expected_bang_etag = etag_for(expand_key([:foo, 123]))
end
@@ -1684,6 +1671,7 @@ class LastModifiedRenderTest < ActionController::TestCase
tests TestController
def setup
+ super
@request.host = "www.nextangle.com"
@last_modified = Time.now.utc.beginning_of_day.httpdate
end
@@ -1739,6 +1727,7 @@ class RenderingLoggingTest < ActionController::TestCase
tests TestController
def setup
+ super
@request.host = "www.nextangle.com"
end
@@ -1746,7 +1735,7 @@ class RenderingLoggingTest < ActionController::TestCase
@controller.logger = MockLogger.new
get :layout_test
logged = @controller.logger.logged.find_all {|l| l =~ /render/i }
- assert_equal "Rendering template within layouts/standard", logged[0]
- assert_equal "Rendering test/hello_world", logged[1]
+ assert_equal "Rendering test/hello_world", logged[0]
+ assert_equal "Rendering template within layouts/standard", logged[1]
end
end
diff --git a/actionpack/test/controller/request/json_params_parsing_test.rb b/actionpack/test/controller/request/json_params_parsing_test.rb
deleted file mode 100644
index a3dde72c4e..0000000000
--- a/actionpack/test/controller/request/json_params_parsing_test.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'abstract_unit'
-
-class JsonParamsParsingTest < ActionController::IntegrationTest
- class TestController < ActionController::Base
- class << self
- attr_accessor :last_request_parameters
- end
-
- def parse
- self.class.last_request_parameters = request.request_parameters
- head :ok
- end
- end
-
- def teardown
- TestController.last_request_parameters = nil
- end
-
- test "parses json params for application json" do
- assert_parses(
- {"person" => {"name" => "David"}},
- "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/json' }
- )
- end
-
- test "parses json params for application jsonrequest" do
- assert_parses(
- {"person" => {"name" => "David"}},
- "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/jsonrequest' }
- )
- end
-
- private
- def assert_parses(expected, actual, headers = {})
- with_routing do |set|
- set.draw do |map|
- map.connect ':action', :controller => "json_params_parsing_test/test"
- end
-
- post "/parse", actual, headers
- assert_response :ok
- assert_equal(expected, TestController.last_request_parameters)
- end
- end
-end
diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb
deleted file mode 100644
index b812072ef4..0000000000
--- a/actionpack/test/controller/request/multipart_params_parsing_test.rb
+++ /dev/null
@@ -1,223 +0,0 @@
-require 'abstract_unit'
-
-class MultipartParamsParsingTest < ActionController::IntegrationTest
- class TestController < ActionController::Base
- class << self
- attr_accessor :last_request_parameters
- end
-
- def parse
- self.class.last_request_parameters = request.request_parameters
- head :ok
- end
-
- def read
- render :text => "File: #{params[:uploaded_data].read}"
- end
- end
-
- FIXTURE_PATH = File.dirname(__FILE__) + '/../../fixtures/multipart'
-
- def teardown
- TestController.last_request_parameters = nil
- end
-
- test "parses single parameter" do
- assert_equal({ 'foo' => 'bar' }, parse_multipart('single_parameter'))
- end
-
- test "parses bracketed parameters" do
- assert_equal({ 'foo' => { 'baz' => 'bar'}}, parse_multipart('bracketed_param'))
- end
-
- test "parses text file" do
- params = parse_multipart('text_file')
- assert_equal %w(file foo), params.keys.sort
- assert_equal 'bar', params['foo']
-
- file = params['file']
- assert_kind_of Tempfile, file
- assert_equal 'file.txt', file.original_filename
- assert_equal "text/plain", file.content_type
- assert_equal 'contents', file.read
- end
-
- test "parses boundary problem file" do
- params = parse_multipart('boundary_problem_file')
- assert_equal %w(file foo), params.keys.sort
-
- file = params['file']
- foo = params['foo']
-
- assert_kind_of Tempfile, file
-
- assert_equal 'file.txt', file.original_filename
- assert_equal "text/plain", file.content_type
-
- assert_equal 'bar', foo
- end
-
- test "parses large text file" do
- params = parse_multipart('large_text_file')
- assert_equal %w(file foo), params.keys.sort
- assert_equal 'bar', params['foo']
-
- file = params['file']
-
- assert_kind_of Tempfile, file
-
- assert_equal 'file.txt', file.original_filename
- assert_equal "text/plain", file.content_type
- assert ('a' * 20480) == file.read
- end
-
- test "parses binary file" do
- params = parse_multipart('binary_file')
- assert_equal %w(file flowers foo), params.keys.sort
- assert_equal 'bar', params['foo']
-
- file = params['file']
- assert_kind_of Tempfile, file
- assert_equal 'file.csv', file.original_filename
- assert_nil file.content_type
- assert_equal 'contents', file.read
-
- file = params['flowers']
- assert_kind_of Tempfile, file
- assert_equal 'flowers.jpg', file.original_filename
- assert_equal "image/jpeg", file.content_type
- assert_equal 19512, file.size
- end
-
- test "parses mixed files" do
- params = parse_multipart('mixed_files')
- assert_equal %w(files foo), params.keys.sort
- assert_equal 'bar', params['foo']
-
- # Ruby CGI doesn't handle multipart/mixed for us.
- files = params['files']
- assert_kind_of String, files
- files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding)
- assert_equal 19756, files.size
- end
-
- test "does not create tempfile if no file has been selected" do
- params = parse_multipart('none')
- assert_equal %w(submit-name), params.keys.sort
- assert_equal 'Larry', params['submit-name']
- assert_equal nil, params['files']
- end
-
- test "parses empty upload file" do
- params = parse_multipart('empty')
- assert_equal %w(files submit-name), params.keys.sort
- assert_equal 'Larry', params['submit-name']
- assert params['files']
- assert_equal "", params['files'].read
- end
-
- test "uploads and reads binary file" do
- with_test_routing do
- fixture = FIXTURE_PATH + "/mona_lisa.jpg"
- params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") }
- post '/read', params
- expected_length = 'File: '.length + File.size(fixture)
- assert_equal expected_length, response.content_length
- end
- end
-
- test "uploads and reads file" do
- with_test_routing do
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
- assert_equal "File: Hello", response.body
- end
- end
-
- # The lint wrapper is used in integration tests
- # instead of a normal StringIO class
- InputWrapper = Rack::Lint::InputWrapper
-
- test "parses unwindable stream" do
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
- params = parse_multipart('large_text_file')
- assert_equal %w(file foo), params.keys.sort
- assert_equal 'bar', params['foo']
- end
-
- test "uploads and reads file with unwindable input" do
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
-
- with_test_routing do
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
- assert_equal "File: Hello", response.body
- end
- end
-
- test "passes through rack middleware and uploads file" do
- with_muck_middleware do
- with_test_routing do
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
- assert_equal "File: Hello", response.body
- end
- end
- end
-
- test "passes through rack middleware and uploads file with unwindable input" do
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
-
- with_muck_middleware do
- with_test_routing do
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
- assert_equal "File: Hello", response.body
- end
- end
- end
-
- private
- def fixture(name)
- File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
- { "rack.input" => file.read,
- "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x",
- "CONTENT_LENGTH" => file.stat.size.to_s }
- end
- end
-
- def parse_multipart(name)
- with_test_routing do
- headers = fixture(name)
- post "/parse", headers.delete("rack.input"), headers
- assert_response :ok
- TestController.last_request_parameters
- end
- end
-
- def with_test_routing
- with_routing do |set|
- set.draw do |map|
- map.connect ':action', :controller => "multipart_params_parsing_test/test"
- end
- yield
- end
- end
-
- class MuckMiddleware
- def initialize(app)
- @app = app
- end
-
- def call(env)
- req = Rack::Request.new(env)
- req.params # Parse params
- @app.call(env)
- end
- end
-
- def with_muck_middleware
- original_middleware = ActionController::Dispatcher.middleware
- middleware = original_middleware.dup
- middleware.insert_after ActionController::RewindableInput, MuckMiddleware
- ActionController::Dispatcher.middleware = middleware
- yield
- ActionController::Dispatcher.middleware = original_middleware
- end
-end
diff --git a/actionpack/test/controller/request/query_string_parsing_test.rb b/actionpack/test/controller/request/query_string_parsing_test.rb
deleted file mode 100644
index a31e326ddf..0000000000
--- a/actionpack/test/controller/request/query_string_parsing_test.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-require 'abstract_unit'
-
-class QueryStringParsingTest < ActionController::IntegrationTest
- class TestController < ActionController::Base
- class << self
- attr_accessor :last_query_parameters
- end
-
- def parse
- self.class.last_query_parameters = request.query_parameters
- head :ok
- end
- end
-
- def teardown
- TestController.last_query_parameters = nil
- end
-
- test "query string" do
- assert_parses(
- {"action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"},
- "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
- )
- end
-
- test "deep query string" do
- assert_parses(
- {'x' => {'y' => {'z' => '10'}}},
- "x[y][z]=10"
- )
- end
-
- test "deep query string with array" do
- assert_parses({'x' => {'y' => {'z' => ['10']}}}, 'x[y][z][]=10')
- assert_parses({'x' => {'y' => {'z' => ['10', '5']}}}, 'x[y][z][]=10&x[y][z][]=5')
- end
-
- test "deep query string with array of hash" do
- assert_parses({'x' => {'y' => [{'z' => '10'}]}}, 'x[y][][z]=10')
- assert_parses({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, 'x[y][][z]=10&x[y][][w]=10')
- assert_parses({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, 'x[y][][z]=10&x[y][][v][w]=10')
- end
-
- test "deep query string with array of hashes with one pair" do
- assert_parses({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, 'x[y][][z]=10&x[y][][z]=20')
- end
-
- test "deep query string with array of hashes with multiple pairs" do
- assert_parses(
- {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}},
- 'x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b'
- )
- end
-
- test "query string with nil" do
- assert_parses(
- { "action" => "create_customer", "full_name" => ''},
- "action=create_customer&full_name="
- )
- end
-
- test "query string with array" do
- assert_parses(
- { "action" => "create_customer", "selected" => ["1", "2", "3"]},
- "action=create_customer&selected[]=1&selected[]=2&selected[]=3"
- )
- end
-
- test "query string with amps" do
- assert_parses(
- { "action" => "create_customer", "name" => "Don't & Does"},
- "action=create_customer&name=Don%27t+%26+Does"
- )
- end
-
- test "query string with many equal" do
- assert_parses(
- { "action" => "create_customer", "full_name" => "abc=def=ghi"},
- "action=create_customer&full_name=abc=def=ghi"
- )
- end
-
- test "query string without equal" do
- assert_parses({ "action" => nil }, "action")
- end
-
- test "query string with empty key" do
- assert_parses(
- { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },
- "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save"
- )
- end
-
- test "query string with many ampersands" do
- assert_parses(
- { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"},
- "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson"
- )
- end
-
- test "unbalanced query string with array" do
- assert_parses(
- {'location' => ["1", "2"], 'age_group' => ["2"]},
- "location[]=1&location[]=2&age_group[]=2"
- )
- end
-
- private
- def assert_parses(expected, actual)
- with_routing do |set|
- set.draw do |map|
- map.connect ':action', :controller => "query_string_parsing_test/test"
- end
-
- get "/parse", actual
- assert_response :ok
- assert_equal(expected, TestController.last_query_parameters)
- end
- end
-end
diff --git a/actionpack/test/controller/request/test_request_test.rb b/actionpack/test/controller/request/test_request_test.rb
new file mode 100644
index 0000000000..81551b4ba7
--- /dev/null
+++ b/actionpack/test/controller/request/test_request_test.rb
@@ -0,0 +1,35 @@
+require 'abstract_unit'
+require 'stringio'
+
+class ActionController::TestRequestTest < ActiveSupport::TestCase
+
+ def setup
+ @request = ActionController::TestRequest.new
+ end
+
+ def test_test_request_has_session_options_initialized
+ assert @request.session_options
+ end
+
+ Rack::Session::Abstract::ID::DEFAULT_OPTIONS.each_key do |option|
+ test "test_rack_default_session_options_#{option}_exists_in_session_options_and_is_default" do
+ assert_equal(Rack::Session::Abstract::ID::DEFAULT_OPTIONS[option],
+ @request.session_options[option],
+ "Missing rack session default option #{option} in request.session_options")
+ end
+ test "test_rack_default_session_options_#{option}_exists_in_session_options" do
+ assert(@request.session_options.has_key?(option),
+ "Missing rack session option #{option} in request.session_options")
+ end
+ end
+
+ def test_session_id_exists_by_default
+ assert_not_nil(@request.session_options[:id])
+ end
+
+ def test_session_id_different_on_each_call
+ prev_id =
+ assert_not_equal(@request.session_options[:id], ActionController::TestRequest.new.session_options[:id])
+ end
+
+end \ No newline at end of file
diff --git a/actionpack/test/controller/request/url_encoded_params_parsing_test.rb b/actionpack/test/controller/request/url_encoded_params_parsing_test.rb
deleted file mode 100644
index 7e6099a041..0000000000
--- a/actionpack/test/controller/request/url_encoded_params_parsing_test.rb
+++ /dev/null
@@ -1,184 +0,0 @@
-require 'abstract_unit'
-
-class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
- class TestController < ActionController::Base
- class << self
- attr_accessor :last_request_parameters, :last_request_type
- end
-
- def parse
- self.class.last_request_parameters = request.request_parameters
- head :ok
- end
- end
-
- def teardown
- TestController.last_request_parameters = nil
- end
-
- test "parses unbalanced query string with array" do
- assert_parses(
- {'location' => ["1", "2"], 'age_group' => ["2"]},
- "location[]=1&location[]=2&age_group[]=2"
- )
- end
-
- test "parses nested hash" do
- query = [
- "note[viewers][viewer][][type]=User",
- "note[viewers][viewer][][id]=1",
- "note[viewers][viewer][][type]=Group",
- "note[viewers][viewer][][id]=2"
- ].join("&")
-
- expected = { "note" => { "viewers"=>{"viewer"=>[{ "id"=>"1", "type"=>"User"}, {"type"=>"Group", "id"=>"2"} ]} } }
- assert_parses(expected, query)
- end
-
- test "parses more complex nesting" do
- query = [
- "customers[boston][first][name]=David",
- "customers[boston][first][url]=http://David",
- "customers[boston][second][name]=Allan",
- "customers[boston][second][url]=http://Allan",
- "something_else=blah",
- "something_nil=",
- "something_empty=",
- "products[first]=Apple Computer",
- "products[second]=Pc",
- "=Save"
- ].join("&")
-
- expected = {
- "customers" => {
- "boston" => {
- "first" => {
- "name" => "David",
- "url" => "http://David"
- },
- "second" => {
- "name" => "Allan",
- "url" => "http://Allan"
- }
- }
- },
- "something_else" => "blah",
- "something_empty" => "",
- "something_nil" => "",
- "products" => {
- "first" => "Apple Computer",
- "second" => "Pc"
- }
- }
-
- assert_parses expected, query
- end
-
- test "parses params with array" do
- query = "selected[]=1&selected[]=2&selected[]=3"
- expected = { "selected" => [ "1", "2", "3" ] }
- assert_parses expected, query
- end
-
- test "parses params with nil key" do
- query = "=&test2=value1"
- expected = { "test2" => "value1" }
- assert_parses expected, query
- end
-
- test "parses params with array prefix and hashes" do
- query = "a[][b][c]=d"
- expected = {"a" => [{"b" => {"c" => "d"}}]}
- assert_parses expected, query
- end
-
- test "parses params with complex nesting" do
- query = "a[][b][c][][d][]=e"
- expected = {"a" => [{"b" => {"c" => [{"d" => ["e"]}]}}]}
- assert_parses expected, query
- end
-
- test "parses params with file path" do
- query = [
- "customers[boston][first][name]=David",
- "something_else=blah",
- "logo=#{File.expand_path(__FILE__)}"
- ].join("&")
-
- expected = {
- "customers" => {
- "boston" => {
- "first" => {
- "name" => "David"
- }
- }
- },
- "something_else" => "blah",
- "logo" => File.expand_path(__FILE__),
- }
-
- assert_parses expected, query
- end
-
- test "parses params with Safari 2 trailing null character" do
- query = "selected[]=1&selected[]=2&selected[]=3\0"
- expected = { "selected" => [ "1", "2", "3" ] }
- assert_parses expected, query
- end
-
- test "passes through rack middleware and parses params" do
- with_muck_middleware do
- assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
- end
- end
-
- # The lint wrapper is used in integration tests
- # instead of a normal StringIO class
- InputWrapper = Rack::Lint::InputWrapper
-
- test "passes through rack middleware and parses params with unwindable input" do
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
- with_muck_middleware do
- assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
- end
- end
-
- private
- class MuckMiddleware
- def initialize(app)
- @app = app
- end
-
- def call(env)
- req = Rack::Request.new(env)
- req.params # Parse params
- @app.call(env)
- end
- end
-
- def with_muck_middleware
- original_middleware = ActionController::Dispatcher.middleware
- middleware = original_middleware.dup
- middleware.insert_after ActionController::RewindableInput, MuckMiddleware
- ActionController::Dispatcher.middleware = middleware
- yield
- ActionController::Dispatcher.middleware = original_middleware
- end
-
- def with_test_routing
- with_routing do |set|
- set.draw do |map|
- map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
- end
- yield
- end
- end
-
- def assert_parses(expected, actual)
- with_test_routing do
- post "/parse", actual
- assert_response :ok
- assert_equal(expected, TestController.last_request_parameters)
- end
- end
-end
diff --git a/actionpack/test/controller/request/xml_params_parsing_test.rb b/actionpack/test/controller/request/xml_params_parsing_test.rb
deleted file mode 100644
index ee764e726e..0000000000
--- a/actionpack/test/controller/request/xml_params_parsing_test.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'abstract_unit'
-
-class XmlParamsParsingTest < ActionController::IntegrationTest
- class TestController < ActionController::Base
- class << self
- attr_accessor :last_request_parameters
- end
-
- def parse
- self.class.last_request_parameters = request.request_parameters
- head :ok
- end
- end
-
- def teardown
- TestController.last_request_parameters = nil
- end
-
- test "parses hash params" do
- with_test_routing do
- xml = "<person><name>David</name></person>"
- post "/parse", xml, default_headers
- assert_response :ok
- assert_equal({"person" => {"name" => "David"}}, TestController.last_request_parameters)
- end
- end
-
- test "parses single file" do
- with_test_routing do
- xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>"
- post "/parse", xml, default_headers
- assert_response :ok
-
- person = TestController.last_request_parameters
- assert_equal "image/jpg", person['person']['avatar'].content_type
- assert_equal "me.jpg", person['person']['avatar'].original_filename
- assert_equal "ABC", person['person']['avatar'].read
- end
- end
-
- test "parses multiple files" do
- xml = <<-end_body
- <person>
- <name>David</name>
- <avatars>
- <avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar>
- <avatar type='file' name='you.gif' content_type='image/gif'>#{ActiveSupport::Base64.encode64('DEF')}</avatar>
- </avatars>
- </person>
- end_body
-
- with_test_routing do
- post "/parse", xml, default_headers
- assert_response :ok
- end
-
- person = TestController.last_request_parameters
-
- assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type
- assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename
- assert_equal "ABC", person['person']['avatars']['avatar'].first.read
-
- assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type
- assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename
- assert_equal "DEF", person['person']['avatars']['avatar'].last.read
- end
-
- private
- def with_test_routing
- with_routing do |set|
- set.draw do |map|
- map.connect ':action', :controller => "xml_params_parsing_test/test"
- end
- yield
- end
- end
-
- def default_headers
- {'CONTENT_TYPE' => 'application/xml'}
- end
-end
-
-class LegacyXmlParamsParsingTest < XmlParamsParsingTest
- private
- def default_headers
- {'HTTP_X_POST_DATA_FORMAT' => 'xml'}
- end
-end
diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb
index 835e73e3ab..83925ed4db 100644
--- a/actionpack/test/controller/request_forgery_protection_test.rb
+++ b/actionpack/test/controller/request_forgery_protection_test.rb
@@ -151,14 +151,10 @@ module RequestForgeryProtectionTests
delete :index, :format => 'xml'
end
end
-
+
def test_should_allow_xhr_post_without_token
assert_nothing_raised { xhr :post, :index }
end
- def test_should_not_allow_xhr_post_with_html_without_token
- @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
- assert_raise(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
- end
def test_should_allow_xhr_put_without_token
assert_nothing_raised { xhr :put, :index }
@@ -168,6 +164,11 @@ module RequestForgeryProtectionTests
assert_nothing_raised { xhr :delete, :index }
end
+ def test_should_allow_xhr_post_with_encoded_form_content_type_without_token
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
+ assert_nothing_raised { xhr :post, :index }
+ end
+
def test_should_allow_post_with_token
post :index, :authenticity_token => @token
assert_response :success
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
deleted file mode 100644
index c72f885a05..0000000000
--- a/actionpack/test/controller/request_test.rb
+++ /dev/null
@@ -1,407 +0,0 @@
-require 'abstract_unit'
-
-class RequestTest < ActiveSupport::TestCase
- def setup
- ActionController::Base.relative_url_root = nil
- @request = ActionController::TestRequest.new
- end
-
- def teardown
- ActionController::Base.relative_url_root = nil
- end
-
- def test_remote_ip
- assert_equal '0.0.0.0', @request.remote_ip
-
- @request.remote_addr = '1.2.3.4'
- assert_equal '1.2.3.4', @request.remote_ip
-
- @request.remote_addr = '1.2.3.4,3.4.5.6'
- assert_equal '1.2.3.4', @request.remote_ip
-
- @request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
- assert_equal '1.2.3.4', @request.remote_ip
-
- @request.remote_addr = '192.168.0.1'
- assert_equal '2.3.4.5', @request.remote_ip
- @request.env.delete 'HTTP_CLIENT_IP'
-
- @request.remote_addr = '1.2.3.4'
- @request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
- assert_equal '1.2.3.4', @request.remote_ip
-
- @request.remote_addr = '127.0.0.1'
- @request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '172.16.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '192.168.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.1, 3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
- assert_equal 'unknown', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
- e = assert_raise(ActionController::ActionControllerError) {
- @request.remote_ip
- }
- assert_match /IP spoofing attack/, e.message
- assert_match /HTTP_X_FORWARDED_FOR="9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4"/, e.message
- assert_match /HTTP_CLIENT_IP="8.8.8.8"/, e.message
-
- # turn IP Spoofing detection off.
- # This is useful for sites that are aimed at non-IP clients. The typical
- # example is WAP. Since the cellular network is not IP based, it's a
- # leap of faith to assume that their proxies are ever going to set the
- # HTTP_CLIENT_IP/HTTP_X_FORWARDED_FOR headers properly.
- ActionController::Base.ip_spoofing_check = false
- assert_equal('8.8.8.8', @request.remote_ip)
- ActionController::Base.ip_spoofing_check = true
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '8.8.8.8, 9.9.9.9'
- assert_equal '8.8.8.8', @request.remote_ip
-
- @request.env.delete 'HTTP_CLIENT_IP'
- @request.env.delete 'HTTP_X_FORWARDED_FOR'
- end
-
- def test_domains
- @request.host = "www.rubyonrails.org"
- assert_equal "rubyonrails.org", @request.domain
-
- @request.host = "www.rubyonrails.co.uk"
- assert_equal "rubyonrails.co.uk", @request.domain(2)
-
- @request.host = "192.168.1.200"
- assert_nil @request.domain
-
- @request.host = "foo.192.168.1.200"
- assert_nil @request.domain
-
- @request.host = "192.168.1.200.com"
- assert_equal "200.com", @request.domain
-
- @request.host = nil
- assert_nil @request.domain
- end
-
- def test_subdomains
- @request.host = "www.rubyonrails.org"
- assert_equal %w( www ), @request.subdomains
-
- @request.host = "www.rubyonrails.co.uk"
- assert_equal %w( www ), @request.subdomains(2)
-
- @request.host = "dev.www.rubyonrails.co.uk"
- assert_equal %w( dev www ), @request.subdomains(2)
-
- @request.host = "foobar.foobar.com"
- assert_equal %w( foobar ), @request.subdomains
-
- @request.host = "192.168.1.200"
- assert_equal [], @request.subdomains
-
- @request.host = "foo.192.168.1.200"
- assert_equal [], @request.subdomains
-
- @request.host = "192.168.1.200.com"
- assert_equal %w( 192 168 1 ), @request.subdomains
-
- @request.host = nil
- assert_equal [], @request.subdomains
- end
-
- def test_port_string
- @request.port = 80
- assert_equal "", @request.port_string
-
- @request.port = 8080
- assert_equal ":8080", @request.port_string
- end
-
- def test_request_uri
- @request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432'
-
- @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
-
- @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri"
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
-
- @request.set_REQUEST_URI "/path/of/some/uri"
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
-
- @request.set_REQUEST_URI "/"
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
-
- @request.set_REQUEST_URI "/?m=b"
- assert_equal "/?m=b", @request.request_uri
- assert_equal "/", @request.path
-
- @request.set_REQUEST_URI "/"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
-
- ActionController::Base.relative_url_root = "/hieraki"
- @request.set_REQUEST_URI "/hieraki/"
- @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
- assert_equal "/hieraki/", @request.request_uri
- assert_equal "/", @request.path
- ActionController::Base.relative_url_root = nil
-
- ActionController::Base.relative_url_root = "/collaboration/hieraki"
- @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
- @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
- assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
- assert_equal "/books/edit/2", @request.path
- ActionController::Base.relative_url_root = nil
-
- # The following tests are for when REQUEST_URI is not supplied (as in IIS)
- @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
- @request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
-
- ActionController::Base.relative_url_root = '/path'
- @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
- @request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/of/some/uri", @request.path
- ActionController::Base.relative_url_root = nil
-
- @request.env['PATH_INFO'] = "/path/of/some/uri"
- @request.env['SCRIPT_NAME'] = nil
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
-
- @request.env['PATH_INFO'] = "/"
- @request.set_REQUEST_URI nil
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
-
- @request.env['PATH_INFO'] = "/?m=b"
- @request.set_REQUEST_URI nil
- assert_equal "/?m=b", @request.request_uri
- assert_equal "/", @request.path
-
- @request.env['PATH_INFO'] = "/"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- @request.set_REQUEST_URI nil
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
-
- ActionController::Base.relative_url_root = '/hieraki'
- @request.env['PATH_INFO'] = "/hieraki/"
- @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
- @request.set_REQUEST_URI nil
- assert_equal "/hieraki/", @request.request_uri
- assert_equal "/", @request.path
- ActionController::Base.relative_url_root = nil
-
- @request.set_REQUEST_URI '/hieraki/dispatch.cgi'
- ActionController::Base.relative_url_root = '/hieraki'
- assert_equal "/dispatch.cgi", @request.path
- ActionController::Base.relative_url_root = nil
-
- @request.set_REQUEST_URI '/hieraki/dispatch.cgi'
- ActionController::Base.relative_url_root = '/foo'
- assert_equal "/hieraki/dispatch.cgi", @request.path
- ActionController::Base.relative_url_root = nil
-
- # This test ensures that Rails uses REQUEST_URI over PATH_INFO
- ActionController::Base.relative_url_root = nil
- @request.env['REQUEST_URI'] = "/some/path"
- @request.env['PATH_INFO'] = "/another/path"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- assert_equal "/some/path", @request.request_uri
- assert_equal "/some/path", @request.path
- end
-
- def test_host_with_default_port
- @request.host = "rubyonrails.org"
- @request.port = 80
- assert_equal "rubyonrails.org", @request.host_with_port
- end
-
- def test_host_with_non_default_port
- @request.host = "rubyonrails.org"
- @request.port = 81
- assert_equal "rubyonrails.org:81", @request.host_with_port
- end
-
- def test_server_software
- assert_equal nil, @request.server_software
-
- @request.env['SERVER_SOFTWARE'] = 'Apache3.422'
- assert_equal 'apache', @request.server_software
-
- @request.env['SERVER_SOFTWARE'] = 'lighttpd(1.1.4)'
- assert_equal 'lighttpd', @request.server_software
- end
-
- def test_xml_http_request
- assert !@request.xml_http_request?
- assert !@request.xhr?
-
- @request.env['HTTP_X_REQUESTED_WITH'] = "DefinitelyNotAjax1.0"
- assert !@request.xml_http_request?
- assert !@request.xhr?
-
- @request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"
- assert @request.xml_http_request?
- assert @request.xhr?
- end
-
- def test_reports_ssl
- assert !@request.ssl?
- @request.env['HTTPS'] = 'on'
- assert @request.ssl?
- end
-
- def test_reports_ssl_when_proxied_via_lighttpd
- assert !@request.ssl?
- @request.env['HTTP_X_FORWARDED_PROTO'] = 'https'
- assert @request.ssl?
- end
-
- def test_symbolized_request_methods
- [:get, :post, :put, :delete].each do |method|
- self.request_method = method
- assert_equal method, @request.method
- end
- end
-
- def test_invalid_http_method_raises_exception
- assert_raise(ActionController::UnknownHttpMethod) do
- self.request_method = :random_method
- @request.request_method
- end
- end
-
- def test_allow_method_hacking_on_post
- [:get, :head, :options, :put, :post, :delete].each do |method|
- self.request_method = method
- assert_equal(method == :head ? :get : method, @request.method)
- end
- end
-
- def test_invalid_method_hacking_on_post_raises_exception
- assert_raise(ActionController::UnknownHttpMethod) do
- self.request_method = :_random_method
- @request.request_method
- end
- end
-
- def test_restrict_method_hacking
- @request.instance_eval { @parameters = { :_method => 'put' } }
- [:get, :put, :delete].each do |method|
- self.request_method = method
- assert_equal method, @request.method
- end
- end
-
- def test_head_masquerading_as_get
- self.request_method = :head
- assert_equal :get, @request.method
- assert @request.get?
- assert @request.head?
- end
-
- def test_xml_format
- @request.instance_eval { @parameters = { :format => 'xml' } }
- assert_equal Mime::XML, @request.format
- end
-
- def test_xhtml_format
- @request.instance_eval { @parameters = { :format => 'xhtml' } }
- assert_equal Mime::HTML, @request.format
- end
-
- def test_txt_format
- @request.instance_eval { @parameters = { :format => 'txt' } }
- assert_equal Mime::TEXT, @request.format
- end
-
- def test_nil_format
- ActionController::Base.use_accept_header, old =
- false, ActionController::Base.use_accept_header
-
- @request.instance_eval { @parameters = {} }
- @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
- assert @request.xhr?
- assert_equal Mime::JS, @request.format
-
- ensure
- ActionController::Base.use_accept_header = old
- end
-
- def test_content_type
- @request.env["CONTENT_TYPE"] = "text/html"
- assert_equal Mime::HTML, @request.content_type
- end
-
- def test_format_assignment_should_set_format
- @request.instance_eval { self.format = :txt }
- assert !@request.format.xml?
- @request.instance_eval { self.format = :xml }
- assert @request.format.xml?
- end
-
- def test_content_no_type
- assert_equal nil, @request.content_type
- end
-
- def test_content_type_xml
- @request.env["CONTENT_TYPE"] = "application/xml"
- assert_equal Mime::XML, @request.content_type
- end
-
- def test_content_type_with_charset
- @request.env["CONTENT_TYPE"] = "application/xml; charset=UTF-8"
- assert_equal Mime::XML, @request.content_type
- end
-
- def test_user_agent
- assert_not_nil @request.user_agent
- end
-
- def test_parameters
- @request.stubs(:request_parameters).returns({ "foo" => 1 })
- @request.stubs(:query_parameters).returns({ "bar" => 2 })
-
- assert_equal({"foo" => 1, "bar" => 2}, @request.parameters)
- assert_equal({"foo" => 1}, @request.request_parameters)
- assert_equal({"bar" => 2}, @request.query_parameters)
- end
-
- protected
- def request_method=(method)
- @request.env['REQUEST_METHOD'] = method.to_s.upcase
- @request.request_method = nil # Reset the ivar cache
- end
-end
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 5709f37e05..741b01caa8 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -141,8 +141,11 @@ end
class RescueControllerTest < ActionController::TestCase
FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures".freeze
- setup :set_all_requests_local
- setup :populate_exception_object
+ def setup
+ super
+ set_all_requests_local
+ populate_exception_object
+ end
def set_all_requests_local
RescueController.consider_all_requests_local = true
@@ -409,7 +412,7 @@ class RescueControllerTest < ActionController::TestCase
def test_rescue_dispatcher_exceptions_without_request_set
@request.env['REQUEST_URI'] = '/no_way'
response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found"))
- assert_kind_of ActionController::Response, response
+ assert_kind_of ActionDispatch::Response, response
assert_equal "no way", response.body
end
diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb
index 3d1904fee9..2e14a0a32c 100644
--- a/actionpack/test/controller/send_file_test.rb
+++ b/actionpack/test/controller/send_file_test.rb
@@ -155,7 +155,7 @@ class SendFileTest < ActionController::TestCase
define_method "test_default_send_#{method}_status" do
@controller.options = { :stream => false }
assert_nothing_raised { assert_not_nil process(method) }
- assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status
+ assert_equal ActionController::DEFAULT_RENDER_STATUS_CODE, @response.status
end
end
end
diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb
index 48a961ca34..b9bf8cf411 100644
--- a/actionpack/test/controller/session/cookie_store_test.rb
+++ b/actionpack/test/controller/session/cookie_store_test.rb
@@ -6,7 +6,8 @@ class CookieStoreTest < ActionController::IntegrationTest
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
DispatcherApp = ActionController::Dispatcher.new
- CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret)
+ CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp,
+ :key => SessionKey, :secret => SessionSecret)
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
@@ -53,41 +54,41 @@ class CookieStoreTest < ActionController::IntegrationTest
def test_raises_argument_error_if_missing_session_key
assert_raise(ArgumentError, nil.inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => nil, :secret => SessionSecret)
}
assert_raise(ArgumentError, ''.inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => '', :secret => SessionSecret)
}
end
def test_raises_argument_error_if_missing_secret
assert_raise(ArgumentError, nil.inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => SessionKey, :secret => nil)
}
assert_raise(ArgumentError, ''.inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => SessionKey, :secret => '')
}
end
def test_raises_argument_error_if_secret_is_probably_insecure
assert_raise(ArgumentError, "password".inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => SessionKey, :secret => "password")
}
assert_raise(ArgumentError, "secret".inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => SessionKey, :secret => "secret")
}
assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
- ActionController::Session::CookieStore.new(nil,
+ ActionDispatch::Session::CookieStore.new(nil,
:key => SessionKey, :secret => "12345678901234567890123456789")
}
end
@@ -135,7 +136,7 @@ class CookieStoreTest < ActionController::IntegrationTest
def test_close_raises_when_data_overflows
with_test_route_set do
- assert_raise(ActionController::Session::CookieStore::CookieOverflow) {
+ assert_raise(ActionDispatch::Session::CookieStore::CookieOverflow) {
get '/raise_data_overflow'
}
end
@@ -194,23 +195,35 @@ class CookieStoreTest < ActionController::IntegrationTest
end
def test_session_store_with_expire_after
- app = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
+ app = ActionDispatch::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
@integration_session = open_session(app)
with_test_route_set do
# First request accesses the session
+ time = Time.local(2008, 4, 24)
+ Time.stubs(:now).returns(time)
+ expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
+
cookies[SessionKey] = SignedBar
get '/set_session_value'
assert_response :success
- cookie = headers['Set-Cookie']
- # Second request does not access the session so the
- # expires header should not be changed
+ cookie_body = response.body
+ assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
+ headers['Set-Cookie']
+
+ # Second request does not access the session
+ time = Time.local(2008, 4, 25)
+ Time.stubs(:now).returns(time)
+ expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
+
get '/no_session_access'
assert_response :success
- assert_equal cookie, headers['Set-Cookie'],
- "#{unmarshal_session(cookie).inspect} expected but was #{unmarshal_session(headers['Set-Cookie']).inspect}"
+
+ # Mystery bug that came up in 2.3 as well. What is this trying to test?!
+ # assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
+ # headers['Set-Cookie']
end
end
diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb
index 2f80a3c7c2..7561c93e4a 100644
--- a/actionpack/test/controller/session/mem_cache_store_test.rb
+++ b/actionpack/test/controller/session/mem_cache_store_test.rb
@@ -33,7 +33,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
begin
DispatcherApp = ActionController::Dispatcher.new
- MemCacheStoreApp = ActionController::Session::MemCacheStore.new(
+ MemCacheStoreApp = ActionDispatch::Session::MemCacheStore.new(
DispatcherApp, :key => '_session_id')
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 65c894c2e7..124e259ef6 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -119,6 +119,7 @@ XML
end
def setup
+ super
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -127,6 +128,7 @@ XML
end
def teardown
+ super
ActionController::Routing::Routes.reload
end
@@ -515,6 +517,14 @@ XML
assert_nil @request.instance_variable_get("@request_method")
end
+ def test_params_reset_after_post_request
+ post :no_op, :foo => "bar"
+ assert_equal "bar", @request.params[:foo]
+ @request.recycle!
+ post :no_op
+ assert @request.params[:foo].blank?
+ end
+
%w(controller response request).each do |variable|
%w(get post put delete head process).each do |method|
define_method("test_#{variable}_missing_for_#{method}_raises_error") do
@@ -635,7 +645,7 @@ class CleanBacktraceTest < ActionController::TestCase
end
def test_should_clean_assertion_lines_from_backtrace
- path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller")
+ path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller/testing")
exception = ActiveSupport::TestCase::Assertion.new('message')
exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
clean_backtrace { raise exception }
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 8ea13fbe98..1539f8f506 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -29,8 +29,8 @@ class ViewLoadPathsTest < ActionController::TestCase
@controller = TestController.new
# Following is needed in order to setup @controller.template object properly
- @controller.send :initialize_template_class, @response
@controller.send :assign_shortcuts, @request, @response
+ @controller.send :initialize_template_class, @response
# Track the last warning.
@old_behavior = ActiveSupport::Deprecation.behavior
@@ -41,7 +41,7 @@ class ViewLoadPathsTest < ActionController::TestCase
def teardown
ActiveSupport::Deprecation.behavior = @old_behavior
end
-
+
def test_template_load_path_was_set_correctly
assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
end