0
@@ -14,6 +14,8 @@ class LogosController < ResourcesController; end
0
class AccountsController < ResourcesController; end
0
class AdminController < ResourcesController; end
0
+class ProductsController < ResourcesController; end
0
+class ImagesController < ResourcesController; end
0
class ProductsController < ResourcesController; end
0
@@ -776,6 +778,121 @@ class ResourcesTest < Test::Unit::TestCase
0
+ def test_resource_has_only_show_action
0
+ map.resources :products, :only => :show
0
+ assert_resource_allowed_routes('products', {}, { :id => '1' }, :show, [:index, :new, :create, :edit, :update, :destroy])
0
+ assert_resource_allowed_routes('products', { :format => 'xml' }, { :id => '1' }, :show, [:index, :new, :create, :edit, :update, :destroy])
0
+ def test_singleton_resource_has_only_show_action
0
+ map.resource :account, :only => :show
0
+ assert_singleton_resource_allowed_routes('accounts', {}, :show, [:index, :new, :create, :edit, :update, :destroy])
0
+ assert_singleton_resource_allowed_routes('accounts', { :format => 'xml' }, :show, [:index, :new, :create, :edit, :update, :destroy])
0
+ def test_resource_does_not_have_destroy_action
0
+ map.resources :products, :except => :destroy
0
+ assert_resource_allowed_routes('products', {}, { :id => '1' }, [:index, :new, :create, :show, :edit, :update], :destroy)
0
+ assert_resource_allowed_routes('products', { :format => 'xml' }, { :id => '1' }, [:index, :new, :create, :show, :edit, :update], :destroy)
0
+ def test_singleton_resource_does_not_have_destroy_action
0
+ map.resource :account, :except => :destroy
0
+ assert_singleton_resource_allowed_routes('accounts', {}, [:new, :create, :show, :edit, :update], :destroy)
0
+ assert_singleton_resource_allowed_routes('accounts', { :format => 'xml' }, [:new, :create, :show, :edit, :update], :destroy)
0
+ def test_resource_has_only_collection_action
0
+ map.resources :products, :except => :all, :collection => { :sale => :get }
0
+ assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
0
+ assert_resource_allowed_routes('products', { :format => 'xml' }, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
0
+ assert_recognizes({ :controller => 'products', :action => 'sale' }, :path => 'products/sale', :method => :get)
0
+ assert_recognizes({ :controller => 'products', :action => 'sale', :format => 'xml' }, :path => 'products/sale.xml', :method => :get)
0
+ def test_resource_has_only_member_action
0
+ map.resources :products, :except => :all, :member => { :preview => :get }
0
+ assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
0
+ assert_resource_allowed_routes('products', { :format => 'xml' }, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
0
+ assert_recognizes({ :controller => 'products', :action => 'preview', :id => '1' }, :path => 'products/1/preview', :method => :get)
0
+ assert_recognizes({ :controller => 'products', :action => 'preview', :id => '1', :format => 'xml' }, :path => 'products/1/preview.xml', :method => :get)
0
+ def test_singleton_resource_has_only_member_action
0
+ map.resource :account, :except => :all, :member => { :signup => :get }
0
+ assert_singleton_resource_allowed_routes('accounts', {}, [], [:new, :create, :show, :edit, :update, :destroy])
0
+ assert_singleton_resource_allowed_routes('accounts', { :format => 'xml' }, [], [:new, :create, :show, :edit, :update, :destroy])
0
+ assert_recognizes({ :controller => 'accounts', :action => 'signup' }, :path => 'account/signup', :method => :get)
0
+ assert_recognizes({ :controller => 'accounts', :action => 'signup', :format => 'xml' }, :path => 'account/signup.xml', :method => :get)
0
+ def test_nested_resource_inherits_only_show_action
0
+ map.resources :products, :only => :show do |product|
0
+ product.resources :images
0
+ assert_resource_allowed_routes('images', { :product_id => '1' }, { :id => '2' }, :show, [:index, :new, :create, :edit, :update, :destroy], 'products/1/images')
0
+ assert_resource_allowed_routes('images', { :product_id => '1', :format => 'xml' }, { :id => '2' }, :show, [:index, :new, :create, :edit, :update, :destroy], 'products/1/images')
0
+ def test_nested_resource_has_only_show_and_member_action
0
+ map.resources :products, :only => [:index, :show] do |product|
0
+ product.resources :images, :member => { :thumbnail => :get }, :only => :show
0
+ assert_resource_allowed_routes('images', { :product_id => '1' }, { :id => '2' }, :show, [:index, :new, :create, :edit, :update, :destroy], 'products/1/images')
0
+ assert_resource_allowed_routes('images', { :product_id => '1', :format => 'xml' }, { :id => '2' }, :show, [:index, :new, :create, :edit, :update, :destroy], 'products/1/images')
0
+ assert_recognizes({ :controller => 'images', :action => 'thumbnail', :product_id => '1', :id => '2' }, :path => 'products/1/images/2/thumbnail', :method => :get)
0
+ assert_recognizes({ :controller => 'images', :action => 'thumbnail', :product_id => '1', :id => '2', :format => 'jpg' }, :path => 'products/1/images/2/thumbnail.jpg', :method => :get)
0
def with_restful_routing(*args)
0
@@ -979,6 +1096,51 @@ class ResourcesTest < Test::Unit::TestCase
0
+ def assert_resource_allowed_routes(controller, options, shallow_options, allowed, not_allowed, path = controller)
0
+ shallow_path = "#{path}/#{shallow_options[:id]}"
0
+ format = options[:format] && ".#{options[:format]}"
0
+ options.merge!(:controller => controller)
0
+ shallow_options.merge!(options)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'index', "#{path}#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'new', "#{path}/new#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'create', "#{path}#{format}", :post)
0
+ assert_whether_allowed(allowed, not_allowed, shallow_options, 'show', "#{shallow_path}#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, shallow_options, 'edit', "#{shallow_path}/edit#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, shallow_options, 'update', "#{shallow_path}#{format}", :put)
0
+ assert_whether_allowed(allowed, not_allowed, shallow_options, 'destroy', "#{shallow_path}#{format}", :delete)
0
+ def assert_singleton_resource_allowed_routes(controller, options, allowed, not_allowed, path = controller.singularize)
0
+ format = options[:format] && ".#{options[:format]}"
0
+ options.merge!(:controller => controller)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'new', "#{path}/new#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'create', "#{path}#{format}", :post)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'show', "#{path}#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'edit', "#{path}/edit#{format}", :get)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'update', "#{path}#{format}", :put)
0
+ assert_whether_allowed(allowed, not_allowed, options, 'destroy', "#{path}#{format}", :delete)
0
+ def assert_whether_allowed(allowed, not_allowed, options, action, path, method)
0
+ action = action.to_sym
0
+ options = options.merge(:action => action.to_s)
0
+ path_options = { :path => path, :method => method }
0
+ if Array(allowed).include?(action)
0
+ assert_recognizes options, path_options
0
+ elsif Array(not_allowed).include?(action)
0
+ assert_not_recognizes options, path_options
0
+ def assert_not_recognizes(expected_options, path)
0
+ assert_raise ActionController::RoutingError, ActionController::MethodNotAllowed, Test::Unit::AssertionFailedError do
0
+ assert_recognizes(expected_options, path)
0
def distinct_routes? (r1, r2)
0
if r1.conditions == r2.conditions and r1.requirements == r2.requirements then
0
if r1.segments.collect(&:to_s) == r2.segments.collect(&:to_s) then
woot. I was working on this, but now I can stop.
This is fantastic! I hope this makes it into 2.2
I would love to see this included in 2.2. Totally awesome.
+1 for 2.2 inclusion
+1 for 2.2 inclusion as well. This is sweet.
+1 for 2.2 inclusion.
Guys, this is still the 2.2 branch, it’s going in. ;)
nice :)
+1 for 2.2 inclusion
I’m all for the feature (been wanting it for ages), but I’d favor holding it to 2.2.1. Maintaining a feature freeze during a release cycle is important for the quality and stability of a release, and relaxing the discipline of a freeze for a shiny object is going to get you in trouble eventually.
+1 for 2.2 inclusion, great job
I have to agree with joshsusser on this.
We want it in for 2.2 final, if you think we should do another RC with it included, then we can do that. However it seems relatively harmless.
Pipe up on the ticket if you feel strongly about it. There’s an enhancement to come it seems
There have probably been enough changes since RC1 to merit an RC2, especially since there have been some feature additions. And I notice there was an issue with removing index and show helpers, which is a good indication this change needs some time to bake.
lol… apparently I was ahead of my time, I was shot down for suggesting this feature – which lead to me adding “shallow” nesting instead… oh well, now we have both
@sbfaulkner: heh, yeah. Specific numbers on the memory usage made me change my mind.
@joshsusser: Indeed, this particular changeset is only intended for people looking to cut down on memory usage with thousands of routes. I just tested with my app and it was a tiny tiny difference.
We’ll do an RC2 and keep it ‘frozen’ barring surprises.
Adding a blank space.