use inheritable hash for valdiated attributes

This commit is contained in:
Adam Meehan 2010-09-17 10:56:13 +10:00
parent 4f8b300261
commit 423d60f885
2 changed files with 11 additions and 3 deletions

View File

@ -5,7 +5,7 @@ module ValidatesTimeliness
included do included do
include ValidationMethods include ValidationMethods
extend ValidationMethods extend ValidationMethods
class_inheritable_accessor :timeliness_validated_attributes class_inheritable_hash :timeliness_validated_attributes
self.timeliness_validated_attributes = {} self.timeliness_validated_attributes = {}
end end
@ -17,7 +17,7 @@ module ValidatesTimeliness
validated[attr_name] = options[:type] validated[attr_name] = options[:type]
validated validated
} }
timeliness_validated_attributes.update(attributes) self.timeliness_validated_attributes = attributes
validates_with Validator, options validates_with Validator, options
end end

View File

@ -21,8 +21,16 @@ describe ValidatesTimeliness::HelperMethods do
describe ".timeliness_validated_attributes" do describe ".timeliness_validated_attributes" do
it 'should return attributes validated with plugin validator' do it 'should return attributes validated with plugin validator' do
Person.timeliness_validated_attributes = {}
Person.validates_date :birth_date Person.validates_date :birth_date
Person.timeliness_validated_attributes.should == {"birth_date" => :date} Person.validates_time :birth_time
Person.validates_datetime :birth_datetime
Person.timeliness_validated_attributes.should == {
"birth_date" => :date,
"birth_time" => :time,
"birth_datetime" => :datetime
}
end end
end end
end end