Fix for validates :timeliness form to add attributes to plugin set

This commit is contained in:
Adam Meehan
2012-08-23 18:38:33 +10:00
parent 4fe22458d3
commit 02fbdc6028
5 changed files with 115 additions and 53 deletions

View File

@@ -15,12 +15,7 @@ module ActiveModel
end
def timeliness_validation_for(attr_names, type)
options = _merge_attributes(attr_names).merge(:type => type)
if respond_to?(:timeliness_validated_attributes)
self.timeliness_validated_attributes ||= []
self.timeliness_validated_attributes += (attr_names - self.timeliness_validated_attributes)
end
validates_with TimelinessValidator, options
validates_with TimelinessValidator, _merge_attributes(attr_names).merge(:type => type)
end
end

View File

@@ -21,7 +21,7 @@ module ValidatesTimeliness
def timeliness_attribute_type(attr_name)
{
Date => :date,
Time => :datetime,
Time => :time,
DateTime => :datetime
}[fields[attr_name.to_s].type] || :datetime
end

View File

@@ -39,6 +39,13 @@ module ValidatesTimeliness
super
end
def setup(model)
if model.respond_to?(:timeliness_validated_attributes)
model.timeliness_validated_attributes ||= []
model.timeliness_validated_attributes |= @attributes
end
end
def validate_each(record, attr_name, value)
raw_value = attribute_raw_value(record, attr_name) || value
return if (@allow_nil && raw_value.nil?) || (@allow_blank && raw_value.blank?)