aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/rack_test.rb6
-rw-r--r--actionpack/test/dispatch/request_test.rb8
-rw-r--r--actionpack/test/dispatch/routing_test.rb45
3 files changed, 52 insertions, 7 deletions
diff --git a/actionpack/test/dispatch/rack_test.rb b/actionpack/test/dispatch/rack_test.rb
index 94eba2a24f..504bebbb86 100644
--- a/actionpack/test/dispatch/rack_test.rb
+++ b/actionpack/test/dispatch/rack_test.rb
@@ -122,7 +122,7 @@ class RackRequestTest < BaseRackTest
test "cgi environment variables" do
assert_equal "Basic", @request.auth_type
assert_equal 0, @request.content_length
- assert_equal nil, @request.content_type
+ assert_equal nil, @request.content_mime_type
assert_equal "CGI/1.1", @request.gateway_interface
assert_equal "*/*", @request.accept
assert_equal "UTF-8", @request.accept_charset
@@ -177,12 +177,12 @@ end
class RackRequestContentTypeTest < BaseRackTest
test "html content type verification" do
@request.env['CONTENT_TYPE'] = Mime::HTML.to_s
- assert @request.content_type.verify_request?
+ assert @request.content_mime_type.verify_request?
end
test "xml content type verification" do
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
- assert !@request.content_type.verify_request?
+ assert !@request.content_mime_type.verify_request?
end
end
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index badef4e92e..9093e1ed65 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -295,7 +295,7 @@ class RequestTest < ActiveSupport::TestCase
test "content type" do
request = stub_request 'CONTENT_TYPE' => 'text/html'
- assert_equal Mime::HTML, request.content_type
+ assert_equal Mime::HTML, request.content_mime_type
end
test "can override format with parameter" do
@@ -310,17 +310,17 @@ class RequestTest < ActiveSupport::TestCase
test "no content type" do
request = stub_request
- assert_equal nil, request.content_type
+ assert_equal nil, request.content_mime_type
end
test "content type is XML" do
request = stub_request 'CONTENT_TYPE' => 'application/xml'
- assert_equal Mime::XML, request.content_type
+ assert_equal Mime::XML, request.content_mime_type
end
test "content type with charset" do
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
- assert_equal Mime::XML, request.content_type
+ assert_equal Mime::XML, request.content_mime_type
end
test "user agent" do
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index c4e71a8689..e58653cb8c 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -114,6 +114,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resources :comments, :except => :destroy
end
+ resources :sheep
+
match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp
match 'people/:id/update', :to => 'people#update', :as => :update_person
@@ -171,6 +173,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resources :descriptions
root :to => 'projects#index'
end
+
+ resources :products, :constraints => { :id => /\d{4}/ } do
+ resources :images
+ end
+
+ resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ }
end
end
@@ -525,6 +533,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_resource_with_slugs_in_ids
+ with_test_routes do
+ get '/posts/rails-rocks'
+ assert_equal 'posts#show', @response.body
+ assert_equal '/posts/rails-rocks', post_path(:id => 'rails-rocks')
+ end
+ end
+
+ def test_resources_for_uncountable_names
+ with_test_routes do
+ assert_equal '/sheep', sheep_index_path
+ assert_equal '/sheep/1', sheep_path(1)
+ assert_equal '/sheep/new', new_sheep_path
+ assert_equal '/sheep/1/edit', edit_sheep_path(1)
+ end
+ end
+
def test_path_names
with_test_routes do
get '/es/projeto'
@@ -794,6 +819,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_resource_constraints
+ with_test_routes do
+ assert_raise(ActionController::RoutingError) { get '/products/1' }
+ get '/products'
+ assert_equal 'products#index', @response.body
+ get '/products/0001'
+ assert_equal 'products#show', @response.body
+
+ assert_raise(ActionController::RoutingError) { get '/products/1/images' }
+ get '/products/0001/images'
+ assert_equal 'images#index', @response.body
+ get '/products/0001/images/1'
+ assert_equal 'images#show', @response.body
+
+ assert_raise(ActionController::RoutingError) { get '/dashboard', {}, {'REMOTE_ADDR' => '10.0.0.100'} }
+ get '/dashboard', {}, {'REMOTE_ADDR' => '192.168.1.100'}
+ assert_equal 'dashboards#show', @response.body
+ end
+ end
+
private
def with_test_routes
yield