aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing
Commit message (Collapse)AuthorAgeFilesLines
* Support testing of non-ActionDispatch-routed apps.Darren Cheng2019-02-051-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The [Grape API framework](https://github.com/ruby-grape/grape) regularly writes tests like [spec/grape/api_spec.rb](https://github.com/ruby-grape/grape/blob/master/spec/grape/api_spec.rb). When attempting to write a test in a Rails environment similar to the following: ``` describe Grape::Api, type: :request do let(:app) { Class.new(Grape::API) do get 'test' do { foo: 'bar' } end end } it '200s' do get 'test' end end ``` The following exception is thrown: ``` NoMethodError: undefined method `url_helpers' for #<Array:0x00007fb4e4bc4c88> -- 0: .../lib/action_dispatch/testing/integration.rb:330:in `block in create_session' 1: .../lib/action_dispatch/testing/integration.rb:326:in `initialize' 2: .../lib/action_dispatch/testing/integration.rb:326:in `new' 3: .../lib/action_dispatch/testing/integration.rb:326:in `create_session' 4: .../lib/action_dispatch/testing/integration.rb:316:in `integration_session' 5: .../lib/action_dispatch/testing/integration.rb:348:in `block (2 levels) in <module:Runner>' ``` This change explicitly ensures that `app.routes` is an `ActionDispatch::Routing::RouteSet` instance.
* Revert "Merge pull request #33970 from rails/eager-url-helpers"schneems2018-10-031-5/+5
| | | | | | | Until #34050 can be resolved This reverts commit 7f870a5ba2aa9177aa4a0e03a9d027928ba60e49, reversing changes made to 6556898884d636c59baae008e42783b8d3e16440.
* Merge branch 'master' into eager-url-helpersAaron Patterson2018-09-261-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: Remove force parent loading when counter cache child is created/destroyed Raise an error when loading all fixtures from nil fixture_path Revert "Remove `counter_cache_target` which is no longer called" Update counter cache in memory if parent target is existed If association is a hash-like object preloading fails Use the same option for create database statements between Raketask and travis.rb Fix "warning: shadowing outer local variable - config" Remove `counter_cache_target` which is no longer called Fix more offences Change the empty block style to have space inside of the block Fix a content_for test description Stringify database configurations Improve error message when assign wrong attributes to model
| * Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-251-2/+2
| |
* | Eagerly build the routing helper module after routes are committedAaron Patterson2018-09-251-5/+5
|/ | | | | | | | | | | | | | This commit eagerly builds the route helper module after the routes have been drawn and finalized. This allows us to cache the helper module but not have to worry about people accessing the module while route definition is "in-flight", and automatically deals with cache invalidation as the module is regenerated anytime someone redraws the routes. The restriction this commit introduces is that the url helper module can only be accessed *after* the routes are done being drawn. Refs #24554 and #32892
* Rails guides are now served over httpsPaul McMahon2018-07-241-5/+5
| | | | | http links will be redirected to the https version, but still better to just directly link to the https version.
* Fix routing inspector tests broken in ↵Kasper Timm Hansen2018-03-131-14/+15
| | | | | | | | | | https://github.com/rails/rails/commit/6629d51a2756fadf961bb09df20579cacfef2c8e * Renames grep_pattern to grep throughout. * Fixes setup not calling super by calling setup with a block. * Converts test helper method to a private one, like we have it other places. * Uses keyword arguments to get around awkward draw({ grep: "x" }, Action…) construction.
* Introduce `ActionDispatch::Routing::ConsoleFormatter::Base`bogdanvlviv2018-03-131-11/+11
| | | | | | | | | | | | | | - Create `Base` and inherit `Sheet` and `Expanded` in order to - prevent code duplication. - Remove trailing "\n" for components of `Expanded`. - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead. - Change `no_routes` message "No routes were found for this controller" since if use `-g`, it sounds incorrect. - Display `No routes were found for this controller.` if apply `-c`. - Display `No routes were found for this grep pattern.` if apply `-g`. Related to #32130
* Draw line of a route name to the end of row console on `rails routes --expanded`bogdanvlviv2018-03-051-5/+10
| | | | | | | In order to get width of console use `IO::console_size`, See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size Related to #32130
* Add --expanded option to "rails routes"Benoit Tigeot2018-02-281-2/+66
| | | | | | | | | | | | | | | | | | | | | | | | | When using rails routes with small terminal or complicated routes it can be very difficult to understand where is the element listed in header. psql had the same issue, that's why they created "expanded mode" you can switch using `\x` or by starting psql with ``` -x --expanded Turn on the expanded table formatting mode. This is equivalent to the \x command. ``` The output is similar to one implemented here for rails routes: db_user-# \du List of roles -[ RECORD 1 ]---------------------------------------------- Role name | super Attributes | Superuser, Create role, Create DB Member of | {} -[ RECORD 2 ]---------------------------------------------- Role name | role Attributes | Superuser, Create role, Create DB, Replication Member of | {}
* Use frozen string literal in actionpack/Kir Shatrov2017-07-295-0/+10
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-025-5/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-025-0/+5
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-015-0/+5
| |
* | Properly register "custom" URL helpers as named helpers.Wilson Bilkovich2017-06-301-0/+6
|/ | | | | | | | | | | | | CustomUrlHelpers were introduced in ce7d5fb2e6, closing issue #22512. They currently register themselves in an ivar that is never accessed. This change removes the @custom_helpers special-case, and registers them the way named routes are normally handled. Without this, you can get route_defined?(:example_url) == false, while still being able to call url_helpers.example_url and example_path. Various popular gems such as 'rspec-rails' make use of route_defined?() when determining how to proxy method calls or whether to define a route.
* Fix missing formats in route-set URLsJonathan del Strother2017-06-231-0/+9
| | | | | | | | | | | Before this change, handle_positional_args would end up mutating @segment_keys if inner_options included path components. Subsequent calls would then be missing the implicit path components. eg: user_path(1, :json) # => "/users/1.json" (correct) user_path(1, format: :json) # => "/users/1.json" (correct, but @segment_keys was mutated) user_path(1, :json) # => "/users/1" (oh no!)
* Reuse the Parameters#to_h check in the routing helpersRafael Mendonça França2017-04-181-4/+4
| | | | | Since this protection is now in Parameters we can use it instead of reimplementing again.
* Add support for calling nested direct routes (#28462)Andrew White2017-03-171-8/+28
| | | | | | | | | | | | | | | | | | | | Not all requirements can be expressed in terms of polymorphic url options so add a `route_for` method that allows calling another direct route (or regular named route) which a set of arguments, e.g: resources :buckets direct :recordable do |recording| route_for(:bucket, recording.bucket) end direct :threadable do |threadable| route_for(:recordable, threadable.parent) end This maintains the context of the original caller, e.g. threadable_path(threadable) # => /buckets/1 threadable_url(threadable) # => http://example.com/buckets/1
* Clarify use of params in `direct`Andrew White2017-02-221-0/+14
| | | | | | | | | Since a `direct` url helper block is evaluated using `instance_exec` then methods that are available in the instance context can be accessed, e.g. the params object in a controller action or view. This wasn't clear from the example so expand on that point and add a test case for this situation.
* Split direct method into twoAndrew White2017-02-211-35/+75
| | | | | Use a separate method called `resolve` for the custom polymorphic mapping to clarify the API.
* Removed `model_name` method to prevent warningAndrew White2017-02-211-0/+1
|
* Support mapping of non-model classesAndrew White2017-02-211-0/+23
|
* Raise an error if `direct` is inside a scope blockAndrew White2017-02-211-0/+12
|
* Add custom polymorphic mappingAndrew White2017-02-211-1/+71
| | | | | | | | | | | | | | | | Allow the use of `direct` to specify custom mappings for polymorphic_url, e.g: resource :basket direct(class: "Basket") { [:basket] } This will then generate the following: >> link_to "Basket", @basket => <a href="/basket">Basket</a> More importantly it will generate the correct url when used with `form_for`. Fixes #1769.
* Add test for calling a url helper in Mapper#directAndrew White2017-02-211-0/+7
|
* Only accept symbols and strings for Mapper#directAndrew White2017-02-211-0/+17
|
* Rename url_helper to directAndrew White2017-02-211-12/+12
|
* Add support for defining custom url helpers in routes.rbAndrew White2017-02-211-0/+121
| | | | | | | | | | | Allow the definition of custom url helpers that will be available automatically wherever standard url helpers are available. The current solution is to create helper methods in ApplicationHelper or some other helper module and this isn't a great solution since the url helper module can be called directly or included in another class which doesn't include the normal helper modules. Reference #22512.
* stop using removed `render :text`yuuji.yaginuma2016-12-031-1/+1
| | | | Follow up to 79a5ea9eadb4d43b62afacedc0706cbe88c54496
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
|
* applies remaining conventions across the projectXavier Noria2016-08-062-3/+1
|
* modernizes hash syntax in actionpackXavier Noria2016-08-062-13/+13
|
* applies new string literal convention in actionpack/testXavier Noria2016-08-064-84/+84
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* More Action Pack `abstract_unit` cleanup (#25211)Jon Moss2016-05-311-0/+2
| | | | | - Remove dead classes / dead code - Move class definitions to where they are used, don't define in a shared space
* Merge pull request #23103 from rails/refactor-handling-of-action-defaultJeremy Daer2016-04-241-1/+1
|\ | | | | | | Refactor handling of :action default in routing
| * Refactor handling of :action default in routingAndrew White2016-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The longstanding convention in Rails is that if the :action parameter is missing or nil then it defaults to 'index'. Up until Rails 5.0.0.beta1 this was handled slightly differently than other routing defaults by deleting it from the route options and adding it to the recall parameters. With the recent focus of removing unnecessary duplications this has exposed a problem in this strategy - we are now mutating the request's path parameters and causing problems for later url generation. This will typically affect url_for rather a named url helper since the latter explicitly pass :controller, :action, etc. The fix is to add a default for :action in the route class if the path contains an :action segment and no default is passed. This change also revealed an issue with the parameterized part expiry in that it doesn't follow a right to left order - as soon as a dynamic segment is required then all other segments become required. Fixes #23019.
* | [ci skip] Use rails routes instead of rake routes in inspector test descriptionAbhishek Jain2016-03-021-9/+9
| |
* | Deprecate :controller and :action path parametersAndrew White2016-03-011-4/+12
| | | | | | | | | | | | | | | | Allowing :controller and :action values to be specified via the path in config/routes.rb has been an underlying cause of a number of issues in Rails that have resulted in security releases. In light of this it's better that controllers and actions are explicitly whitelisted rather than trying to blacklist or sanitize 'bad' values.
* | Add `internal` attribute to routesJon Moss2016-02-221-0/+23
|/ | | | | | | | | | | | | | This is meant to provide a way for Action Cable, Sprockets, and possibly other Rack applications to mark themselves as internal, and to exclude themselves from the routing inspector, and thus `rails routes` / `rake routes`. I think this is the only way to have mounted Rack apps be marked as internal, within AD/Journey. Another option would be to create an array of regexes for internal apps, and then to iterate over that everytime a request comes through. Also, I only had the first `add_route` method set `internal`'s default to false, to avoid littering it all over the codebase.
* Add options for rake routes taskVipul A M2016-02-021-7/+27
| | | | | | | | | | Add two options: `-c` and `-g`. `-g` option returns the urls name, verb and path fields that match the pattern. `-c` option returns the urls for specific controller. Fixes #18902, and Fixes #20420 [Anton Davydov & Vipul A M]
* Better error message when running `rake routes` with CONTROLLER arg:Edouard CHIN2016-01-071-0/+38
| | | | | | | - `CONTROLLER` argument can now be supplied in different ways (Rails::WelcomeController, Rails::Welcome, rails/welcome) - If `CONTROLLER` argument was supplied but it does not exist, will warn the user that this controller does not exist - If `CONTROLLER` argument was supplied and no routes could be found matching this filter, will warn the user that no routes were found matching the supplied filter - If no routes were defined in the config/routes.rb file, will warn the user with the original message
* Remove skipped JRuby tests that are passing on 9.0.3.0.Guo Xiang Tan2015-10-271-2/+0
|
* Change `Journey::Route#verb` to return string instead of regexp.yui-knk2015-10-031-0/+11
| | | | | | | | | By [this commit](https://github.com/rails/rails/commit/0b476de445faf330c58255e2ec3eea0f3a7c1bfc) `Journey::Route#verb` need not to return verb as regexp. The returned value is used by inspector, so change it to be a string. Add inspect_with_multiple_verbs test case to keep the behavior of inspector correctly.
* Merge pull request #19788 from cmdrclueless/actionpack_http_url_ipv6Rafael Mendonça França2015-09-011-0/+45
|\ | | | | Fix broken IPv6 addresses handling
| * Fix broken IPv6 addresses handlingBrian Weaver2015-04-161-0/+45
| |
* | Get rid of mocha tests - part 2Marcin Olichwirowicz2015-08-251-9/+0
| |
* | Skip a few failing tests on JRuby with the attached ticketsRobin Dupret2015-07-171-0/+2
| |
* | Prefer assert_not over refuteRafael Mendonça França2015-05-181-1/+1
| |
* | ActionDispatch::Journey::Routes#empty? test casesValentine Valyaeff2015-05-191-0/+14
| |