Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created November 4, 2009 14:45
Show Gist options
  • Save jwreagor/226089 to your computer and use it in GitHub Desktop.
Save jwreagor/226089 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
require 'dm-types'
require 'bacon'
DataMapper.setup :default, :adapter => :in_memory
class User
include DataMapper::Resource
property :id, Serial
property :password, BCryptHash, :nullable => true
end
describe "Hashing a user's password" do
before do
@user = User.create
@user.password = "password"
end
it "should set a password" do
@user.password.should.not.be.empty
end
it "should hash a password when read" do
@user.password.hash.should.not.be.nil
end
it "should identify the password" do
(@user.password == "password").should.be.true
end
it "should not identify the password" do
(@user.password == "not password").should.not.be.true
end
it "should provide the hash salt" do
@user.password.salt.should.not.be.empty
end
end
# more here, ok? http://bcrypt-ruby.rubyforge.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment