Clarify if rails 4.1 route constraint changing request object is a feature or a bug

Hi,

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 (rails/routing.rb at 77627c5aa3b9aeb68a53ad4a700f5003f2f24089 · rails/rails · GitHub) 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.

Here’s the constraint code: rails/mapper.rb at 77627c5aa3b9aeb68a53ad4a700f5003f2f24089 · rails/rails · GitHub

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?

Thanks

ps

if you’re interested about the context where I run in to this: One URL segment serving different resources with Ruby on Rails route constraints