I didn’t open this on github cause I am unsure if this is an intended feature or a bug.
Currently the constraint object has access to the request object and can modify its parameters. Ie.
module RouteConstraints class VanitySlug def matches?(request) vanity_url = request.path_parameters[:vanity_url] if vanity_url =~ /^filter-/ filter_string = vanity_url.gsub(/^filter-/, '') filter_dictionary = FilterDictionary.new(filter_string) request.path_parameters[:filter_ids] = filter_dictionary.ids return true end false end end end
the automated route test helpers (https://github.com/rails/rails/blob/77627c5aa3b9aeb68a53ad4a700f5003f2f24089/actionpack/lib/action_dispatch/testing/assertions/routing.rb) will not pick up the new parameter, which is why I started thinking this might be a bug. In that case passing a frozen request object to the constraint would a way to ensure the constraint responsibility.
Personally when I look at the constraint I would not expect it to change the request. I’d delegate that to a request transformer.
Can somebody clarify if this is a supported feature or a bug?
if you’re interested about the context where I run in to this: http://teotti.com/one-url-segment-serving-different-resources-with-ruby-on-rails-route-constraints#hack-for-adventurous-people