aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorHendy Tanata <htanata@gmail.com>2011-07-15 01:54:59 +0800
committerHendy Tanata <htanata@gmail.com>2011-07-16 04:23:05 +0800
commit193e4de20646a025bf6dd3f90d1f9a53edb1cecf (patch)
tree8edc77c9475262ef0308de17d01c21b119cab707 /railties/test
parentf88e9d83f13c7d29120696d7e568fae1efea67f4 (diff)
downloadrails-193e4de20646a025bf6dd3f90d1f9a53edb1cecf.tar.gz
rails-193e4de20646a025bf6dd3f90d1f9a53edb1cecf.tar.bz2
rails-193e4de20646a025bf6dd3f90d1f9a53edb1cecf.zip
Better formatting of route requirements in rake:routes.
Previously it was: {:controller=>"photos", :action=>"show", :id=>/[A-Z]\d{5}/} Now it becomes: photos#show {:id=>/[A-Z]\d{5}/}
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/rake_test.rb67
1 files changed, 65 insertions, 2 deletions
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index 7671c129e9..6988b2541d 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -91,7 +91,7 @@ module ApplicationTests
get '/cart', :to => 'cart#show'
end
RUBY
- assert_match 'cart GET /cart(.:format)', Dir.chdir(app_path){ `rake routes` }
+ assert_equal "cart GET /cart(.:format) cart#show\n", Dir.chdir(app_path){ `rake routes` }
end
def test_rake_routes_shows_custom_assets
@@ -100,7 +100,70 @@ module ApplicationTests
get '/custom/assets', :to => 'custom_assets#show'
end
RUBY
- assert_match 'custom_assets GET /custom/assets(.:format)', Dir.chdir(app_path){ `rake routes` }
+ assert_equal "custom_assets GET /custom/assets(.:format) custom_assets#show\n",
+ Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_resources_route
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ resources :articles
+ end
+ RUBY
+ expected =
+ " articles GET /articles(.:format) articles#index\n" <<
+ " POST /articles(.:format) articles#create\n" <<
+ " new_article GET /articles/new(.:format) articles#new\n" <<
+ "edit_article GET /articles/:id/edit(.:format) articles#edit\n" <<
+ " article GET /articles/:id(.:format) articles#show\n" <<
+ " PUT /articles/:id(.:format) articles#update\n" <<
+ " DELETE /articles/:id(.:format) articles#destroy\n"
+ assert_equal expected, Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_root_route
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ root :to => 'pages#main'
+ end
+ RUBY
+ assert_equal "root / pages#main\n", Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_controller_and_action_only_route
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match ':controller/:action'
+ end
+ RUBY
+ assert_equal " /:controller/:action(.:format) \n", Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_controller_and_action_route_with_constraints
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match ':controller(/:action(/:id))', :id => /\\d+/
+ end
+ RUBY
+ assert_equal " /:controller(/:action(/:id))(.:format) {:id=>/\\d+/}\n", Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_route_with_defaults
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'}
+ end
+ RUBY
+ assert_equal %Q[ /photos/:id(.:format) photos#show {:format=>"jpg"}\n], Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_rake_routes_shows_route_with_constraints
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match 'photos/:id' => 'photos#show', :id => /[A-Z]\\d{5}/
+ end
+ RUBY
+ assert_equal " /photos/:id(.:format) photos#show {:id=>/[A-Z]\\d{5}/}\n", Dir.chdir(app_path){ `rake routes` }
end
def test_logger_is_flushed_when_exiting_production_rake_tasks