Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hibernate4] Support for array citext (case insensitive strings) #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some tests for Citext. WIP: NOT FINISHED YET!
ilopmar committed Aug 18, 2014
commit b707fc31374e8fd3b786a0effb0c167edd451935
16 changes: 16 additions & 0 deletions grails-app/domain/test/array/TestCitext.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.array

import net.kaleidos.hibernate.usertype.ArrayType

class TestCitext {

String[] citextArray

static mapping = {
citextArray type: ArrayType, params: [type: String, caseInsensitive: true]
}

static constraints = {
citextArray nullable:true
}
}
2 changes: 2 additions & 0 deletions grails-app/domain/test/criteria/array/Like.groovy
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class Like {
Juice[] favoriteJuices = []
Double[] favoriteDoubleNumbers = []
Float[] favoriteFloatNumbers = []
String[] favoriteMoviesCI = []

static enum Juice {
ORANGE(0),
@@ -37,5 +38,6 @@ class Like {
favoriteJuices type:ArrayType, params: [type: Juice]
favoriteFloatNumbers type:ArrayType, params: [type: Float]
favoriteDoubleNumbers type:ArrayType, params: [type: Double]
favoriteMoviesCI type:ArrayType, params: [type: String, caseInsensitive: true]
}
}
Original file line number Diff line number Diff line change
@@ -186,6 +186,35 @@ class PgContainsCriteriaTestServiceIntegrationSpec extends Specification {
[] | 4
}

@Unroll
void 'search #movie in an array of case insensitive strings'() {
setup:
new Like(favoriteMoviesCI: ["The Matrix", "The Lord of the Rings"]).save()
new Like(favoriteMoviesCI: ["Spiderman", "Blade Runner", "Starwars"]).save()
new Like(favoriteMoviesCI: ["Romeo & Juliet", "Casablanca", "Starwars"]).save()
new Like(favoriteMoviesCI: ["Romeo & Juliet", "Blade Runner", "The Lord of the Rings"]).save()

when:
def result = pgArrayTestSearchService.search('favoriteMoviesCI', 'pgArrayContains', movie)

then:
result.size() == resultSize

where:
movie | resultSize
"THE MATRIX" | 1
"the LORD of the RINGs" | 2
"Blade RUNNER" | 2
"STARwars" | 2
"The USUAL Suspects" | 0
["StARWars", "RoMEo & JuLIet"] | 1
["The LORD of THE Rings"] | 2
[] | 4
["Starwars", "ROMEO & Juliet"] as String[] | 1
["The Lord of THE Rings"] as String[] | 2
[] as String[] | 4
}

void 'search in an array of strings with join with another domain class'() {
setup:
def user1 = new User(name: 'John', like: new Like(favoriteMovies: ["The Matrix", "The Lord of the Rings"])).save()
@@ -291,4 +320,15 @@ class PgContainsCriteriaTestServiceIntegrationSpec extends Specification {
where:
juice << [["Test"], [Like.Juice.ORANGE, "Test"], [1L], [Like.Juice.APPLE, 1L]]
}

void 'search an invalid list inside the array of case insensitive string'() {
when:
pgArrayTestSearchService.search('favoriteMoviesCI', 'pgArrayContains', movie)

then:
thrown HibernateException

where:
movie << [[1], ["Test", 1], [1L], ["Test", 1L]]
}
}
Original file line number Diff line number Diff line change
@@ -101,4 +101,20 @@ class PostgresqlArraysDomainIntegrationSpec extends Specification {
where:
days << [null, [], [TestEnum.Day.MONDAY], [TestEnum.Day.SUNDAY, TestEnum.Day.SATURDAY], [TestEnum.Day.WEDNESDAY, TestEnum.Day.THURSDAY, TestEnum.Day.TUESDAY]]
}

@Unroll
void 'save a domain class with an citext array value #citext'() {
setup:
def testCitext = new TestCitext(citextArray: citext)

when:
testCitext.save(flush: true)

then:
testCitext.hasErrors() == false
testCitext.citextArray?.length == citext?.size()

where:
citext << [null, [], ["string 1"], ["string 1", "string 2"], ["string 1", "string 2", "string 3"]]
}
}