저는 RoH에 관한 Michael Hartl의 튜토리얼을 현재 따르고 있으며, Rspec 테스트에 대해 더 많은 정보를 얻으려고합니다. 인증 방법의 기능 : 그러나 나는 내가 무엇을하는 방법에 관해서는 조금 혼란 스러워요 무슨 일이 일어나고 있는지의 대부분을 수행 할 수 있어요: Rspec의 authenticate 메소드
:it { should respond_to(:authenticate) }
을 그리고 코드의 다음 섹션에 관련이 있는지
describe "return value of authenticate" 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
let과 해당 블록을 사용하여 과제를 이해할 수 있지만 authenticate 메소드가 호출 될 때 무슨 일이 일어나고 있는지 이해하는 데 어려움을 겪고 있습니다. 초기 행에서 인증하는 대상은 무엇입니까? 전자 메일이 있어야하고 특정 정규식과 일치하는지 또는 다른 것인가를 요구하는 user.rb 모델에 대해 인증하고 있습니까? 나는 명확성을 위해 user.rb 코드를 포함 시켰습니다 :
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = 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, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
어떤 도움을 많이 주셨습니다.
정말로 도움이되는 많은 고마워! has_secure_password가 내장 된 기능이라는 것이 내 이해입니다. 이제 정확합니까? 또한 첫 번째 줄에는 올바른 내용이 있습니다. 왜냐하면 코드에서 그것을 언급하기 위해'subject {@user} '를 사용했기 때문에 객체를 진술하지 않았습니다. – Tom
예. Rails 3.1에서 소개 된 것 같습니다. Rails에 항상 훌륭한 것들이 많이 추가되고 있습니다. 실제로 Rails뿐 아니라 인기있는 보석도 정기적으로 업데이트됩니다. – edralph