Follow_redirect bug for ivars?


#1

I’m getting some odd Rails behavior that is causing different behavior
in a test than I get in the development environment. The problem is
essentially this…I
define an instance variable in an action and then redirect back to the
same action, and for some reason, the instance variable is still set.
This only happens in tests though. The problem is illustrated by this
situation:

in routes.rb, I have:
map.connect ‘fun/thingy/:abc’, :controller => ‘fun’, :action =>
‘thingy’

in fun_controller.rb, we have:
def thingy
puts “Starting thingy action”
@thing1 ? (puts “@thing1 is defined at beginning”) : (puts
@thing1 is NOT defined at beginning”)
if params[:abc]
puts “Setting @thing1 to ‘Woohoo’ and raising an error”
@thing1 = “Woohoo”
raise “Some error”
end
@thing1 ? (puts “@thing1 is defined at end”) : (puts “@thing1 is
NOT defined at end”)
rescue
puts “Redirecting back to thingy, but with params[:abc]=nil”
redirect_to :controller => ‘fun’, :action => “thingy”, :abc =>
nil
return
else
render_text “@thing1 is #{@thing1}”
end

So if I go to the url /fun/thingy/foo, I get the following rendered to
my browser:
@thing1 is
Here is the printout to my console:
Starting thingy action
@thing1 is NOT defined at beginning
Setting @thing1 to ‘Woohoo’ and raising an error
Redirecting back to thingy, but with params[:abc]=nil
Starting thingy action
@thing1 is NOT defined at beginning
@thing1 is NOT defined at end

HOWEVER. Things are different in the testing environment. In
fun_controller_test.rb, I have:
def test_some_thing
get :thingy, {:abc => ‘foo’}
follow_redirect
end

Now here is the output to my console during the test:

Starting thingy action
@thing1 is NOT defined at beginning
Setting @thing1 to ‘Woohoo’ and raising an error
Redirecting back to thingy, but with params[:abc]=nil
Starting thingy action
@thing1 is defined at beginning
@thing1 is defined at end

Notice that unlike in the development cases where I was using my
browser, in this case, now that it’s a test, @thing1 remains defined the
second time the thingy action runs.

Is this a bug in Rails? I’ve been Googling around for someone with a
similar problem but haven’t found anyone.


#2

Meager attempt to revive this post here…anyone ever seen this issue?
I think my Rails version is 1.2.1.