[openstreetmap/openstreetmap-website] Refactor site controller tests to inherit from ActionDispatch::IntegrationTest (#2596)

Andy Allan notifications at github.com
Wed Apr 22 11:56:07 UTC 2020


> Can I just clarify - are the other changes actually required when changing the inheritance or is that just general cleanup?

They are actually required. The `get` etc methods now takes either a `foo_path`, `foo_url` or `'/foo/bar'` instead of a symbol, so I went for the `foo_path` style. The session handling needs to be changed too since there's no `:session` keyword for those methods any more.

http://blog.napcs.com/2016/07/03/upgrading-rails-5-controller-tests/ has a few more details. 

There is a choice of whether to pass the parameters to the `get` method, or to the `_path`, e.g.

```
get foo_path, :params => { :bar => :baz }   # both are pretty much
get foo_path(:bar => :baz)                  # equivalent
```
This generally doesn't matter for url query parameters. However the parameters that are created by matching in the routes file (e.g. `code` in `get "/go/:code" => "site#permalink"` defined in config/routes.rb) must be given to the `_path` method e.g.

```
# this doesn't work, since permalink_path needs a `code` param:
get permalink_path, :params => { :code => 'wBz3--', :node => 1}

# this works, since the `code` path parameter is provided to permalink_path:
get permalink_path(:code => 'wBz3--'), :params => { : node => 1 } 

# this also works, since any spare params are treated as query parameters:
get permalink_path(:code => 'wBz3--', :node => 1) 
```

... so I went with the third option throughout, for consistency and less typing/reading.




-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2596#issuecomment-617732540
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20200422/0b200503/attachment.htm>


More information about the rails-dev mailing list