我有一个类用户如下
class User < ActiveRecord::Base
has_one :session
has_and_belongs_to_many :posts
has_and_belongs_to_many :replies
attr_accessor :clear_text_password;
validates_presence_of :username
validates_uniqueness_of :username
validates :clear_text_password, :presence => true, :length => {:minimum => 6}
validates_confirmation_of :clear_text_password
validates_presence_of :e_mail
validates_uniqueness_of :e_mail
def User.authenticate(name, password)
if user = find_by_username(name)
if user.password == encrypt_password(password)
user
end
end
end
end
现在,我的rspec测试文件如下
require 'spec_helper'
require 'rspec'
require 'rspec-rails'
require 'user'
describe User do
describe "my first test" do
it "should redirect if user is authenticated" do
user = User.authenticate('abcd','abcdef')
c=false
if user
c=true
end
c.should == true
end
end
end
数据库表用户的用户名和密码为“abcd”和“abcdef”。但测试总是失败。方法调用始终返回false。请帮忙!!