Skip to content

Commit

Permalink
Merge pull request #627 from sponiro/unique2
Browse files Browse the repository at this point in the history
More tests for unique constraint names fix #623
  • Loading branch information
graemerocher committed Jan 18, 2016
2 parents 773013b + 6ff982f commit 5827074
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Expand Up @@ -136,7 +136,7 @@ apply from: "gradle/idea.gradle"
subprojects {
configurations {
documentation
}
}
version = "${projectVersion}.${releaseType}"
group = "org.grails"

Expand Down Expand Up @@ -345,6 +345,9 @@ subprojects {
// If there is a corresponding source file in the particular modules
// test source tree. Allows a module to override a test/helper.

if (!details.file.isFile()) {
return false
}
def candidatePath = details.file.absolutePath
def relativePath = toBaseClassRelativePathWithoutExtension(tckClassesDir.absolutePath, candidatePath)

Expand All @@ -369,7 +372,7 @@ subprojects {

configure([groovydoc]) {
groovyClasspath += configurations.documentation
}
}

modifyPom {
delegate.project {
Expand Down
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
package org.grails.orm.hibernate.cfg

import grails.core.DefaultGrailsApplication
import grails.core.GrailsDomainClass
import grails.util.Holders
Expand Down Expand Up @@ -307,6 +308,38 @@ class Widget {
assertFalse descriptionColumn.isUnique()
}

void testGroupUniqueProperty() {
DefaultGrailsDomainConfiguration config = getDomainConfig('''
class CompositeUnique1 {
Long id
Long version
String name
String surname
static constraints = {
name unique:'surname'
}
}
class CompositeUnique2 {
Long id
Long version
String name
String surname
static constraints = {
name unique:'surname'
}
}
''')
Table tableMapping = getTableMapping("composite_unique1", config)
UniqueKey key = tableMapping.getUniqueKey('unique_composite_unique1_name')
assertNotNull(key)

Table tableMapping2 = getTableMapping("composite_unique2", config)
UniqueKey key2 = tableMapping2.getUniqueKey('unique_composite_unique2_name')
assertNotNull(key2)

assertTrue(key.name != key2.name)
}

void testPrecisionProperty() {
DefaultGrailsDomainConfiguration config = getDomainConfig('''
class Widget {
Expand Down Expand Up @@ -1123,7 +1156,7 @@ class CascadeParent {
}
}"""))
grailsDomainBinder.evaluateMapping(cascadeParent)
return (PropertyConfig)cascadeParent.persistentProperties.find { it.name == 'child' }.mapping.mappedForm
return (PropertyConfig) cascadeParent.persistentProperties.find { it.name == 'child' }.mapping.mappedForm
}

private org.hibernate.mapping.Collection findCollection(DefaultGrailsDomainConfiguration config, String role) {
Expand Down Expand Up @@ -1178,13 +1211,13 @@ class CascadeParent {

private void assertColumnNotNullable(String tablename, String columnName, DefaultGrailsDomainConfiguration config) {
Table table = getTableMapping(tablename, config)
assertFalse(table.name + "." + columnName + " is nullable",
assertFalse(table.name + "." + columnName + " is nullable",
table.getColumn(new Column(columnName)).isNullable())
}

private void assertColumnNullable(String tablename, String columnName, DefaultGrailsDomainConfiguration config) {
Table table = getTableMapping(tablename, config)
assertTrue(table.name + "." + columnName + " is not nullable",
assertTrue(table.name + "." + columnName + " is not nullable",
table.getColumn(new Column(columnName)).isNullable())
}

Expand Down
Expand Up @@ -31,6 +31,7 @@ import org.hibernate.mapping.PersistentClass
import org.hibernate.mapping.Property
import org.hibernate.mapping.SimpleValue
import org.hibernate.mapping.Table
import org.hibernate.mapping.UniqueKey
import org.springframework.context.support.GenericApplicationContext

/**
Expand Down Expand Up @@ -313,6 +314,39 @@ class Widget {
assertFalse descriptionColumn.isUnique()
}

void testGroupUniqueProperty() {
DefaultGrailsDomainConfiguration config = getDomainConfig('''
class CompositeUnique1 {
Long id
Long version
String name
String surname
static constraints = {
name unique:'surname'
}
}
class CompositeUnique2 {
Long id
Long version
String name
String surname
static constraints = {
name unique:'surname'
}
}
''')
Table tableMapping = getTableMapping("composite_unique1", config)
UniqueKey key = tableMapping.getUniqueKey('unique_composite_unique1_name')
assertNotNull(key)

Table tableMapping2 = getTableMapping("composite_unique2", config)
UniqueKey key2 = tableMapping2.getUniqueKey('unique_composite_unique2_name')
assertNotNull(key2)

assertTrue(key.name != key2.name)
}


void testPrecisionProperty() {
DefaultGrailsDomainConfiguration config = getDomainConfig('''
class Widget {
Expand Down

0 comments on commit 5827074

Please sign in to comment.