私はちょうどレールを使い始めました。M. Hartlの "Ruby on Railsチュートリアル"に従うことにしました。良いイントロのようだ。パスワード:Ruby on Railsチュートリアル:M.Hartl
私はナットを駆動している失敗したテストに入っています。 私は「has_password」メソッドの仕事上の私は条件を変更しようとしている2.7.0
RSpecの、そしてテストで、レール3.1.1を実行しています。
失敗テスト:
1) User password encryption authenticate method should return the user on email/password match Failure/Error: matching_user.should == @user expected: # got: nil (using ==) # ./spec/models/user_spec.rb:149:in `block (4 levels) in '
RSpecのテスト:Userモデルで
describe User do
before(:each) do
@attr = {:name => 'testing',
:email =>'[email protected]',
:password => "testtest",
:password_confirmation => "testtest"}
end
...
describe "password encryption" do
before(:each) do
@user = User.create!(@attr)
end
...
describe "authenticate method" do
it "should exist" do
User.should respond_to(:authenticate)
end
it "should return nil on email/password mismatch" do
User.authenticate(@attr[:email], "wrongpass").should be_nil
end
it "should return nil for an email address with no user" do
User.authenticate("[email protected]", @attr[:password]).should be_nil
end
it "should return the user on email/password match" do
matching_user = User.authenticate(@attr[:email], @attr[:password])
matching_user.should == @user
end
end
:
...
def has_password?(submitted_password)
encrypt_password == encrypt(submitted_password)
end
def self.authenticate(email, submitted_password)
user = find_by_email(email) #self.where("email = ?", email)
return nil if user.nil?
return user if user.has_password?(submitted_password)
end
private
def encrypt_password
self.salt = make_salt if new_record?
self.encrypted_password = encrypt(password)
end
は、私がここで間違ってやっているかを把握することはできません。あなたの失敗の仕様で
この書籍には、明らかにフォーラムがあります。これは役に立ちました: http://getsatisfaction.com/railstutorial – Slamice