I have a domain
with named query:
class Publication {
String title
String author
static namedQueries = {
publicationsWithBookInTitle {
like 'title', '%Book%'
}
}
@Override
String toString() {
return title
}
}
and in controller
I have
def show() {
Publication publicationInstance = Publication.publicationsWithBookInTitle.get()
println "Get: ${publicationInstance}"
println "List: ${Publication.publicationsWithBookInTitle.list()}"
respond publicationInstance
}
and my unit test
:
void "test show"() {
given:
Publication publication = new Publication(title: 'MyBook', author: 'MB').save(flush: true, failOnError: true)
when:
controller.show()
then:
model.publicationInstance == publication
}
When I run the test it gives me null when using get() method and my test fails. System output is
Get: null
List: [MyBook ]
I search for this but not found any solution of this issue.
Why this is happening and what is the solution or workaround of this issue?
NOTE:- I am currently using grails 2.3.9
. But my project initially created in grails 2.3.5
then upgraded to grails 2.3.9
.