Validation inheritance: do deeper dup so that child classes don't add to the parent's validations
This commit is contained in:
parent
e466b20df9
commit
49d19e2a29
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue