Only mark a field as changed if the value has changed (#258)

This commit is contained in:
Ross Lawley 2013-04-15 07:52:04 +00:00
parent 8f05896bc9
commit 97a98f0045

View File

@ -185,8 +185,9 @@ class FieldTest(unittest.TestCase):
# Migrate the data # Migrate the data
for g in Group.objects(): for g in Group.objects():
g.author = g.author # Explicitly mark as changed so resets
g.members = g.members g._mark_as_changed('author')
g._mark_as_changed('members')
g.save() g.save()
group = Group.objects.first() group = Group.objects.first()
@ -997,7 +998,7 @@ class FieldTest(unittest.TestCase):
msg = Message.objects.get(id=1) msg = Message.objects.get(id=1)
self.assertEqual(0, msg.comments[0].id) self.assertEqual(0, msg.comments[0].id)
self.assertEqual(1, msg.comments[1].id) self.assertEqual(1, msg.comments[1].id)
def test_tuples_as_tuples(self): def test_tuples_as_tuples(self):
""" """
Ensure that tuples remain tuples when they are Ensure that tuples remain tuples when they are
@ -1007,16 +1008,16 @@ class FieldTest(unittest.TestCase):
class EnumField(BaseField): class EnumField(BaseField):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(EnumField,self).__init__(**kwargs) super(EnumField,self).__init__(**kwargs)
def to_mongo(self, value): def to_mongo(self, value):
return value return value
def to_python(self, value): def to_python(self, value):
return tuple(value) return tuple(value)
class TestDoc(Document): class TestDoc(Document):
items = ListField(EnumField()) items = ListField(EnumField())
TestDoc.drop_collection() TestDoc.drop_collection()
tuples = [(100,'Testing')] tuples = [(100,'Testing')]
doc = TestDoc() doc = TestDoc()