Knock: NameError: undefined local variable or method `has_secure_password' for

Created on 23 Oct 2016  路  3Comments  路  Source: nsarno/knock

class User < ApplicationRecord
  has_secure_password
  has_many :invitations, :class_name => "Invite", :foreign_key => 'recipient_id'
  has_many :sent_invites, :class_name => "Invite", :foreign_key => 'sender_id'
  has_one :group

  validates :password, length: { minimum: 8 }
end

  describe "secure password" do
    it { is_expected.to has_secure_password }
    it { is_expected.to validate_presence_of(:password) }

    it { expect(User.new({ email: "[email protected]", password: nil }).save).to be_falsey }
    it { expect(User.new({ email: "[email protected]", password: "foo" }).save).to be_falsey }
    it { expect(User.new({ email: "[email protected]", password: "af3714ff0ffae" }).save).to be_truthy }
  end

Hi there thank for awesome gem but would you like to check please where i am doing wrong ? here thanks advance

Most helpful comment

@saroar This does not seem related to knock but rather to how you use has_secure_password.

Also, I don't believe this is valid and this might be what the error is referring to.

it { is_expected.to has_secure_password }

I also don't know what ApplicationRecord is, so I can't help you much here. If you're not using Active Record, then ActiveModel::SecurePassword will not be included automatically.

Again, please read the documentation for has_secure_password carefully:

http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password

All 3 comments

Please refer to this section of the README as well as the documentation of has_secure_password (as linked in the README).

Did you add the bcrypt gem to your Gemfile?

Hope this helps.

@saroar This does not seem related to knock but rather to how you use has_secure_password.

Also, I don't believe this is valid and this might be what the error is referring to.

it { is_expected.to has_secure_password }

I also don't know what ApplicationRecord is, so I can't help you much here. If you're not using Active Record, then ActiveModel::SecurePassword will not be included automatically.

Again, please read the documentation for has_secure_password carefully:

http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password

Was this page helpful?
0 / 5 - 0 ratings