On Feb 2, 9:58 am, Vishwa Rao <[email protected]> wrote:
> I am testing with assert_equal
>
> Here is my Fixture:
> bob1:
>   id: 1000001
>   login: bob
>   glogin: [email protected]
>   session_token: 77a38 # test
>
> Here is my Test method:
> class Guser < ActiveRecord::Base
>   attr_accessor :session_token
>   def self.match_login(glogin, login, ses_token)
>     u=find(:first, :conditions=>["glogin = ? AND login = ?", glogin,
> login])
>   return nil if u.nil?
>     if (u.session_token != ses_token)
>     u.session_token = ses_token
>     return u
>     end
>     nil
>   end
> end
>
> The test database table is Guser and it has no rows to start with
>
> Here is my where I call test method:
> assert_equal �...@bob1, Guser.match_login("[email protected]", "bob", "77a038")
>
> I get this message on the console:
>   1) Failure:
> test_match_login(GuserTest) [test/unit/guser_test.rb:14]:
> <#<Guser id: 1000001, glogin: "[email protected]", login: "bob",
> session_token: "77a
> 0d943cdbace52716a9ef9fae12e45e2788d38", created_at: "2010-02-02
> 15:45:37", updat
> ed_at: "2010-02-02 15:45:37">> expected but was
> <nil>.
> 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
>

You want users(:bob1), not @bob1, in your test (unless you've
explicitly turned on use_instantiated_fixtures = true in your
test_helper.rb).

Jeff

purpleworkshops.com

> I expected the test to fail as there was no record in the database and
> the 'find' should return nothing. But it creates a new one and the test
> is a success. I do not see any code for creating new record or save. So
> why is it creating a new record?
> I do not understand assert_equal behavior , can someone please explain?
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to