Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Threre is no way to test routing with constraints

#4344

I did not find any way to test how my routing works with constraints. Methods

assert_generates
assert_recognizes
assert_routing

do not accept any options related to constraints

Reported by saks · April 8th, 2010 @ 11:50 AM

State: invalid
Milestone: 3.0.2
Assigned to: josh josh
Importance: Medium

Activity

  1. saks
    saks
    • Tag changed from routing testing constraints to routing, testing

    I have no any idea about how to test these routes:

    constraints(:host => /^catalog\./) do
        get 'categories'           => 'categories#index'
        get 'categories/:url_name' => 'categories#show'
    end
    

    becauses i don't see the way to change host for this request. It is hardcoded to be 'example.org':

    # Return the Rack environment used for a request to +uri+.
    def self.env_for(uri="", opts={})
      uri = URI(uri)
      uri.path = "/#{uri.path}" unless uri.path[0] == ?/
    
      env = DEFAULT_ENV.dup
    
      env["REQUEST_METHOD"] = opts[:method] ? opts[:method].to_s.upcase : "GET"
      env["SERVER_NAME"] = uri.host || "example.org"
    

    April 9th, 2010 @ 01:22 PM

  2. saks
    saks
    • Tag changed from routing, testing to constraints, routing, testing

    def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)

        expected_path = "/#{expected_path}" unless expected_path[0] == ?/
        # Load routes.rb if it hasn't been loaded.
    

    "/#{expected_path}... does not allow to pass path like "http://test.host.com/books", That's why URI(uri) cannot parse host

    April 9th, 2010 @ 01:31 PM

  3. saks
    saks
    • Assigned user set to DHH

    April 9th, 2010 @ 01:36 PM

  4. Anil Wadghule
    Anil Wadghule
    • Title changed from Threre is no way to test roting with constraints to Threre is no way to test routing with constraints

    April 9th, 2010 @ 05:24 PM

  5. José Valim
    José Valim
    • Assigned user changed from DHH to josh
    • Milestone cleared.

    @saks, please don't assign users. Wait until someone comes and assign it properly.

    April 10th, 2010 @ 12:26 PM

  6. josh
    josh
    • State changed from new to invalid

    April 11th, 2010 @ 07:09 PM

  7. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Medium

    October 15th, 2010 @ 11:01 PM