Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. require 'rubygems'
  2. require 'dm-core'
  3. require 'dm-types'
  4.  
  5. DataMapper.setup(:default, 'sqlite3::memory:')
  6.  
  7. class Test
  8. include DataMapper::Resource
  9.  
  10. property :id, Serial
  11. property :password, BCryptHash
  12. end
  13.  
  14. Test.auto_migrate!
  15.  
  16. # Create new object
  17. @t = Test.new(:password => 'hi')
  18. @t.save
  19.  
  20. # Reload the object
  21. @t = nil
  22. @t = Test.first
  23.  
  24. # Capture and test values
  25. v1 = @t.password.to_s #For the raw hash value
  26. @t.save
  27. @t = Test.first
  28. v2 = @t.password.to_s #For the new hash values
  29. v1 == v2
  30. @t.password == 'hi'
  31. @t.password == v1
  32. ## Why isn't it equal if I haven't changed the password
Add Comment
Please, Sign In to add comment