aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb22
-rw-r--r--actionpack/test/controller/caching_test.rb37
-rw-r--r--actionpack/test/controller/filters_test.rb25
-rw-r--r--actionpack/test/controller/integration_test.rb12
-rw-r--r--actionpack/test/controller/render_test.rb10
-rw-r--r--actionpack/test/controller/resources_test.rb8
-rw-r--r--actionpack/test/controller/routing_test.rb8
-rw-r--r--actionpack/test/controller/test_test.rb31
-rw-r--r--actionpack/test/dispatch/request_test.rb2
-rw-r--r--actionpack/test/dispatch/test_request_test.rb45
10 files changed, 134 insertions, 66 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index dd59999a0c..711640f9a9 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -305,24 +305,30 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
# check the empty flashing
def test_flash_me_naked
process :flash_me_naked
- assert !@response.has_flash?
- assert !@response.has_flash_with_contents?
+ assert_deprecated do
+ assert !@response.has_flash?
+ assert !@response.has_flash_with_contents?
+ end
end
# check if we have flash objects
def test_flash_haves
process :flash_me
- assert @response.has_flash?
- assert @response.has_flash_with_contents?
- assert @response.has_flash_object?('hello')
+ assert_deprecated do
+ assert @response.has_flash?
+ assert @response.has_flash_with_contents?
+ assert @response.has_flash_object?('hello')
+ end
end
# ensure we don't have flash objects
def test_flash_have_nots
process :nothing
- assert !@response.has_flash?
- assert !@response.has_flash_with_contents?
- assert_nil @response.flash['hello']
+ assert_deprecated do
+ assert !@response.has_flash?
+ assert !@response.has_flash_with_contents?
+ assert_nil @response.flash['hello']
+ end
end
# check if we were rendered by a file-based template?
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index b61a58dd09..10b904481d 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -1,5 +1,6 @@
require 'fileutils'
require 'abstract_unit'
+require 'active_record_unit'
CACHE_DIR = 'test_cache'
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
@@ -153,6 +154,7 @@ class ActionCachingTestController < ActionController::Base
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
caches_action :with_layout
caches_action :layout_false, :layout => false
+ caches_action :record_not_found, :four_oh_four, :simple_runtime_error
layout 'talk_from_action.erb'
@@ -175,6 +177,18 @@ class ActionCachingTestController < ActionController::Base
render :text => @cache_this, :layout => true
end
+ def record_not_found
+ raise ActiveRecord::RecordNotFound, "oops!"
+ end
+
+ def four_oh_four
+ render :text => "404'd!", :status => 404
+ end
+
+ def simple_runtime_error
+ raise "oops!"
+ end
+
alias_method :show, :index
alias_method :edit, :index
alias_method :destroy, :index
@@ -345,7 +359,7 @@ class ActionCacheTest < ActionController::TestCase
cached_time = content_to_cache
reset!
- @request.set_REQUEST_URI "/action_caching_test/expire.xml"
+ @request.request_uri = "/action_caching_test/expire.xml"
get :expire, :format => :xml
reset!
@@ -458,6 +472,27 @@ class ActionCacheTest < ActionController::TestCase
assert_response :success
end
+ def test_record_not_found_returns_404_for_multiple_requests
+ get :record_not_found
+ assert_response 404
+ get :record_not_found
+ assert_response 404
+ end
+
+ def test_four_oh_four_returns_404_for_multiple_requests
+ get :four_oh_four
+ assert_response 404
+ get :four_oh_four
+ assert_response 404
+ end
+
+ def test_simple_runtime_error_returns_500_for_multiple_requests
+ get :simple_runtime_error
+ assert_response 500
+ get :simple_runtime_error
+ assert_response 500
+ end
+
private
def content_to_cache
assigns(:cache_this)
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index aca7a821c8..9e74538310 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -2,6 +2,8 @@ require 'abstract_unit'
# FIXME: crashes Ruby 1.9
class FilterTest < Test::Unit::TestCase
+ include ActionController::TestProcess
+
class TestController < ActionController::Base
before_filter :ensure_login
after_filter :clean_up
@@ -669,12 +671,11 @@ class FilterTest < Test::Unit::TestCase
private
def test_process(controller, action = "show")
- ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
- request = ActionController::TestRequest.new
- request.action = action
- controller = controller.new if controller.is_a?(Class)
- @controller = controller
- @controller.process_with_test(request, ActionController::TestResponse.new)
+ @controller = controller.is_a?(Class) ? controller.new : controller
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ process(action)
end
end
@@ -810,6 +811,7 @@ end
class YieldingAroundFiltersTest < Test::Unit::TestCase
include PostsController::AroundExceptions
+ include ActionController::TestProcess
def test_filters_registering
assert_equal 1, ControllerWithFilterMethod.filter_chain.size
@@ -912,11 +914,10 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
protected
def test_process(controller, action = "show")
- ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
- request = ActionController::TestRequest.new
- request.action = action
- controller = controller.new if controller.is_a?(Class)
- @controller = controller
- @controller.process_with_test(request, ActionController::TestResponse.new)
+ @controller = controller.is_a?(Class) ? controller.new : controller
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ process(action)
end
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 70fa41aded..c616107324 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -30,7 +30,7 @@ class SessionTest < Test::Unit::TestCase
def test_request_via_redirect_uses_given_method
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
- @session.expects(:put).with(path, args, headers)
+ @session.expects(:process).with(:put, path, args, headers)
@session.stubs(:redirect?).returns(false)
@session.request_via_redirect(:put, path, args, headers)
end
@@ -90,16 +90,6 @@ class SessionTest < Test::Unit::TestCase
assert_equal '/show', @session.url_for(options)
end
- def test_redirect_bool_with_status_in_300s
- @session.stubs(:status).returns 301
- assert @session.redirect?
- end
-
- def test_redirect_bool_with_status_in_200s
- @session.stubs(:status).returns 200
- assert !@session.redirect?
- end
-
def test_get
path = "/index"; params = "blah"; headers = {:location => 'blah'}
@session.expects(:process).with(:get,path,params,headers)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index da063710a9..023bf0eeaa 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -194,6 +194,10 @@ class TestController < ActionController::Base
render :inline => "<%= controller_name %>"
end
+ def render_json_nil
+ render :json => nil
+ end
+
def render_json_hello_world
render :json => ActiveSupport::JSON.encode(:hello => 'world')
end
@@ -874,6 +878,12 @@ class RenderTest < ActionController::TestCase
assert_equal "The secret is in the sauce\n", @response.body
end
+ def test_render_json_nil
+ get :render_json_nil
+ assert_equal 'null', @response.body
+ assert_equal 'application/json', @response.content_type
+ end
+
def test_render_json
get :render_json_hello_world
assert_equal '{"hello":"world"}', @response.body
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index c807e71cd7..30ab110ef7 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -120,6 +120,14 @@ class ResourcesTest < ActionController::TestCase
end
end
+ def test_irregular_id_requirements_should_get_passed_to_member_actions
+ expected_options = {:controller => 'messages', :action => 'custom', :id => '1.1.1'}
+
+ with_restful_routing(:messages, :member => {:custom => :get}, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do
+ assert_recognizes(expected_options, :path => 'messages/1.1.1/custom', :method => :get)
+ end
+ end
+
def test_with_path_prefix
with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do
assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index ef56119751..77abb68f32 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -1923,7 +1923,7 @@ class RouteSetTest < Test::Unit::TestCase
end
end
- request.path = "/people"
+ request.request_uri = "/people"
request.env["REQUEST_METHOD"] = "GET"
assert_nothing_raised { set.recognize(request) }
assert_equal("index", request.path_parameters[:action])
@@ -1945,7 +1945,7 @@ class RouteSetTest < Test::Unit::TestCase
}
request.recycle!
- request.path = "/people/5"
+ request.request_uri = "/people/5"
request.env["REQUEST_METHOD"] = "GET"
assert_nothing_raised { set.recognize(request) }
assert_equal("show", request.path_parameters[:action])
@@ -2047,7 +2047,7 @@ class RouteSetTest < Test::Unit::TestCase
end
end
- request.path = "/people/5"
+ request.request_uri = "/people/5"
request.env["REQUEST_METHOD"] = "GET"
assert_nothing_raised { set.recognize(request) }
assert_equal("show", request.path_parameters[:action])
@@ -2059,7 +2059,7 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal("update", request.path_parameters[:action])
request.recycle!
- request.path = "/people/5.png"
+ request.request_uri = "/people/5.png"
request.env["REQUEST_METHOD"] = "GET"
assert_nothing_raised { set.recognize(request) }
assert_equal("show", request.path_parameters[:action])
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index f68ffc7a2a..919f9815ec 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -201,7 +201,7 @@ XML
end
def test_process_with_request_uri_with_params_with_explicit_uri
- @request.set_REQUEST_URI "/explicit/uri"
+ @request.request_uri = "/explicit/uri"
process :test_uri, :id => 7
assert_equal "/explicit/uri", @response.body
end
@@ -212,7 +212,7 @@ XML
end
def test_process_with_query_string_with_explicit_uri
- @request.set_REQUEST_URI "/explicit/uri?q=test?extra=question"
+ @request.request_uri = "/explicit/uri?q=test?extra=question"
process :test_query_string
assert_equal "q=test?extra=question", @response.body
end
@@ -629,33 +629,6 @@ XML
end
end
-class CleanBacktraceTest < ActionController::TestCase
- def test_should_reraise_the_same_object
- exception = ActiveSupport::TestCase::Assertion.new('message')
- clean_backtrace { raise exception }
- rescue Exception => caught
- assert_equal exception.object_id, caught.object_id
- assert_equal exception.message, caught.message
- end
-
- def test_should_clean_assertion_lines_from_backtrace
- 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 }
- rescue Exception => caught
- assert_equal ["#{path}/abc"], caught.backtrace
- end
-
- def test_should_only_clean_assertion_failure_errors
- clean_backtrace do
- raise "can't touch this", [File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller/assertions/abc")]
- end
- rescue => caught
- assert !caught.backtrace.empty?
- end
-end
-
class InferringClassNameTest < ActionController::TestCase
def test_determine_controller_class
assert_equal ContentController, determine_class("ContentControllerTest")
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index d57a2a611f..3a85db8aa5 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -307,7 +307,7 @@ class RequestTest < ActiveSupport::TestCase
test "restrict method hacking" do
[:get, :put, :delete].each do |method|
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase,
- 'action_controller.request.request_parameters' => { :_method => 'put' }
+ 'action_dispatch.request.request_parameters' => { :_method => 'put' }
assert_equal method, request.method
end
end
diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb
new file mode 100644
index 0000000000..19b5e2988b
--- /dev/null
+++ b/actionpack/test/dispatch/test_request_test.rb
@@ -0,0 +1,45 @@
+require 'abstract_unit'
+
+class TestRequestTest < ActiveSupport::TestCase
+ test "sane defaults" do
+ env = ActionDispatch::TestRequest.new.env
+
+ assert_equal "GET", env.delete("REQUEST_METHOD")
+ assert_equal "off", env.delete("HTTPS")
+ assert_equal "http", env.delete("rack.url_scheme")
+ assert_equal "example.org", env.delete("SERVER_NAME")
+ assert_equal "80", env.delete("SERVER_PORT")
+ assert_equal "/", env.delete("PATH_INFO")
+ assert_equal "", env.delete("SCRIPT_NAME")
+ assert_equal "", env.delete("QUERY_STRING")
+ assert_equal "0", env.delete("CONTENT_LENGTH")
+
+ assert_equal "test.host", env.delete("HTTP_HOST")
+ assert_equal "0.0.0.0", env.delete("REMOTE_ADDR")
+ assert_equal "Rails Testing", env.delete("HTTP_USER_AGENT")
+
+ assert_equal [1, 0], env.delete("rack.version")
+ assert_equal "", env.delete("rack.input").string
+ assert_kind_of StringIO, env.delete("rack.errors")
+ assert_equal true, env.delete("rack.multithread")
+ assert_equal true, env.delete("rack.multiprocess")
+ assert_equal false, env.delete("rack.run_once")
+
+ assert env.empty?, env.inspect
+ end
+
+ test "cookie jar" do
+ req = ActionDispatch::TestRequest.new
+
+ assert_equal({}, req.cookies)
+ assert_equal nil, req.env["HTTP_COOKIE"]
+
+ req.cookies["user_name"] = "david"
+ assert_equal({"user_name" => "david"}, req.cookies)
+ assert_equal "user_name=david;", req.env["HTTP_COOKIE"]
+
+ req.cookies["login"] = "XJ-122"
+ assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
+ assert_equal "login=XJ-122; user_name=david;", req.env["HTTP_COOKIE"]
+ end
+end