все.У меня следующая проблема: после реализации has_password?в разделе 7.2.3 RSpec отображает следующую ошибку для теста «следует создать новый экземпляр с заданными действительными атрибутами», например
1) Пользователь должен создать новый экземпляр с заданными действительными атрибутами Failure / Error: User.create! (@ attr) ArgumentError: неверное количество аргументов (1 для 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
блок (2 уровня) в '
Закончено за 1,47 секунды 1 пример, 1 сбой <- Выполнение ведомого (1) выполнено! </p>
Я не понимаю,что именно вызывает проблему.Вот мой код user.rb:
require 'digest'
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
email_regex = /\A[\w+\-.]+@[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
Что это может быть?Заранее спасибо!