rails/rails — pull request #17725 by chancancode (2014-11-23 10:29:30+00:00)
Title: Deprecate use route

This is a continuation of #17453

Already in master:

* [x] Guide is fixed via b7b9e92 and backported to 4-1-stable. It should [show up on edge guide](b7b9e92093ed128c2b27a64c5732f6a98191cbf0) on the next rebuild.
* [x] The engine-oriented test cases are added via 77a2764 to prevent regressions during the 4.2 series.

In this pull request:

* [x] Deprecated passing `use_route` in `process` in controller tests
* [x] Deprecated passing an invalid route name to `Formatter#generate`, fixed a few internal test case that relied on that

As far as I can tell, the `Formatter#generate` accepting invalid route names is a bug that's been around forever.

As @huoxito pointed out, currently if you pass in *anything* that is not `nil` as the first argument to `generate`, it will try to match against just about anything that is present on the routes table. As @pixeltrix has discovered in 1555a18, this leads to incorrect results, in particular when engines are involved.

Unfortunately, this is actually why the `use_route` hack worked in the first place – the `mount Foo::Engine => '/foo'` entry in the dummy app does not actually generate a named route called "foo", so it appears that the only reason it works currently is because of this bug. So we basically documented a buggy behavior which means we can't just fix it. I added a separate deprecation for it and so we should be able to fix it in the next version.

By the way, to answer @pixeltrix's question... From what I can tell `ActionController::TestCase` on its own actually work perfectly fine with engine controllers *without any special configuration*, overriding `@routes` or whatsoever. (As demonstrated in [this test case](https://github.com/rails/rails/commit/77a276411e717353bc562c04d62e144f4410e706#diff-279ac5c088a3ee7e9f954bbc10d1b773R772).)

The reason it doesn't work out of the box in a generated engine is that the generated `test_helper` always [require the dummy application](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb#L4) and then [require the `test_help` file](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb#L11), which [defaults the `@routes` to `Rails.application.routes`](https://github.com/rails/rails/blob/master/railties/lib/rails/test_help.rb#L35).

I suppose we should improve that situation... but that's out of the scope of this PR and I'm not sure if I'll have time to work on that anytime soon. If @huoxito or anyone else is interested please feel free to explore that further :smile:

cc @tenderlove @pixeltrix @huoxito @radar for review :smile: