Skip to content

Commit

Permalink
fix dirty check for empty hstore #96
Browse files Browse the repository at this point in the history
  • Loading branch information
jglapa authored and ilopmar committed May 21, 2017
1 parent f9c2ea2 commit ce59c06
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,41 @@ class PostgresqlHstoreMapDomainIntegrationSpec extends Specification {
[foo: "bar"] | "foo" | "bar"
["foo,bar": "baz,qux"] | "foo,bar" | "baz,qux"
}

@Unroll
void 'save a domain class with a empty map and validate that is not dirty right after retrieval'() {
setup:
def testHstoreMap = new TestHstoreMap(testAttributes: [:])

when: 'I save an instance'
testHstoreMap.save()

and: 'The instance is saved'
assert !testHstoreMap.hasErrors()

and: 'I retrieve it and check for dirty properties'
def retrievedTestHstoreMap = testHstoreMap.get(testHstoreMap.id)

then: 'It shouldn\'t be dirty right after db retrieval'
!retrievedTestHstoreMap.isDirty()
}

@Unroll
void 'save a domain class, modify it and validate that it\'s dirty'() {
setup:
def testHstoreMap = new TestHstoreMap(testAttributes: [:])

when: 'I save an instance'
testHstoreMap.save()

and: 'The instance is saved'
assert !testHstoreMap.hasErrors()

and: 'I retrieve it and modify a property'
def retrievedTestHstoreMap = testHstoreMap.get(testHstoreMap.id)
retrievedTestHstoreMap.testAttributes << [foo: 'bar']

then: 'It shouldn be dirty'
retrievedTestHstoreMap.isDirty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HstoreMapType implements UserType {
}

Object deepCopy(Object value) throws HibernateException {
value ? new HashMap(value as Map) : null
value == null ? null : new HashMap(value as Map)
}

boolean isMutable() {
Expand Down

0 comments on commit ce59c06

Please sign in to comment.