Skip to content

Commit

Permalink
More DRY route inspect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszx0 committed May 18, 2012
1 parent 40bdf55 commit 61fc10d
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions railties/test/application/route_inspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def setup
Rails.stubs(:env).returns("development")
end

def draw(&block)
@set.draw(&block)
@inspector.format(@set.routes)
end

def test_displaying_routes_for_engines
engine = Class.new(Rails::Engine) do
def self.to_s
Expand All @@ -26,12 +31,11 @@ def self.to_s
get '/cart', :to => 'cart#show'
end

@set.draw do
output = draw do
get '/custom/assets', :to => 'custom_assets#show'
mount engine => "/blog", :as => "blog"
end

output = @inspector.format @set.routes
expected = [
"custom_assets GET /custom/assets(.:format) custom_assets#show",
" blog /blog Blog::Engine",
Expand All @@ -42,26 +46,23 @@ def self.to_s
end

def test_cart_inspect
@set.draw do
output = draw do
get '/cart', :to => 'cart#show'
end
output = @inspector.format @set.routes
assert_equal ["cart GET /cart(.:format) cart#show"], output
end

def test_inspect_shows_custom_assets
@set.draw do
output = draw do
get '/custom/assets', :to => 'custom_assets#show'
end
output = @inspector.format @set.routes
assert_equal ["custom_assets GET /custom/assets(.:format) custom_assets#show"], output
end

def test_inspect_routes_shows_resources_route
@set.draw do
output = draw do
resources :articles
end
output = @inspector.format @set.routes
expected = [
" articles GET /articles(.:format) articles#index",
" POST /articles(.:format) articles#create",
Expand All @@ -75,50 +76,44 @@ def test_inspect_routes_shows_resources_route
end

def test_inspect_routes_shows_root_route
@set.draw do
output = draw do
root :to => 'pages#main'
end
output = @inspector.format @set.routes
assert_equal ["root GET / pages#main"], output
end

def test_inspect_routes_shows_dynamic_action_route
@set.draw do
output = draw do
get 'api/:action' => 'api'
end
output = @inspector.format @set.routes
assert_equal [" GET /api/:action(.:format) api#:action"], output
end

def test_inspect_routes_shows_controller_and_action_only_route
@set.draw do
output = draw do
get ':controller/:action'
end
output = @inspector.format @set.routes
assert_equal [" GET /:controller/:action(.:format) :controller#:action"], output
end

def test_inspect_routes_shows_controller_and_action_route_with_constraints
@set.draw do
output = draw do
get ':controller(/:action(/:id))', :id => /\d+/
end
output = @inspector.format @set.routes
assert_equal [" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"], output
end

def test_rake_routes_shows_route_with_defaults
@set.draw do
output = draw do
get 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'}
end
output = @inspector.format @set.routes
assert_equal [%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]], output
end

def test_rake_routes_shows_route_with_constraints
@set.draw do
output = draw do
get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/
end
output = @inspector.format @set.routes
assert_equal [" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]\\d{5}/}"], output
end

Expand All @@ -128,10 +123,9 @@ def self.call(env)
end

def test_rake_routes_shows_route_with_rack_app
@set.draw do
output = draw do
get 'foo/:id' => RackApp, :id => /[A-Z]\d{5}/
end
output = @inspector.format @set.routes
assert_equal [" GET /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"], output
end

Expand All @@ -142,21 +136,19 @@ def to_s
end
end

@set.draw do
output = draw do
scope :constraint => constraint.new do
mount RackApp => '/foo'
end
end

output = @inspector.format @set.routes
assert_equal [" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"], output
end

def test_rake_routes_dont_show_app_mounted_in_assets_prefix
@set.draw do
output = draw do
get '/sprockets' => RackApp
end
output = @inspector.format @set.routes
assert_no_match(/RackApp/, output.first)
assert_no_match(/\/sprockets/, output.first)
end
Expand Down

0 comments on commit 61fc10d

Please sign in to comment.