I have this stub of code to add dynamic attributes. I work with mongodb and i want to add the properties dynamically. This is what i tried to do when unit testing.
User.metaClass.dynamicAttributes = [:]
User.metaClass.propertyMissing = { String name ->
delegate.dynamicAttributes[name]
}
User.metaClass.propertyMissing = { String name, value ->
delegate.dynamicAttributes[name] = value
}
But this fails and i am stepping over my patience limit!
User u = new User()
u.ppt = 0
User u2 = new User()
u2.ppt = 1
assert u2.ppt == 1
assert u.ppt == 0 // fails here, println shows that u.ppt is also 1!