Fix simple resource named routes for new routing dsl
This commit is contained in:
parent
aaa5a692a3
commit
f950d0b4af
@ -20,15 +20,20 @@ def resource(*resources, &block)
|
||||
return self
|
||||
end
|
||||
|
||||
controller(resource) do
|
||||
singular = resource.to_s
|
||||
plural = singular.pluralize
|
||||
|
||||
controller(plural) do
|
||||
namespace(resource) do
|
||||
with_scope_level(:resource) do
|
||||
yield if block_given?
|
||||
|
||||
get "", :to => :show
|
||||
get "", :to => :show, :as => "#{singular}"
|
||||
post "", :to => :create
|
||||
put "", :to => :update
|
||||
delete "", :to => :destory
|
||||
delete "", :to => :destroy
|
||||
get "new", :to => :new, :as => "new_#{singular}"
|
||||
get "edit", :to => :edit, :as => "edit_#{singular}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -54,22 +59,25 @@ def resources(*resources, &block)
|
||||
return self
|
||||
end
|
||||
|
||||
plural = resource.to_s
|
||||
singular = plural.singularize
|
||||
|
||||
controller(resource) do
|
||||
namespace(resource) do
|
||||
with_scope_level(:resources) do
|
||||
yield if block_given?
|
||||
|
||||
member do
|
||||
get "", :to => :show
|
||||
get "", :to => :show, :as => "#{singular}"
|
||||
put "", :to => :update
|
||||
delete "", :to => :destory
|
||||
get "edit", :to => :edit
|
||||
delete "", :to => :destroy
|
||||
get "edit", :to => :edit, :as => "edit_#{singular}"
|
||||
end
|
||||
|
||||
collection do
|
||||
get "", :to => :index
|
||||
get "", :to => :index, :as => "#{plural}"
|
||||
post "", :to => :create
|
||||
get "new", :to => :new
|
||||
get "new", :to => :new, :as => "new_#{singular}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -221,6 +229,10 @@ def delete(*args, &block)
|
||||
map_method(:delete, *args, &block)
|
||||
end
|
||||
|
||||
def root(options = {})
|
||||
match '/', options.merge(:as => :root)
|
||||
end
|
||||
|
||||
def match(*args)
|
||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
|
||||
|
@ -190,8 +190,21 @@ def test_global
|
||||
|
||||
def test_projects
|
||||
with_test_routes do
|
||||
get '/projects'
|
||||
assert_equal 'projects#index', @response.body
|
||||
assert_equal '/projects', projects_path
|
||||
|
||||
get '/projects/new'
|
||||
assert_equal 'projects#new', @response.body
|
||||
assert_equal '/projects/new', new_project_path
|
||||
|
||||
get '/projects/1'
|
||||
assert_equal 'projects#show', @response.body
|
||||
assert_equal '/projects/1', project_path(:id => '1')
|
||||
|
||||
get '/projects/1/edit'
|
||||
assert_equal 'projects#edit', @response.body
|
||||
assert_equal '/projects/1/edit', edit_project_path(:id => '1')
|
||||
end
|
||||
end
|
||||
|
||||
@ -231,7 +244,7 @@ def test_projects_companies
|
||||
assert_equal 'people#index', @response.body
|
||||
|
||||
get '/projects/1/companies/1/avatar'
|
||||
assert_equal 'avatar#show', @response.body
|
||||
assert_equal 'avatars#show', @response.body
|
||||
end
|
||||
end
|
||||
|
||||
@ -254,7 +267,7 @@ def test_projects_people
|
||||
assert_equal 'people#show', @response.body
|
||||
|
||||
get '/projects/1/people/1/7a2dec8/avatar'
|
||||
assert_equal 'avatar#show', @response.body
|
||||
assert_equal 'avatars#show', @response.body
|
||||
|
||||
put '/projects/1/people/1/accessible_projects'
|
||||
assert_equal 'people#accessible_projects', @response.body
|
||||
@ -282,7 +295,7 @@ def test_projects_posts
|
||||
assert_equal 'posts#preview', @response.body
|
||||
|
||||
get '/projects/1/posts/1/subscription'
|
||||
assert_equal 'subscription#show', @response.body
|
||||
assert_equal 'subscriptions#show', @response.body
|
||||
|
||||
get '/projects/1/posts/1/comments'
|
||||
assert_equal 'comments#index', @response.body
|
||||
@ -329,13 +342,13 @@ def test_articles_perma
|
||||
def test_account_namespace
|
||||
with_test_routes do
|
||||
get '/account/subscription'
|
||||
assert_equal 'subscription#show', @response.body
|
||||
assert_equal 'subscriptions#show', @response.body
|
||||
|
||||
get '/account/credit'
|
||||
assert_equal 'credit#show', @response.body
|
||||
assert_equal 'credits#show', @response.body
|
||||
|
||||
get '/account/credit_card'
|
||||
assert_equal 'credit_card#show', @response.body
|
||||
assert_equal 'credit_cards#show', @response.body
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user