implemented some missing dirty functionality for casted_array and casted_hash. improved dirty spec test

This commit is contained in:
Andrew Williams 2011-03-03 23:22:19 +10:30
parent dcf43e3641
commit 2a9305ebd3
8 changed files with 284 additions and 35 deletions

View file

@ -15,36 +15,41 @@ module CouchRest::Model
end
def << obj
couchrest_parent_will_change!
couchrest_parent_will_change! if use_dirty?
super(instantiate_and_cast(obj))
end
def push(obj)
couchrest_parent_will_change!
couchrest_parent_will_change! if use_dirty?
super(instantiate_and_cast(obj))
end
def pop
couchrest_parent_will_change!
couchrest_parent_will_change! if use_dirty? && self.length > 0
super
end
def shift
couchrest_parent_will_change!
couchrest_parent_will_change! if use_dirty? && self.length > 0
super
end
def unshift(obj)
couchrest_parent_will_change!
super(obj)
couchrest_parent_will_change! if use_dirty?
super(instantiate_and_cast(obj))
end
def []= index, obj
value = instantiate_and_cast(obj)
couchrest_parent_will_change! if value != self[index]
couchrest_parent_will_change! if use_dirty? && value != self[index]
super(index, value)
end
def clear
couchrest_parent_will_change! if use_dirty? && self.length > 0
super
end
protected
def instantiate_and_cast(obj)