Forum: Ruby on Rails follow_redirect bug for ivars?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71c90d30f8c437a593aeb5588408ec1a?d=identicon&s=25 Jon (Guest)
on 2007-02-14 09:03
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.
71c90d30f8c437a593aeb5588408ec1a?d=identicon&s=25 Jon (Guest)
on 2007-02-15 00:25
Meager attempt to revive this post here...anyone ever seen this issue?
I think my Rails version is 1.2.1.
This topic is locked and can not be replied to.