[問題] 想問ROR一個測的問題?
(ctrl + y 刪去不必要的行列)
環境:
Ruby 1.8.6 Rails 2.1.0
--------------------------------------
http://www.aidanf.net/rails_user_authentication_tutorial
在這個網頁上的教學..
我不懂在class UserTest類別中的類變數@bob裡好像是一個新建的變數,
哪為什麼在測試的時候@bob這個變數已經存在著一個值
來跟User.authenticate("bob", "test")回傳的值作比較是否相等呢?
可能我有點誤會了程式的意思?
--------------------------------------
(User model)
class User < ActiveRecord::Base
...
def self.authenticate(login, pass)
u=find(:first, :conditions=>["login = ?", login])
return nil if u.nil?
return u if User.encrypt(pass, u.salt)==u.hashed_password
nil
end
...
end
------------------------------------------
(Unit Test)
class UserTest < Test::Unit::TestCase
self.use_instantiated_fixtures = true
fixtures :users
def test_auth
#check that we can login we a valid user
assert_equal @bob, User.authenticate("bob", "test")
#wrong username
assert_nil User.authenticate("nonbob", "test")
#wrong password
assert_nil User.authenticate("bob", "wrongpass")
#wrong login and pass
assert_nil User.authenticate("nonbob", "wrongpass")
end
...........
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.138.249
→
09/12 21:22, , 1F
09/12 21:22, 1F
推
09/12 21:54, , 2F
09/12 21:54, 2F
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章