aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2015-11-28 16:32:24 +0900
committeryui-knk <spiketeika@gmail.com>2016-04-23 11:40:50 +0900
commitb50e88ebdf375cf81ad63586ce4599979262f975 (patch)
treeb22902d744f08a8cd2d30e3a0a22672337027312 /actionpack/test
parent4c76ce640449cc2568e31b5ed533caec8af5e39f (diff)
downloadrails-b50e88ebdf375cf81ad63586ce4599979262f975.tar.gz
rails-b50e88ebdf375cf81ad63586ce4599979262f975.tar.bz2
rails-b50e88ebdf375cf81ad63586ce4599979262f975.zip
Make `assert_recognizes` to traverse mounted engines
Before this commit paths of mounted engines are not traversed when `assert_recognizes` is called, causing strange test results. This commit enable to traverse mounted paths.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/routing_assertions_test.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb
index 56ea644f22..111d5d637f 100644
--- a/actionpack/test/dispatch/routing_assertions_test.rb
+++ b/actionpack/test/dispatch/routing_assertions_test.rb
@@ -1,13 +1,39 @@
require 'abstract_unit'
+require 'rails/engine'
require 'controller/fake_controllers'
class SecureArticlesController < ArticlesController; end
class BlockArticlesController < ArticlesController; end
class QueryArticlesController < ArticlesController; end
+class SecureBooksController < BooksController; end
+class BlockBooksController < BooksController; end
+class QueryBooksController < BooksController; end
+
class RoutingAssertionsTest < ActionController::TestCase
def setup
+ engine = Class.new(Rails::Engine) do
+ def self.name
+ "blog_engine"
+ end
+ end
+ engine.routes.draw do
+ resources :books
+
+ scope 'secure', :constraints => { :protocol => 'https://' } do
+ resources :books, :controller => 'secure_books'
+ end
+
+ scope 'block', :constraints => lambda { |r| r.ssl? } do
+ resources :books, :controller => 'block_books'
+ end
+
+ scope 'query', :constraints => lambda { |r| r.params[:use_query] == 'true' } do
+ resources :books, :controller => 'query_books'
+ end
+ end
+
@routes = ActionDispatch::Routing::RouteSet.new
@routes.draw do
resources :articles
@@ -23,6 +49,8 @@ class RoutingAssertionsTest < ActionController::TestCase
scope 'query', :constraints => lambda { |r| r.params[:use_query] == 'true' } do
resources :articles, :controller => 'query_articles'
end
+
+ mount engine => "/shelf"
end
end
@@ -82,6 +110,49 @@ class RoutingAssertionsTest < ActionController::TestCase
assert_match err.message, "This is a really bad msg"
end
+ def test_assert_recognizes_with_engine
+ assert_recognizes({ :controller => 'books', :action => 'index' }, '/shelf/books')
+ assert_recognizes({ :controller => 'books', :action => 'show', :id => '1' }, '/shelf/books/1')
+ end
+
+ def test_assert_recognizes_with_engine_and_extras
+ assert_recognizes({ :controller => 'books', :action => 'index', :page => '1' }, '/shelf/books', { :page => '1' })
+ end
+
+ def test_assert_recognizes_with_engine_and_method
+ assert_recognizes({ :controller => 'books', :action => 'create' }, { :path => '/shelf/books', :method => :post })
+ assert_recognizes({ :controller => 'books', :action => 'update', :id => '1' }, { :path => '/shelf/books/1', :method => :put })
+ end
+
+ def test_assert_recognizes_with_engine_and_hash_constraint
+ assert_raise(Assertion) do
+ assert_recognizes({ :controller => 'secure_books', :action => 'index' }, 'http://test.host/shelf/secure/books')
+ end
+ assert_recognizes({ :controller => 'secure_books', :action => 'index', :protocol => 'https://' }, 'https://test.host/shelf/secure/books')
+ end
+
+ def test_assert_recognizes_with_engine_and_block_constraint
+ assert_raise(Assertion) do
+ assert_recognizes({ :controller => 'block_books', :action => 'index' }, 'http://test.host/shelf/block/books')
+ end
+ assert_recognizes({ :controller => 'block_books', :action => 'index' }, 'https://test.host/shelf/block/books')
+ end
+
+ def test_assert_recognizes_with_engine_and_query_constraint
+ assert_raise(Assertion) do
+ assert_recognizes({ :controller => 'query_books', :action => 'index', :use_query => 'false' }, '/shelf/query/books', { :use_query => 'false' })
+ end
+ assert_recognizes({ :controller => 'query_books', :action => 'index', :use_query => 'true' }, '/shelf/query/books', { :use_query => 'true' })
+ end
+
+ def test_assert_recognizes_raises_message_with_engine
+ err = assert_raise(Assertion) do
+ assert_recognizes({ :controller => 'secure_books', :action => 'index' }, 'http://test.host/shelf/secure/books', {}, "This is a really bad msg")
+ end
+
+ assert_match err.message, "This is a really bad msg"
+ end
+
def test_assert_routing
assert_routing('/articles', :controller => 'articles', :action => 'index')
end