Skip to content

Commit

Permalink
Tidy up tests and CHANGELOG for #12598
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix committed Jan 20, 2014
1 parent f9f32e0 commit bf19131
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
15 changes: 13 additions & 2 deletions actionpack/CHANGELOG.md
@@ -1,9 +1,20 @@
* Add ability to set a prefix name for routes which have hyphen(s).
* Automatically convert dashes to underscores for shorthand routes, e.g:

get '/our-work/latest'

When running `rake routes` you will get the following output:

Prefix Verb URI Pattern Controller#Action
our_work_latest GET /our-work/latest(.:format) our_work#latest

*Mikko Johansson*

* Automatically convert dashes to underscores for url helpers, e.g:

get '/contact-us' => 'pages#contact'
get '/about-us' => 'pages#about_us'

The above routes will inspected to
When running `rake routes` you will get the following output:

Prefix Verb URI Pattern Controller#Action
contact_us GET /contact-us(.:format) pages#contact
Expand Down
17 changes: 14 additions & 3 deletions actionpack/test/dispatch/routing/inspector_test.rb
Expand Up @@ -37,7 +37,6 @@ def self.inspect
end
engine.routes.draw do
get '/cart', :to => 'cart#show'
get '/view-cart', :to => 'cart#show'
end

output = draw do
Expand All @@ -51,8 +50,7 @@ def self.inspect
" blog /blog Blog::Engine",
"",
"Routes for Blog::Engine:",
" cart GET /cart(.:format) cart#show",
"view_cart GET /view-cart(.:format) cart#show"
" cart GET /cart(.:format) cart#show"
], output
end

Expand Down Expand Up @@ -162,6 +160,19 @@ def test_rake_routes_shows_route_with_constraints
], output
end

def test_rake_routes_shows_routes_with_dashes
output = draw do
get 'about-us' => 'pages#about_us'
get 'our-work/latest'
end

assert_equal [
" Prefix Verb URI Pattern Controller#Action",
" about_us GET /about-us(.:format) pages#about_us",
"our_work_latest GET /our-work/latest(.:format) our_work#latest"
], output
end

class RackApp
def self.call(env)
end
Expand Down
2 changes: 0 additions & 2 deletions actionpack/test/dispatch/routing/route_set_test.rb
Expand Up @@ -30,12 +30,10 @@ def call(env)
draw do
get 'foo', to: SimpleApp.new('foo#index')
get 'bar', to: SimpleApp.new('bar#index')
get 'foo-bar', to: SimpleApp.new('bar#index')
end

assert_equal '/foo', url_helpers.foo_path
assert_equal '/bar', url_helpers.bar_path
assert_equal '/foo-bar', url_helpers.foo_bar_path
end

test "url helpers are updated when route is updated" do
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -2912,6 +2912,16 @@ def test_trailing_slash
assert @response.ok?, 'route with trailing slash and with QUERY_STRING should work'
end

def test_route_with_dashes_in_path
draw do
get '/contact-us', to: 'pages#contact_us'
end

get '/contact-us'
assert_equal 'pages#contact_us', @response.body
assert_equal '/contact-us', contact_us_path
end

def test_shorthand_route_with_dashes_in_path
draw do
get '/about-us/index'
Expand Down

0 comments on commit bf19131

Please sign in to comment.