aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/cookies_test.rb10
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb1
-rw-r--r--actionpack/test/dispatch/prefix_generation_test.rb93
-rw-r--r--actionpack/test/dispatch/request/multipart_params_parsing_test.rb2
-rw-r--r--actionpack/test/dispatch/request/xml_params_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/request_test.rb7
-rw-r--r--actionpack/test/dispatch/response_test.rb16
-rw-r--r--actionpack/test/dispatch/routing_test.rb26
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb2
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb14
10 files changed, 122 insertions, 50 deletions
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index 360fb351df..efdc1f5d93 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -47,7 +47,7 @@ class CookiesTest < ActionController::TestCase
cookies["user_name"] = { :value => "david", :httponly => true }
head :ok
end
-
+
def authenticate_with_secure
cookies["user_name"] = { :value => "david", :secure => true }
head :ok
@@ -133,7 +133,7 @@ class CookiesTest < ActionController::TestCase
assert_cookie_header "user_name=david; path=/; HttpOnly"
assert_equal({"user_name" => "david"}, @response.cookies)
end
-
+
def test_setting_cookie_with_secure
get :authenticate_with_secure
assert_cookie_header "user_name=david; path=/; secure"
@@ -169,8 +169,8 @@ class CookiesTest < ActionController::TestCase
def test_permanent_cookie
get :set_permanent_cookie
- assert_match /Jamie/, @response.headers["Set-Cookie"]
- assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
+ assert_match(/Jamie/, @response.headers["Set-Cookie"])
+ assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"])
end
def test_signed_cookie
@@ -185,7 +185,7 @@ class CookiesTest < ActionController::TestCase
def test_permanent_signed_cookie
get :set_permanent_signed_cookie
- assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
+ assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"])
assert_equal 100, @controller.send(:cookies).signed[:remember_me]
end
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 369212e2d0..4c2b95550c 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -41,7 +41,6 @@ class MimeTypeTest < ActiveSupport::TestCase
begin
Mime::Type.register("image/gif", :gif)
assert_nothing_raised do
- Mime::GIF
assert_equal Mime::GIF, Mime::SET.last
end
ensure
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb
index 26d76557dd..18f28deee4 100644
--- a/actionpack/test/dispatch/prefix_generation_test.rb
+++ b/actionpack/test/dispatch/prefix_generation_test.rb
@@ -1,8 +1,23 @@
require 'abstract_unit'
+require 'rack/test'
module TestGenerationPrefix
+ class Post
+ extend ActiveModel::Naming
+
+ def to_param
+ "1"
+ end
+
+ def self.model_name
+ klass = "Post"
+ def klass.name; self end
+
+ ActiveModel::Name.new(klass)
+ end
+ end
+
class WithMountedEngine < ActionDispatch::IntegrationTest
- require 'rack/test'
include Rack::Test::Methods
class BlogEngine
@@ -55,21 +70,6 @@ module TestGenerationPrefix
# force draw
RailsApplication.routes
- class Post
- extend ActiveModel::Naming
-
- def to_param
- "1"
- end
-
- def self.model_name
- klass = "Post"
- def klass.name; self end
-
- ActiveModel::Name.new(klass)
- end
- end
-
class ::InsideEngineGeneratingController < ActionController::Base
include BlogEngine.routes.url_helpers
include RailsApplication.routes.mounted_helpers
@@ -253,4 +253,65 @@ module TestGenerationPrefix
assert_equal "http://www.example.com/awesome/blog/posts/1", path
end
end
+
+ class EngineMountedAtRoot < ActionDispatch::IntegrationTest
+ include Rack::Test::Methods
+
+ class BlogEngine
+ def self.routes
+ @routes ||= begin
+ routes = ActionDispatch::Routing::RouteSet.new
+ routes.draw do
+ match "/posts/:id", :to => "posts#show", :as => :post
+ end
+
+ routes
+ end
+ end
+
+ def self.call(env)
+ env['action_dispatch.routes'] = routes
+ routes.call(env)
+ end
+ end
+
+ class RailsApplication
+ def self.routes
+ @routes ||= begin
+ routes = ActionDispatch::Routing::RouteSet.new
+ routes.draw do
+ mount BlogEngine => "/"
+ end
+
+ routes
+ end
+ end
+
+ def self.call(env)
+ env['action_dispatch.routes'] = routes
+ routes.call(env)
+ end
+ end
+
+ # force draw
+ RailsApplication.routes
+
+ class ::PostsController < ActionController::Base
+ include BlogEngine.routes.url_helpers
+ include RailsApplication.routes.mounted_helpers
+
+ def show
+ render :text => post_path(:id => params[:id])
+ end
+ end
+
+ def app
+ RailsApplication
+ end
+
+ test "generating path inside engine" do
+ get "/posts/1"
+ assert_equal "/posts/1", last_response.body
+ end
+ end
end
diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
index 1ae514ebf7..073dd3ddad 100644
--- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
@@ -68,7 +68,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
- assert ('a' * 20480) == file.read
+ assert_equal(('a' * 20480), file.read)
end
test "parses binary file" do
diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
index 16669614d6..ad9de02eb4 100644
--- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -18,6 +18,7 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest
test "parses a strict rack.input" do
class Linted
+ undef call if method_defined?(:call)
def call(env)
bar = env['action_dispatch.request.request_parameters']['foo']
result = "<ok>#{bar}</ok>"
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index a8b8f9377b..3efed8bef6 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -45,9 +45,9 @@ class RequestTest < ActiveSupport::TestCase
e = assert_raise(ActionDispatch::RemoteIp::IpSpoofAttackError) {
request.remote_ip
}
- assert_match /IP spoofing attack/, e.message
- assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message
- assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message
+ assert_match(/IP spoofing attack/, e.message)
+ assert_match(/HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message)
+ assert_match(/HTTP_CLIENT_IP="2.2.2.2"/, e.message)
# turn IP Spoofing detection off.
# This is useful for sites that are aimed at non-IP clients. The typical
@@ -474,6 +474,7 @@ protected
def stub_request(env = {})
ip_spoofing_check = env.key?(:ip_spoofing_check) ? env.delete(:ip_spoofing_check) : true
+ @trusted_proxies ||= nil
ip_app = ActionDispatch::RemoteIp.new(Proc.new { }, ip_spoofing_check, @trusted_proxies)
tld_length = env.key?(:tld_length) ? env.delete(:tld_length) : 1
ip_app.call(env)
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index c20fa10f63..cd0418c338 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -120,10 +120,10 @@ class ResponseTest < ActiveSupport::TestCase
end
test "read cache control" do
- resp = ActionDispatch::Response.new.tap { |resp|
- resp.cache_control[:public] = true
- resp.etag = '123'
- resp.body = 'Hello'
+ resp = ActionDispatch::Response.new.tap { |response|
+ response.cache_control[:public] = true
+ response.etag = '123'
+ response.body = 'Hello'
}
resp.to_a
@@ -135,10 +135,10 @@ class ResponseTest < ActiveSupport::TestCase
end
test "read charset and content type" do
- resp = ActionDispatch::Response.new.tap { |resp|
- resp.charset = 'utf-16'
- resp.content_type = Mime::XML
- resp.body = 'Hello'
+ resp = ActionDispatch::Response.new.tap { |response|
+ response.charset = 'utf-16'
+ response.content_type = Mime::XML
+ response.body = 'Hello'
}
resp.to_a
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index bdef04efc6..5c188a60c7 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -442,6 +442,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get :preview, :on => :member
end
+ scope :as => "routes" do
+ get "/c/:id", :as => :collision, :to => "collision#show"
+ get "/collision", :to => "collision#show"
+ get "/no_collision", :to => "collision#show", :as => nil
+
+ get "/fc/:id", :as => :forced_collision, :to => "forced_collision#show"
+ get "/forced_collision", :as => :forced_collision, :to => "forced_collision#show"
+ end
+
match '/purchases/:token/:filename',
:to => 'purchases#fetch',
:token => /[[:alnum:]]{10}/,
@@ -1216,14 +1225,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- def test_index
- with_test_routes do
- assert_equal '/info', info_path
- get '/info'
- assert_equal 'projects#info', @response.body
- end
- end
-
def test_match_shorthand_with_no_scope
with_test_routes do
assert_equal '/account/overview', account_overview_path
@@ -2128,6 +2129,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_raises(ActionController::RoutingError){ list_todo_path(:list_id => '2', :id => '1') }
end
+ def test_named_routes_collision_is_avoided_unless_explicitly_given_as
+ assert_equal "/c/1", routes_collision_path(1)
+ assert_equal "/forced_collision", routes_forced_collision_path
+ end
+
+ def test_explicitly_avoiding_the_named_route
+ assert !respond_to?(:routes_no_collision_path)
+ end
+
def test_controller_name_with_leading_slash_raise_error
assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index b436fb5518..3489f628ed 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -279,7 +279,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
def test_session_store_with_explicit_domain
with_test_route_set(:domain => "example.es") do
get '/set_session_value'
- assert_match /domain=example\.es/, headers['Set-Cookie']
+ assert_match(/domain=example\.es/, headers['Set-Cookie'])
headers['Set-Cookie']
end
end
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index 5b181600e8..4ede1ab47c 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -58,15 +58,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
- assert_match /puke/, body
+ assert_match(/puke/, body)
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
- assert_match /#{ActionController::UnknownAction.name}/, body
+ assert_match(/#{ActionController::UnknownAction.name}/, body)
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
- assert_match /ActionController::MethodNotAllowed/, body
+ assert_match(/ActionController::MethodNotAllowed/, body)
end
end
@@ -96,15 +96,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
- assert_match /puke/, body
+ assert_match(/puke/, body)
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
- assert_match /#{ActionController::UnknownAction.name}/, body
+ assert_match(/#{ActionController::UnknownAction.name}/, body)
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
- assert_match /ActionController::MethodNotAllowed/, body
+ assert_match(/ActionController::MethodNotAllowed/, body)
end
test "does not show filtered parameters" do
@@ -113,6 +113,6 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true,
'action_dispatch.parameter_filter' => [:foo]}
assert_response 500
- assert_match "&quot;foo&quot;=&gt;&quot;[FILTERED]&quot;", body
+ assert_match("&quot;foo&quot;=&gt;&quot;[FILTERED]&quot;", body)
end
end