Sha256: 76d5ed429e445024671c21f23d99c44f4acad3755a1f5d9c733853e110ba6646

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 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
    let(:password) { 'password' }

    before do
      subject.password = password
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clearance-1.2.0 spec/models/bcrypt_spec.rb
clearance-1.1.0 spec/models/bcrypt_spec.rb
clearance-1.0.1 spec/models/bcrypt_spec.rb
clearance-1.0.0 spec/models/bcrypt_spec.rb
clearance-1.0.0.rc8 spec/models/bcrypt_spec.rb
clearance-1.0.0.rc7 spec/models/bcrypt_spec.rb
clearance-1.0.0.rc6 spec/models/bcrypt_spec.rb