Saturday, August 2, 2008

How to set flash in tests

Do not set the flash directly, like in the following.

fixtures :categories

def test_new_car
flash[:category] = categories(:cars)
get :new
end

You'll get a strange error: 'TypeError: can't convert String into Integer'.

Instead, use the 4th parameter to the get or post method as in the following.

fixtures :categories

def test_new_car
#flash[:category] = categories(:cars) - do NOT use it !!!
get :new, {}, {}, {:category=>categories(:cars)}
end

No comments: