Sha256: 0cffb9cfc618fbea48fd28cf97533894cd7d13fa23cf8e9f8734028c0266b2fd

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require "spec_helper"

describe SimpleAuth, "compatibility mode" do
  before do
    SimpleAuth::Config.model = :customer
    load "./lib/simple_auth/compat.rb"
    require "customer"
  end

  after :all do
    mod = SimpleAuth::ActiveRecord::InstanceMethods
    mod.send :remove_method, :password=
    mod.send :remove_method, :password_confirmation=
    mod.send :remove_method, :authenticate
  end

  it "finds user based on the hashing system" do
    password_salt = SecureRandom.hex
    password_hash = SimpleAuth::Config.crypter.call("test", password_salt)
    password_digest = BCrypt::Password.create(password_hash, cost: BCrypt::Engine::MIN_COST)

    ActiveRecord::Base.connection.execute <<-SQL
    INSERT INTO customers
      (email, login, password_digest, password_salt)
    VALUES
      ('john@example.org', 'johndoe', '#{password_digest}', '#{password_salt}')
    SQL

    expect(Customer.authenticate("johndoe", "test")).to be_a(Customer)
  end

  it "assigns password_digest" do
    customer = Customer.create(password: "test")
    expect(customer.password_digest).not_to be_empty
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_auth-2.0.1 spec/simple_auth/compat_spec.rb