Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec failing when attempting to find user in DB
    primarykey
    data
    text
    <p>I can't figure out what I'm doing wrong in my model spec (user_spec.rb). I'm attempting to check that the authentication method works with a valid password, but something is going wrong in the <code>User.find_by</code> part of the spec I think since it returns <code>nil</code>. I've checked that it responds to :authenticate, :password, and :password_confirmation, which passes (I'll omit that in the code below for the sake of readability).</p> <p>Here's the failure I'm getting when running the spec:</p> <pre><code>Failures: 1) User return value of authenticate method with valid password should eq #&lt;User id: 136, fullname: "Sherwood Hickle", email: "jewell.brekke@stokes.net", created_at: "2013-11-06 23:04:35", updated_at: "2013-11-06 23:04:35", password_digest: "$2a$04$O5V2X9sZrl/u2T9W25c3Pu/PU6XaIvtZSIB39Efkid6a..."&gt; Failure/Error: it { should eq found_user.authenticate(user.password) } expected: #&lt;User id: 136, fullname: "Sherwood Hickle", email: "jewell.brekke@stokes.net", created_at: "2013-11-06 23:04:35", updated_at: "2013-11-06 23:04:35", password_digest: "$2a$04$O5V2X9sZrl/u2T9W25c3Pu/PU6XaIvtZSIB39Efkid6a..."&gt; got: #&lt;User id: nil, fullname: nil, email: nil, created_at: nil, updated_at: nil, password_digest: nil&gt; (compared using ==) Diff: @@ -1,2 +1,2 @@ -#&lt;User id: 136, fullname: "Sherwood Hickle", email: "jewell.brekke@stokes.net", created_at: "2013-11-06 23:04:35", updated_at: "2013-11-06 23:04:35", password_digest: "$2a$04$O5V2X9sZrl/u2T9W25c3Pu/PU6XaIvtZSIB39Efkid6a..."&gt; +#&lt;User id: nil, fullname: nil, email: nil, created_at: nil, updated_at: nil, password_digest: nil&gt; # ./spec/models/user_spec.rb:41:in `block (4 levels) in &lt;top (required)&gt;' </code></pre> <p>user_spec.rb:</p> <pre><code>require 'spec_helper' describe User do describe "return value of authenticate method" do user = FactoryGirl.create(:user) let(:found_user) { User.find_by(email: user.email) } describe "with valid password" do it { should eq found_user.authenticate(user.password) } end describe "with 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 I'm also using FactoryGirl to generate the username and email addresses but I don't think it has anything to do with the failure:</p> <pre><code>require 'faker' FactoryGirl.define do factory :user do |u| u.fullname { Faker::Name.name } u.email { Faker::Internet.email } u.password { "foobar" } u.password_confirmation { "foobar" } end end </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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