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:
- 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
.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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?