assert_recognizes don't aware of constraints #8679

Open
mmontossi opened this Issue Jan 1, 2013 · 12 comments

Comments

Projects
None yet

I notice in the method recognized_request_for used in assert_recognizes that it's not aware of the constraints of a route, so will always trigger an RoutingError exception.

https://github.com/rails/rails/blob/v3.2.9.rc3/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L210

Member

senny commented Jan 2, 2013

/cc @pixeltrix

this could be related to #8294

Definitely related to that issue, thanks @senny.

Contributor

JonRowe commented Feb 27, 2013

There's a PR in progress that might fix this #6922, but has anyone tried to see if this is an issue in Rails4?

Contributor

betesh commented Dec 3, 2013

Any decent workarounds?

Owner

pixeltrix commented Dec 4, 2013

@betesh use ActionDispatch::IntegrationTest to test your constraints is the best solution as this builds a full stack rather than mocking everything.

Owner

pixeltrix commented Jan 5, 2014

Part of the plan for 4.2 is to make functional tests and integration tests equivalent so as part of that assert_recognizes will be made aware of constraints.

pixeltrix was assigned Jan 5, 2014

mmontossi added the stale label Apr 23, 2014

Owner

rafaelfranca commented May 1, 2014

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

laurocaetano removed the stale label May 2, 2014

@rafaelfranca rafaelfranca modified the milestone: 4.2.0, 5.0.0 Aug 18, 2014

@gsamokovarov gsamokovarov added a commit to gsamokovarov/rails that referenced this issue Sep 8, 2014

@gsamokovarov gsamokovarov Mock the requests in recognize_path with a whole environment
If you have complex route constraints, which depend on specific headers,
for example, you cannot recognize them with the current state of
`recognize_path`. I've hit this in an app.

Currently, I pass the Pass `environment` to the Rack mock request, so I
can plug the HTTP headers I need for the constraint to pass. Did it in a
way, that doesn't change the current interface of the method. Don't know
how many people use it in practice, though.

If you guys think that we can add this to `assert_recognizes` as well, I
can do it as well.

Please, @pixeltrix if you have another plan of action for this method,
please I'll be glad to help with that too.

A few possibly related issues: #8679, #8294, #6922.
edd22e9

@gsamokovarov gsamokovarov added a commit to gsamokovarov/rails that referenced this issue Sep 8, 2014

@gsamokovarov gsamokovarov Mock the requests in recognize_path with a whole environment
If you have complex route constraints, which depend on specific headers,
for example, you cannot recognize them with the current state of
`recognize_path`. I've hit this in an app.

Currently, I pass the Pass `environment` to the Rack mock request, so I
can plug the HTTP headers I need for the constraint to pass. Did it in a
way, that doesn't change the current interface of the method. Don't know
how many people use it in practice, though.

If you guys think that we can add this to `assert_recognizes` as well, I
can do it as well.

Please, @pixeltrix if you have another plan of action for this method,
please I'll be glad to help with that too.

A few possibly related issues: #8679, #8294, #6922.
228dfa2

@gsamokovarov gsamokovarov added a commit to gsamokovarov/rails that referenced this issue Sep 8, 2014

@gsamokovarov gsamokovarov Mock the requests in recognize_path with a whole environment
If you have complex route constraints, which depend on specific headers,
for example, you cannot recognize them with the current state of
`recognize_path`. I've hit this in an app.

Currently, I pass the Pass `environment` to the Rack mock request, so I
can plug the HTTP headers I need for the constraint to pass. Did it in a
way, that doesn't change the current interface of the method. Don't know
how many people use it in practice, though.

If you guys think that we can add this to `assert_recognizes` as well, I
can do it as well.

Please, @pixeltrix if you have another plan of action for this method,
please I'll be glad to help with that too.

A few possibly related issues: #8679, #8294, #6922.
dc3b9b6

rails-bot added the stale label Jan 2, 2015

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

jensb commented Jan 8, 2015

I tried something similar (see http://stackoverflow.com/questions/27840410) on Rails 3.2.21 and 4.1.9 and my tests fail as soon as I insert a constraints: hash into my namespaced route. If I remove it, tests work again, but since the constraints hash defines a subdomain, this is not a solution for production.
The code referenced on StackOverflow worked fine on Rails 3.0.20. It does NOT work on 4-2-stable as of today.

So this is still a bug that needs to be fixed.

jensb commented Jan 21, 2015

Is anybody working on this issue? Please respond. Thank you!

Contributor

dmitry commented Jan 22, 2015

Don't believe so. If you are really need this to be fixed, please write at least test case and create a PR.

@rafaelfranca rafaelfranca added pinned and removed stale labels Mar 20, 2015

rafaelfranca removed this from the 5.0.0 [temp] milestone Apr 5, 2016

Member

maclover7 commented Apr 20, 2016

#22435 could end up being a solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment