Skip to content
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

Passing locale as param does not work with rails 3.2.3 #36

Closed
klobuczek opened this issue Apr 3, 2012 · 12 comments
Closed

Passing locale as param does not work with rails 3.2.3 #36

klobuczek opened this issue Apr 3, 2012 · 12 comments

Comments

@klobuczek
Copy link

Looks like passing locale in params does not work with rails 3.2.3 anymore.

@designium
Copy link

I also had issue with 3.2.3.

@joost
Copy link

joost commented Apr 12, 2012

Indeed I have the same issue when running rspec tests in Rails 3.2.3. Rails 3.2.2 works correctly.

@mjonuschat
Copy link
Collaborator

Could one of you provide a failing test case or a small rails app exhibiting this behaviour?

@klobuczek
Copy link
Author

I couldn't reproduce the problem by adding a test case to router-filter unit tests. It seem to appear only in combination of rails 3.2.3 and rspec.
This line:
get :edit, id: situation.id, locale: :de
will properly set the locale in rails 3.2.2 but not 3.2.3.
In non test mode locale params seems to be recognized properly even in rails 3.2.3.

@mjonuschat
Copy link
Collaborator

I've tracked the source of the problem down to this commit in rails/rails@275ee0d

The merging of the additional controller parameters in the test environment has been removed there.

Haven't found a way around that though. Any ideas are appreciated

@dvandersluis
Copy link

I'm running into this as well, any updates or workarounds?

@joost
Copy link

joost commented May 4, 2012

Use Rails 3.2.2 :)

@dvandersluis
Copy link

Changing line 64 of filters/locale.rb from

locale = params.delete(:locale) 

to

locale = params[:locale]

seems to fix this issue for RSpec at least, but I can't tell if it's going to affect anything else (filtered routes are still working properly in my development app) and I can't get the routing-filter tests to run here.

@mjonuschat
Copy link
Collaborator

Ok, I just spent a couple of hours to this issue and my conclusion is that it was a lucky coincidence that these tests ever worked. What happend on Rails <= 3.2.2 is basically this:

  1. Duplicate the params hash and directly assign it as the ActionController::TestCase params hash
  2. Call build_request_uri
  3. RoutingFilter gets called and removes params from the hash depending on the active filters
  4. The generated Url gets assigned
  5. Action within the tested controller gets dispatched without calling the router
  6. Tests see the param hash from step 1 - not the params hash the real router would have generated

Rails 3.2.3 removes step 1, so now some params get lost as they get encoded in the url but not decoded by the router.

The quick and easy workaround is adding

RoutingFilter.active = false

to your test_helper.rb or spec_helper.rb. If you are running tests for the routing you can re-enable routingfilter there, the router and thus routing-filter gets called correctly in those tests.

@joost
Copy link

joost commented May 7, 2012

Cool. Thanks for the fix and all the effort!

On 7 mei 2012, at 23:15, yabawockreply@reply.github.com wrote:

Ok, I just spent a couple of hours to this issue and my conclusion is that it was a lucky coincidence that these tests ever worked. What happend on Rails <= 3.2.2 is basically this:

  1. Duplicate the params hash and directly assign it as the ActionController::TestCase params hash
  2. Call build_request_uri
  3. RoutingFilter gets called and removes params from the hash depending on the active filters
  4. The generated Url gets assigned
  5. Action within the tested controller gets dispatched without calling the router
  6. Tests see the param hash from step 1 - not the params hash the real router would have generated

Since the filters never got tested the quick and easy workaround is adding

RoutingFilter.active = false

to the test_helper.rb or spec_helper.rb

If you are running tests for the routing you can re-enable routingfilter there, the router and thus routing-filter gets called correctly in those tests.


Reply to this email directly or view it on GitHub:
#36 (comment)

mjonuschat added a commit that referenced this issue May 7, 2012
@mjonuschat
Copy link
Collaborator

Closing since the cause is in upstream rails, it's not a real bug and a viable workaround is available and documented.

@dvandersluis
Copy link

👍 Thanks for figuring this out, yabawock!

alexandred pushed a commit to alexandred/music that referenced this issue Nov 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants