Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5433 (reopened defect)

Opened 4 years ago

Last modified 2 years ago

[PATCH] ActionController::Integration::Session#redirect? doesn't always work

Reported by: peter_marklund@fastmail.fm Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version:
Severity: normal Keywords: patch
Cc:

Description

I haven't been able to track down why this happens, but I came across a redirect "302 Found" in my integration test where the redirect? method would return false since status/100 returned 151/50 which is not equal to 3. I worked around this problem by adding a to_i so that the redirect? method becomes:

def redirect?
  (status/100).to_i == 3
end

Rake runs through cleanly in actionpack with this change. I'm not sure how to reproduce this bug since status.inspect will return "302" and status.class.name is "Fixnum" when the bug occurs.

Attachments

mathn_rational.patch (1.0 kB) - added by cliffmoon on 09/06/07 18:59:45.
Patch for redirect? failure when mathn and rational are used.

Change History

08/22/06 23:13:58 changed by anonymous

Related to this issue, it is interesting to note that invoking 35/6 in irb yields 5 (class Fixnum) whereas with ./script/console it yields 35/6 (class Rational). Does Rails change the behaviour of Fixnum division and if so why?

01/16/07 17:24:58 changed by manfred

I can't reproduce this problem. Is it possible to post your integration test?

01/20/07 09:21:46 changed by peter_marklund

I can't reproduce this anymore either, maybe because of Rails 1.2? No idea really what's going on here.

01/20/07 09:26:05 changed by manfred

  • status changed from new to closed.
  • resolution set to fixed.

Apparently fixed. Please re-open if this occurs again.

09/06/07 18:59:45 changed by cliffmoon

  • attachment mathn_rational.patch added.

Patch for redirect? failure when mathn and rational are used.

09/06/07 19:04:16 changed by cliffmoon

  • status changed from closed to reopened.
  • resolution deleted.

I'm reopening this ticket, having come across this problem today. It can be reproduced by requiring the mathn and rational libraries in your rails app. This alters the behavior of integer division, causing 302/100 to return a rational instead of 3. The patch modifies redirect to use a range instead of division.

The patch also includes a modification to integration_test.rb, requiring mathn and rational to duplicate the problem. I'm not sure whether this a good idea. An alternative would be to use the sandbox gem to isolate the libraries in a single test. Thoughts?

09/06/07 20:29:54 changed by Henrik N

  • keywords set to patch.
  • summary changed from ActionController::Integration::Session#redirect? doesn't always work to [PATCH] ActionController::Integration::Session#redirect? doesn't always work.

01/17/08 04:19:05 changed by chris.catton

+1

03/13/08 15:54:37 changed by bbrinck

I also ran into this yesterday after trying to use Ruby Classifier in my Rails project (classifier requires mathn). This repros reliably if you require mathn in an integration test that uses post_via_redirect and then try to assert :success (the post_via_redirect doesn't seem to work correctly so the assert fails).