New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route constraint matcher class doesn't receive adequate request object during tests #2781

Closed
tristanm opened this Issue Aug 31, 2011 · 2 comments

Comments

Projects
None yet
3 participants
@tristanm

Given a hypothetical (and overly simple) constrained route:

match ":one(/:two(/:three))", :constraints => CategorizationHelper, :as => :categorization

with CategorizationHelper:

module CategorizationHelper
  def self.matches?(request)
    params = request.symbolized_path_parameters

    params[:one] == 'hello' && params[:two] == 'world' && params[:three] == 'foo'
  end
end

This will match fine for a real world request to /hello/world/foo.

However, given the functional test:

require 'test_helper'

class HypotheticalControllerTest < ActionController::TestCase
  fixtures :all

  test 'hypothetical constrained routes get to the right place' do
    assert_recognizes({
      :controller => 'hypothetical',
      :action => 'index',
      :one => 'hello',
      :two => 'world',
      :three => 'foo'
    }, 'hello/world/foo')
  end
end

This will always raise the following error during testing:

ERROR hypothetical constrained routes get to the right place (0.30s) 
    ActionController::RoutingError: No route matches [GET] "/hello/world/foo"

From what I can tell by reading the Rails source, the dummy request that is passed to matches? by assert_recognises is an empty one. It doesn't contain any parameters that would be available to a real request so the match will always fail (unless it is designed to pass when the parameters are missing).

Perhaps the routing assertions could create a real request or something closer to it?

@sjtipton

This comment has been minimized.

Show comment
Hide comment
@sjtipton

sjtipton Sep 1, 2011

This is strikingly similar to my issue from yesterday... Glad to know someone else is experiencing it!

#2774

sjtipton commented Sep 1, 2011

This is strikingly similar to my issue from yesterday... Glad to know someone else is experiencing it!

#2774

mattfawcett added a commit to mattfawcett/rails that referenced this issue Feb 24, 2012

tenderlove added a commit that referenced this issue Feb 29, 2012

@sikachu

This comment has been minimized.

Show comment
Hide comment
@sikachu

sikachu Apr 27, 2012

Member

#5219 was merged as a fixed for this issue, so I'm closing this.

Member

sikachu commented Apr 27, 2012

#5219 was merged as a fixed for this issue, so I'm closing this.

@sikachu sikachu closed this Apr 27, 2012

bronson added a commit to bronson/rails that referenced this issue May 4, 2012

myabc added a commit to opf/openproject that referenced this issue Nov 5, 2014

Update routing specs to account for query params
Appears to relate to:
  rspec/rspec-rails#712
  rails/rails#2781

Signed-off-by: Alex Coles <alex@alexbcoles.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment