aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | Use nested_scope? not shallow? to determine whether to copy optionsAndrew White2014-03-161-0/+36
| | | | | | | | | | | | | | | | The method `shallow?` returns false if the parent resource is a singleton so we need to check if we're not inside a nested scope before copying the :path and :as options to their shallow equivalents. Fixes #14388.
* | Copy shallow options from normal options when using scopeAndrew White2014-03-081-0/+48
| | | | | | | | | | | | If the options :shallow_prefix and :shallow_path are not set in the scope options then copy them from the normal :as and :path options if they are set.
* | Pull namespace defaults out of the options hashAndrew White2014-03-081-0/+130
| | | | | | | | | | | | | | If a developer has specified either :path or :as in the options hash then these should be used as the defaults for :shallow_path and :shallow_prefix. Fixes #14241.
* | Only use shallow nested scope when depth is > 1Andrew White2014-03-081-0/+60
| | | | | | | | | | | | | | | | By tracking the depth of resource nesting we can push the need for nested shallow scoping to only those routes that are nested more than one deep. This allows us to keep the fix for #12498 and fix the regression in #14224. Fixes #14224.
* | Set the :shallow_path as each scope is generatedAndrew White2014-02-091-0/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we set :shallow_path when shallow is called it can result in incorrect paths if the resource is inside a namespace because namespace itself sets the :shallow_path option to the namespace path. We fix this by removing the :shallow_path option from shallow as that should only be turning shallow routes on and not otherwise affecting the scope. To do this we need to treat the :shallow option to resources differently to other scope options and move it to before the nested block is called. This change also has the positive side effect of making the behavior of the :shallow option consistent with the shallow method. Fixes #12498.
* | Add additional tests for #13824Andrew White2014-01-251-0/+26
| |
* | Tidy up tests and CHANGELOG for #12598Andrew White2014-01-201-0/+10
| |
* | Automatically convert dashes to underscores in shorthand routesMikko Johansson2014-01-201-0/+10
| |
* | Add failing test for #13369Piotr Sarnacki2014-01-161-0/+18
| | | | | | | | | | | | After introducing 50311f1 a regression was introduced: routes with trailing slash are no longer recognized properly. This commit provides a failing test for this situation.
* | Allow an absolute controller path inside a module scopeAndrew White2014-01-051-0/+12
| | | | | | | | Fixes #12777
* | Unique the segment keys array for non-optimized url helpersAndrew White2014-01-051-0/+18
| | | | | | | | | | | | | | | | | | | | In Rails 3.2 you only needed pass an argument for dynamic segment once so unique the segment keys array to match the number of args. Since the number of args is less than required parts the non-optimized code path is selected. This means to benefit from optimized url generation the arg needs to be specified as many times as it appears in the path. Fixes #12808
* | Show full route constraints in error messageAndrew White2014-01-051-0/+25
| | | | | | | | | | | | | | | | When an optimized helper fails to generate, show the full route constraints in the error message. Previously it would only show the contraints that were required as part of the path. Fixes #13592
* | Use a custom route vistor for optimized route generationAndrew White2014-01-051-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using a Regexp to replace dynamic segments in a path string is fraught with difficulty and can lead to odd edge cases like #13349. Since we already have a parsed representation of the path it makes sense to use that to generate an array of segments that can be used to build an optimized route's path quickly. Tests on a simple route (e.g. /posts/:id) show a speedup of 35%: https://gist.github.com/pixeltrix/8261932 Calculating ------------------------------------- Current Helper: 5274 i/100ms New Helper: 8050 i/100ms ------------------------------------------------- Current Helper: 79263.6 (±3.7%) i/s - 395550 in 4.997252s New Helper: 153464.5 (±4.9%) i/s - 772800 in 5.047834s Tests on a more complex route show even an greater performance boost: https://gist.github.com/pixeltrix/8261957 Calculating ------------------------------------- Current Helper: 2367 i/100ms New Helper: 5382 i/100ms ------------------------------------------------- Current Helper: 29506.0 (±3.2%) i/s - 149121 in 5.059294s New Helper: 78815.5 (±4.1%) i/s - 398268 in 5.062161s It also has the added benefit of fixing the edge cases described above. Fixes #13349
* | Try to escape each part of a path redirect route correctlyAndrew White2013-12-021-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | A path redirect may contain any and all parts of a url which have different escaping rules for each part. This commit tries to escape each part correctly by splitting the string into three chunks - path (which may also include a host), query and fragment; then it applies the correct escape pattern to each part. Whilst using `URI.parse` would be better, unfortunately the possible presence of %{name} parameters in the path redirect string prevents us from using it so we have to use a regular expression instead. Fixes #13110.
* | add test_scoped_root_as_nameSam Ruby2013-09-241-0/+13
| | | | | | | | test for regression introduced by https://github.com/rails/rails/pull/9155
* | Skip Rack applications and redirects when generating urlsAndrew White2013-07-161-0/+53
|/ | | | | | | | | | When generating an unnamed url (i.e. using `url_for` with an options hash) we should skip anything other than standard Rails routes otherwise it will match the first mounted application or redirect and generate a url with query parameters rather than raising an error if the options hash doesn't match any defined routes. Fixes #8018
* test-case => failingYves Senn2013-06-251-0/+13
|
* Add has_named_route? to the mapper APIJosé Valim2013-05-201-0/+13
|
* Add test for `format: false` with resources - closes #10323Andrew White2013-04-241-0/+29
|
* Add url generation tests for #10185Andrew White2013-04-181-0/+2
|
* Passing subdomain: '' to url_for removes the subdomain (instead of adding a ↵Derek Watson2013-04-181-0/+20
| | | | | | leading .) Adding a boolean route constraint checks for presence/absence of request property
* Merge pull request #9932 from senny/9913_routing_problemAndrew White2013-04-031-0/+29
|\ | | | | routing bugfixes when matching multiple paths
| * routing shorthand syntax works with multiple pathsYves Senn2013-03-261-0/+14
| | | | | | | | | | | | Closes #9913. We need to expand the match shorthand syntax for every path.
| * bugfix, when matching multiple paths with `get`, `post`, ...Yves Senn2013-03-261-0/+15
| | | | | | | | | | | | This problem was introduced with: https://github.com/rails/rails/commit/d03aa104e069be4e301efa8cefb90a2a785a7bff
* | fix regression in Mapper when `format:` was used in a `scope`.Yves Senn2013-04-031-0/+22
|/ | | | | | | Closes #10071 `#normalize_path!` depends on the options so we need to call `#normalize_options!` first to make sure everything is set correctly.
* Raise an ArgumentError when a clashing named route is definedTrevor Turk2013-03-191-19/+18
|
* Use custom visitor class for optimized url helpersAndrew White2013-03-031-0/+6
| | | | | | | | Rather than trying to use gsub to remove the optional route segments, which will fail with nested optional segments, use a custom visitor class that returns a empty string for group nodes. Closes #9524
* `format: true` does not override existing format constraints.Yves Senn2013-02-271-0/+24
| | | | | | | Closes #9466. Passing `format: true` used to override the constraints: { format: /json/ } with `/.+/`. This patch only sets the format if there is no constraint present.
* allow non-String default params in the router.Yves Senn2013-02-261-1/+21
| | | | | | | Closes #9435. Skip valid encoding checks for non-String parameters that come from the matched route's defaults.
* the router allows String contraints.Yves Senn2013-02-261-0/+36
| | | | Closes #9432.
* determine the match shorthand target early.Yves Senn2013-02-211-0/+27
| | | | | | | | Closes #7554. This patch determines the `controller#action` directly in the `match` method when the shorthand syntax is used. this prevents problems with namespaces and scopes.
* the `:controller` option for routes can contain numbers. closes #9231.Yves Senn2013-02-091-0/+12
|
* ruby constant syntax is not supported as routing `:controller` option.Yves Senn2013-02-061-9/+40
| | | | | | | | | | The current implementation only works correctly if you supply the `:controller` with directory notation (eg. `:controller => 'admin/posts'`). The ruby constant notation (eg. `:controller => 'Admin::Posts`) leads to unexpected problems with `url_for`. This patch prints a warning for every non supported `:controller` option. I also added documentation how to work with namespaced controllers. The warning links to that documentation in the rails guide.
* Duplicate possible frozen string from routeAndrew White2013-01-211-0/+9
| | | | | | | | | | | | | Ruby 1.9 freezes Hash string keys by default so where a route is defined like this: get 'search' => 'search' then the Mapper will derive the action from the key. This blows up later when the action is added to the parameters hash and the encoding is forced. Closes #3429
* Change the behavior of route defaultsAndrew White2013-01-151-0/+28
| | | | | | | | | | | | | | | | | | | This commit changes route defaults so that explicit defaults are no longer required where the key is not part of the path. For example: resources :posts, bucket_type: 'posts' will be required whenever constructing the url from a hash such as a functional test or using url_for directly. However using the explicit form alters the behavior so it's not required: resources :projects, defaults: { bucket_type: 'projects' } This changes existing behavior slightly in that any routes which only differ in their defaults will match the first route rather than the closest match. Closes #8814
* Add support for other types of routing constraintsAndrew White2013-01-151-0/+48
| | | | | | | | | | | | | | This now allows the use of arrays like this: get '/foo/:action', to: 'foo', constraints: { subdomain: %w[www admin] } or constraints where the request method returns an Fixnum like this: get '/foo', to: 'foo#index', constraints: { port: 8080 } Note that this only applies to constraints on the request - path constraints still need to be specified as Regexps as the various constraints are compiled into a single Regexp.
* Fixed issue where routes with globs caused constraints on that glob toMaura Fitzgerald2012-12-041-0/+29
| | | | | | be ignored. A regular expression constraint gets overwritten when the routes.rb file is processed. Changed the overwriting to an ||= instead of an = assignment.
* Improve clarity of routing testsAndrew White2012-11-261-634/+1081
| | | | | | | | | | | | | | | | | Move the routes for each test inside the test method so that it's easier to see which routes are applicable to which test. To ensure that each test wasn't invalidated the changes were done by first removing all of the routes, ensuring that all of the tests failed and then adding the routes back to each test one by one. One test for `assert_recognizes` was removed as it wasn't actually testing the defined routes and is now tested more thoroughly in routing_assertions_test.rb. One downside is that the test suite takes about 1s longer due to having to using `method_missing` for handling the url helpers as using `include url_helpers` isn't isolated for each test.
* Allow setting a symbol as path in scope on routesGuillermo Iguaran2012-11-211-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | Was surprising found that this example doesn't work: scope :api do resources :users end and the right form to use it is: scope 'api' do resources :users end I think this should work similary as `namespace` where both are allowed. These two are equivalent: namespace :api do resources :users end namespace 'api' do resources :user end
* Add test to avoid regression of 1bfc5b4Rafael Mendonça França2012-11-021-0/+8
|
* Revert "Merge pull request #7668 from Draiken/fix_issue_6497"Rafael Mendonça França2012-11-021-7/+0
| | | | | | | | | | | | | | This reverts commit f4ad0ebe7a6b17658bddfeb996e3c34835b75623, reversing changes made to 8b2cbb3a832101f0e672ee309beca0f8c555b292. Conflicts: actionpack/CHANGELOG.md REASON: This added introduced a bug when you have a shorthand route inside a nested namespace. See https://github.com/rafaelfranca/rails/commit/281367eb770faf8077c1fd6194188e92ed1637a1
* resource and resources do no longer modify passed optionsYves Senn2012-10-011-0/+20
| | | | this is a patch for #7777.
* Removing to_shorthand from default_controller_and_action. Fixes #6497Luiz Felipe2012-09-191-0/+7
| | | | | When using shortcut routes inside an engine the "to_shorthand" variable is set to true, causing the module scope of the route to not be applied.
* Add Missing Keys from Journey on failed URL formatschneems2012-08-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | Many named routes have keys that are required to successfully resolve. If a key is left off like this: <%= link_to 'user', user_path %> This will produce an error like this: No route matches {:action=>"show", :controller=>"users"} Since we know that the :id is missing, we can add extra debugging information to the error message. No route matches {:action=>"show", :controller=>"users"} missing required keys: [:id] This will help new and seasoned developers look closer at their parameters. I've also subclassed the routing error to be clear that this error is a result of attempting to generate a url and not because the user is trying to visit a bad url. While this may sound trivial this error message is misleading and confuses most developers. The important part isn't what's in the options its's what's missing. Adding this information to the error message will make debugging much more obvious. This is the sister pull request of https://github.com/rails/journey/pull/44 which will be required to get they missing keys into the correct error message. Example Development Error in Rails: http://cl.ly/image/3S0T0n1T3421
* removes usage of Object#in? from the code base (the method remains defined ↵Xavier Noria2012-08-061-1/+1
| | | | | | | | | | | | | | | | | | | by Active Support) Selecting which key extensions to include in active_support/rails made apparent the systematic usage of Object#in? in the code base. After some discussion in https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d we decided to remove it and use plain Ruby, which seems enough for this particular idiom. In this commit the refactor has been made case by case. Sometimes include? is the natural alternative, others a simple || is the way you actually spell the condition in your head, others a case statement seems more appropriate. I have chosen the one I liked the most in each case.
* load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-021-1/+0
|
* Don't assume resource param is :id when using shallow routesAndrew White2012-07-201-0/+12
| | | | | Since #5581 added support for resources with custom params we should not assume that it is :id when using shallow resource routing.
* Support constraints on resource custom params when nestingAndrew White2012-07-201-1/+12
| | | | | | | The Mapper looks for a :id constraint in the scope to see whether it should apply a constraint for nested resources. Since #5581 added support for resource params other than :id, we need to check for a constraint on the parent resource's param name and not assume it's :id.
* Add support for optional root segments containing slashesAndrew White2012-07-171-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optional segments with a root scope need to have the leading slash outside of the parentheses, otherwise the generated url will be empty. However if the route has non-optional elements then the leading slash needs to remain inside the parentheses otherwise the generated url will have two leading slashes, e.g: Blog::Application.routes.draw do get '/(:category)', :to => 'posts#index', :as => :root get '/(:category)/author/:name', :to => 'posts#author', :as => :author end $ rake routes root GET /(:category)(.:format) posts#index author GET (/:category)/author/:name(.:format) posts#author This change adds support for optional segments that contain a slash, allowing support for urls like /page/2 for the root path, e.g: Blog::Application.routes.draw do get '/(page/:page)', :to => 'posts#index', :as => :root end $ rake routes root GET /(page/:page)(.:format) posts#index Fixes #7073
* Remove more tests related to draw external routes filesRafael Mendonça França2012-06-291-49/+0
| | | | Related with 5e7d6bba79393de0279917f93b82f3b7b176f4b5