Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Monkey patch for datamapper version 0.9.10
- #
- # Allow the validates_present validator
- # to check for blank BCryptHash passwords.
- #
- # require "dm-core"
- # require "dm-validations"
- # require "dm-types"
- # class User
- # include DataMapper::Resource
- # property :password, BCryptHash
- # validates_present :password
- # end
- #
- # user = User.new
- # user.password = nil; user.valid? => false
- # user.password = ""; user.valid? => false
- # user.password = " "; user.valid? => false
- # user.password = "x"; user.valid? => true
- # user.password = " x "; user.valid? => true
- # user.password == " x " => true
- # user.password == "x" => false
- #
- require 'dm-types/bcrypt_hash'
- module DataMapper
- module Types
- class BCryptHash
- class << self
- alias_method :old_non_blank_check_self_typecast, :typecast
- end
- def self.typecast(value, property)
- value = nil if value.respond_to?(:blank?) && value.blank?
- old_non_blank_check_self_typecast(value, property)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment