Note that there are some explanatory texts on larger screens.

plurals
  1. POI just can't get my valid password test to pass
    primarykey
    data
    text
    <p>I'm trying to get my valid password test to pass. When I run it it seems that the <code>password_digest</code> hash is different. I don't know what to do to get them to match.</p> <p>I was mostly using the book "Ruby on Rails Tutorial: Learn Rails by Example" by Michael Hartl and it seems that he gets this to pass.</p> <p>Additionally, my application code works just as expected. I can create a user and authenticate them in the console so this is only breaking in tests.</p> <p>I'm fairly new to testing so I may be missing something obvious here.</p> <p>Thanks for your help!</p> <p>I am using bcrypt with <code>has_secure_password</code> and here's part relavent user spec code:</p> <pre><code>describe User do before { @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar") } 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 "return value of authenticate method" do before { @user.save } let(:found_user) { User.find_by(email: @user.email) } describe "with a valid password" do it { should eq found_user.authenticate(@user.password) } end describe "with an invalid password" do let(:user_for_invalid_password) { found_user.authenticate('invalid') } it { should_not eq user_for_invalid_password } specify { expect(user_for_invalid_password).to be_false } end end end </code></pre> <p>And this is my user model</p> <pre><code>class User &lt; ActiveRecord::Base before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i validates :email, presence: true, uniqueness: { case_sensitive: false }, format: { with: VALID_EMAIL_REGEX } has_secure_password validates :password_confirmation, presence: true validates :password, length: { minimum: 6 } end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload