diff options
author | Arthur Neves <arthurnn@gmail.com> | 2015-08-10 20:01:18 +0200 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2015-08-10 22:16:52 +0200 |
commit | 0ffaa56d51e8e0213db250ea36221c232a0c92f3 (patch) | |
tree | 9da358a0df664292f645c87e382e9a02e8665c03 /actionview | |
parent | 942f41263152277dd5d23744a97a67e8c1a8d3d4 (diff) | |
download | rails-0ffaa56d51e8e0213db250ea36221c232a0c92f3.tar.gz rails-0ffaa56d51e8e0213db250ea36221c232a0c92f3.tar.bz2 rails-0ffaa56d51e8e0213db250ea36221c232a0c92f3.zip |
Dont try to call method missing in routes if thats not what we want
If, doing a test like this:
```
class BugTest < ActionView::TestCase
def test_foo
omg
end
```
Will raise with:
```
RuntimeError: In order to use #url_for, you must include routing helpers
explicitly. For instance, `include
Rails.application.routes.url_helpers`.
```
Thats a bit confusing, as we are not calling url_for at all.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/test_case.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index c4bc26ca8a..f6b5696a13 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -263,9 +263,15 @@ module ActionView end def method_missing(selector, *args) - if @controller.respond_to?(:_routes) && - ( @controller._routes.named_routes.route_defined?(selector) || - @controller._routes.mounted_helpers.method_defined?(selector) ) + begin + routes = @controller.respond_to?(:_routes) && @controller._routes + rescue + # Dont call routes, if there is an error on _routes call + end + + if routes && + ( routes.named_routes.route_defined?(selector) || + routes.mounted_helpers.method_defined?(selector) ) @controller.__send__(selector, *args) else super |