Sha256: 6fc080787cf23c542485aac9d2f4b446d97c999501f716f8c3c372cac1188919

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe Clearance::PasswordStrategies::BCrypt do
  subject do
    fake_model_with_password_strategy(Clearance::PasswordStrategies::BCrypt)
  end

  describe '#password=' do
    let(:password) { 'password' }
    let(:encrypted_password) { stub('encrypted password') }

    before do
      BCrypt::Password.stubs create: encrypted_password
    end

    it 'encrypts the password into encrypted_password' do
      subject.password = password

      subject.encrypted_password.should == encrypted_password
    end

    it 'encrypts with BCrypt using default cost in non test environments' do
      Rails.stubs env: ActiveSupport::StringInquirer.new("production")

      subject.password = password

      BCrypt::Password.should have_received(:create).with(
        password,
        cost: ::BCrypt::Engine::DEFAULT_COST
      )
    end

    it 'encrypts with BCrypt using minimum cost in test environment' do
      subject.password = password

      BCrypt::Password.should have_received(:create).with(
        password,
        cost: ::BCrypt::Engine::MIN_COST
      )
    end
  end

  describe '#authenticated?' do

    before do
      subject.password = password
    end

    context 'given a password' do
      let(:password) { 'password' }

      it 'is authenticated with BCrypt' do
        subject.should be_authenticated(password)
      end
    end

    context 'given no password' do
      let(:password) { nil }

      it 'is not authenticated' do
        subject.should_not be_authenticated(password)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clearance-1.4.3 spec/models/bcrypt_spec.rb
clearance-1.4.2 spec/models/bcrypt_spec.rb
clearance-1.4.1 spec/models/bcrypt_spec.rb