Hi,
I’m getting a bit frustated here. I’m trying to test the following code
in my User controller:
def validate
if params[:user_id] and params[:key]
@user = User.find(:first,
:conditions => [“id= ? AND security_token = ? AND
token_expiry >= now()”, params[:user_id], params[:key]])
if @user
@user.verified = 1
@user.update
flash[:notice] = "Uw account is geverifieerd. Welkom op onze
site."
redirect_to :action => ‘login’
else
flash[:notice] = “Uw account kon niet geverifieerd worden.”
end
else
redirect_to :action => ‘signup’
end
end
validates get called like:
http://localhost:3000/user/validate?user_id=15&key=4f0f73620459a199c2816afb32fd4599
I’m trying to test it as follows:
def test_validate
get :validate, { :user_id => 1000005, :key => “abc” }
assert_equal 1, User.count
assert_equal 1, User.verified
assert_equal 1, ActionMailer::Base.deliveries.size
assert_redirected_to :action => “login”
end
The first line get :validate … works. But the second line returns 6 (I
have 6 users in my user fixture), but according to my validate method it
should only return 1 user. I have tried different kind of things, but
cann’t get the test to work.
Hope somebody has some helpful comments. Code improvements are always
greatly appreciated!
Kind regards,
Nick