Note that there are some explanatory texts on larger screens.

plurals
  1. POSpock test cases doesn't make a relationship of domain classes in Grails?
    primarykey
    data
    text
    <p>I have a Spock test case, in which the <code>setup</code> block looks like this :</p> <pre><code>setup: "set the required objects" def company = new Company(shortName:"infyyy",fullName:"infoysys", region:"tamilnadu" ,email:"a@ac.com" ,telphone:34343433,fax:34343433).save(failOnError:true) def project = new Project(name:"testing") def userInstance = new User(username:username,password:password, company:company,project:project,pt:["dummy"]).save(failOnError:true) def tasksInstance = new Tasks(title:"testingwork",startDate:(new Date()-4),endDate:(new Date().clearTime()-6),description:"blah blah",project:project,completed:true,user:userInstance).save(failOnError:true) </code></pre> <p>And more over, the <code>Tasks</code> domain class looks like this :</p> <pre><code>class Tasks { static belongsTo = [ user : User, project: Project ] //other code } </code></pre> <p>And <code>User</code> class is like this :</p> <pre><code>class User { static hasMany = [ holidays : Holiday, tasks : Tasks, pt:String, project: Project ] //other code } </code></pre> <p>But when I run my test and my test fails(not with an error message, but it fails in the <code>then</code> block of my Spock test) and I find a error in it. My setup doesn't create any relationship between <code>User</code> and <code>Tasks</code>, which makes my test to fail. </p> <p>The controller code, which I'm trying to test is :</p> <pre><code>def todaysTasks() { def user = User.get(springSecurityService.principal.id) def choice = params.managersProject params.max = Math.min(params.max ? params.int('max') : 10,100) def search = Tasks.createCriteria().list(max: params.max as Integer, offset: params.offset as Integer, order: params.order as String, sort : params.sort) { and { project { like('name',"${choice}") } eq('endDate', new Date().clearTime()) } } println "todays task selected project is " + search [tasksInstanceList : search, tasksInstanceTotal: search.getTotalCount() ] } </code></pre> <p>The <code>println</code> in the above test prints <code>0</code>. Why does this happen even though I'm making the <code>endDate</code> in my test less than today's date? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload