Re: assert_equal Test - how to test updates

vihrao
Tue, 02 Feb 2010 18:03:16 -0000

I meant it does not update the value from ''77a38'' to
''77a138''

vihrao wrote:
>
> I am testing an update via assert_equal and it does not seem to work.
>
> I have this fixture:
> bob1:
>   id: 1000001
>   login: bob
>   glogin: bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org
>   session_token: 77a38
>
> Here is my test method:
> class Guser < ActiveRecord::Base
>   def self.update_token(glogin, login, stoken)
>     u=find(:first, :conditions=>["glogin = ? AND login = ?",
glogin,
> login])
> 	return nil if u.nil?
> 	if u.session_token != stoken
> 		u.session_token = stoken
> 		u.save
> 		return u
>     end
> 	#nil
>   end
> end
>
> Here is where I call the method, where I match the
''glogin'' and ''login''
> column values and if they match I want to update the session token.
>
> require File.dirname(__FILE__) + ''/../test_helper''
> class GuserTest < ActiveSupport::TestCase
>   self.use_instantiated_fixtures  = true
>   fixtures :users
>   def test_match_login
>      assert_equal  @bob1,
Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org",
"bob",
> "77a38")
>   end
>
> The first time even if there is no record in the database it inserts and
> gives a success message:
> 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
>
> Then I run it again by changing the method argument like this to update
> the sesison token
>  assert_equal  @bob1,
Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org",
"bob", "77a138")
> It still gives a success message: 1 tests, 1 assertions, 0 failures, 0
> errors, 0 skips
>
> The new value of session token is never updated in the table column from
> ''77a38''  to ''77a38'' . Can you please
tell me how to update the sesison
> token if my glogin and login fields are found to match
>
>
>
>
>

--
View this message in context: