Rspec testing in ruby mine always returns false
I have a class User as follows
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
Now, my rspec test file is as below
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
The databas开发者_开发知识库e table users has the username and password "abcd" and "abcdef" . but the test always fails. the method call always returns false. Please help!!
精彩评论