모두. 나는 다음과 같은 문제가있다 : has_password를 구현 한 후에? 정확하게 문제를 일으키는 것, 예를ArgumentError by Michael Hartl "레일 튜토리얼"의 제 7 장
1) User should create a new instance given valid attributes Failure/Error: User.create!(@attr) ArgumentError: wrong number of arguments (1 for 0) # ./app/models/user.rb:42:in
secure_hash' # ./app/models/user.rb:39:in
make_salt' # ./app/models/user.rb:30:inencrypt_password' # ./spec/models/user_spec.rb:14:in
block (2 levels) in 'Finished in 1.47 seconds 1 example, 1 failure <-- Slave(1) run done!
이해가 안에 대한 테스트 "유효한 속성 주어진 새로운 인스턴스를 생성해야"절 7.2.3에 RSpec에 다음과 같은 오류가 표시됩니다.
require 'digest'
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
# Automatically create the virtual attribute "password_confirmation"
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
before_save :encrypt_password
# Return 'true' if the user's password matches the submitted password
def has_password?(submitted_password)
encrypted_password == encrypt(submitted_password)
end
private
def encrypt_password
self.salt = make_salt if new_record?
self.encrypted_password = encrypt(password)
end
def encrypt(string)
secure_hash("#{salt}--#{string}")
end
def make_salt
secure_hash("#{Time.now.utc}--#{password}")
end
def secure_hash
Digest::SHA2.hexdigest(string)
end
end
가 무엇을 할 수 있습니다 : 여기 내 user.rb 코드? 미리 감사드립니다.