내 문제는 내가 current_user = user.authrnticate(foobar)
을 시도하고 다시 "레일 C"를 사용하거나 corectly user.rb 파일을 볼되지 믿고 날 리드 NameError: undefined local variable or method 'user' for main:Object
는 "정의되지 않은 지역 변수 또는 메소드"는 has_secure_password
을 얻었다.
[rake db : test : prepare] 및 [rake db : migrate]를 수행하기 전후에 레일스 서버를 다시 시작해 보았습니다.
[rails c]는 user.rb에 정의되지 않은 메소드를 실행합니다.
Rspec이 문제없이 실행 중입니다. user_spec의 모든 테스트가 통과합니다. 그리고 내가이라고 말하면 모든 테스트가 실패합니다.
require 'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "[email protected]",
password: "foobar", password_confirmation: "foobar")
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:authenticate) }
it { should be_valid }
describe "when name is not present" do
before { @user.name = " " }
it { should_not be_valid }
end
describe "when email is not present" do
before { @user.email = " " }
it { should_not be_valid }
end
describe "when name is to long" do
before { @user.name = "a" * 51 }
it { should_not be_valid }
end
describe "when email format is invalid" do
it "should be invalid" do
addresses = %w[[email protected],com user_at_foo.org [email protected]
[email protected]_baz.com [email protected]+baz.com]
addresses.each do |invalid_address|
@user.email = invalid_address
@user.should_not be_valid
end
end
end
describe "when email format is valid" do
it "should be valid" do
addresses = %w[[email protected] [email protected] [email protected] [email protected]]
addresses.each do |valid_address|
@user.email = valid_address
@user.should be_valid
end
end
end
describe "when email address is already taken" do
before do
user_with_same_email = @user.dup
user_with_same_email.email = @user.email.upcase
user_with_same_email.save
end
it { should_not be_valid }
end
describe "when password is not present" do
before { @user.password = @user.password_confirmation = " " }
it { should_not be_valid }
end
describe "when password doesn't match confirmation " do
before { @user.password_confirmation = "mismatch" }
it { should_not be_valid }
end
describe "when password confirmation is nil" do
before { @user.password_confirmation = nil }
it { should_not be_valid }
end
describe "when password is too short" do
before { @user.password = @user.password_confirmation = "a" * 5}
it { should_not be_valid }
end
describe "return value of authenticate method" do
before { @user.save }
let(:found_user) { User.find_by_email(@user.email) }
describe "with valid password" do
it { should == found_user.authenticate(@user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not == user_for_invalid_password }
specify { user_for_invalid_password.should be_false }
end
end
end
내 user.rb 내가 액티브 문서의 읽기 고투를 포함한 솔루션을 철저하게 보았다 내가 난처한 상황에 빠진거야
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = user.email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: {minimum: 6 }
validates :password_confirmation, presence: true
end
and here is the entire project on github
입니다.
도움을 주시면 대단히 감사하겠습니다.
그게 전부입니다! 가변 사용자를 인스턴스화하지 않았습니다. 고마워요, 고마워요! – Kit