Validation inheritance: do deeper dup so that child classes don't add to the parent's validations

This commit is contained in:
Geoff Buesing 2009-03-25 00:18:28 -05:00 committed by Matt Aimonetti
parent e466b20df9
commit 49d19e2a29
2 changed files with 9 additions and 1 deletions

View file

@ -63,7 +63,9 @@ module CouchRest
# share the validations with subclasses
def self.inherited(subklass)
subklass.instance_variable_set(:@validations, self.validators.dup)
self.validators.contexts.each do |k, v|
subklass.validators.contexts[k] = v.dup
end
end
EOS

View file

@ -42,6 +42,12 @@ describe "Subclassing an ExtendedDocument" do
validated_fields.should include(:job_title)
end
it "should not add to the parent's validations" do
validated_fields = Card.validators.contexts[:default].map{|v| v.field_name}
validated_fields.should_not include(:extension_code)
validated_fields.should_not include(:job_title)
end
it "should inherit default property values" do
@card.bg_color.should == '#ccc'
end