Skip to content

Commit

Permalink
Amend :length validation inference to work on any derivation of Text …
Browse files Browse the repository at this point in the history
…or String.

Previously, inferred validation for :length only worked on Text or String
property classes only.  But if one of these types is subclassed, the common
expectation is more likely to be that their (auto) validations are inherited as
well as their behaviours.
  • Loading branch information
jpr5 committed Oct 2, 2010
1 parent 3e1edea commit ea517f0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dm-validations/auto_validate.rb
Expand Up @@ -130,7 +130,7 @@ def infer_presence_validation_for(property, options)
end

def infer_length_validation_for(property, options)
return unless [ DataMapper::Property::String, DataMapper::Property::Text ].include?(property.class)
return unless [ DataMapper::Property::String, DataMapper::Property::Text ].any? { |klass| property.kind_of?(klass) }

case length = property.options.fetch(:length, DataMapper::Property::String::DEFAULT_LENGTH)
when Range then options[:within] = length
Expand Down

0 comments on commit ea517f0

Please sign in to comment.