[問題] 想問ROR一個測的問題?

看板Ruby作者 (vincent)時間17年前 (2008/09/12 20:42), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
(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
fixture :users
09/12 21:22, 1F

09/12 21:54, , 2F
建議用 users :bob 來取 fixture, 你看的教學有點老了...
09/12 21:54, 2F
文章代碼(AID): #18ocEf0Q (Ruby)
文章代碼(AID): #18ocEf0Q (Ruby)