Sha256: 12118ade6b5eb8e4ac4e4a5ba98ed96a1971f6ddac6ec73fb93ed5745186e910

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'

include DataMapper::Types

begin
  require 'bcrypt'
rescue LoadError
  skip_tests = true
end

describe "DataMapper::Types::BCryptHash" do
  unless skip_tests

    before(:each) do
      @clear_password = "DataMapper R0cks!"
      @crypted_password = BCrypt::Password.create(@clear_password)
    end

    describe ".dump" do
      it "should return a crypted hash as a BCrypt::Password" do
        BCryptHash.dump(@clear_password, :property).should be_an_instance_of(BCrypt::Password)
      end

      it "should return a string that is 60 characters long" do
        BCryptHash.dump(@clear_password, :property).should have(60).characters
      end

      it "should return nil if nil is passed" do
        BCryptHash.dump(nil, :property).should be_nil
      end
    end

    describe ".load" do
      it "should return the password as a BCrypt::Password" do
        BCryptHash.load(@crypted_password, :property).should be_an_instance_of(BCrypt::Password)
      end

      it "should return the password as a password which matches" do
        BCryptHash.load(@crypted_password, :property).should == @clear_password
      end

      it "should return nil if given nil" do
        FilePath.load(nil, :property).should be_nil
      end
    end
  else
    it "requires the bcrypt-ruby gem to test"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dm-types-0.9.5 spec/unit/bcrypt_hash_spec.rb
dm-types-0.9.4 spec/unit/bcrypt_hash_spec.rb
dm-types-0.9.3 spec/unit/bcrypt_hash_spec.rb
dm-types-0.9.6 spec/unit/bcrypt_hash_spec.rb
dm-types-0.9.7 spec/unit/bcrypt_hash_spec.rb