Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:12+00:00 2026-06-01T20:03:12+00:00

I have a Spock test case, in which the setup block looks like this

  • 0

I have a Spock test case, in which the setup block looks like this :

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)

And more over, the Tasks domain class looks like this :

class Tasks {
    static belongsTo = [ user : User, project: Project ]
        //other code
}

And User class is like this :

class User  {
        static hasMany = [ holidays : Holiday, tasks : Tasks, pt:String, project: Project ]
        //other code
}

But when I run my test and my test fails(not with an error message, but it fails in the then block of my Spock test) and I find a error in it. My setup doesn’t create any relationship between User and Tasks, which makes my test to fail.

The controller code, which I’m trying to test is :

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() ]
    }

The println in the above test prints 0. Why does this happen even though I’m making the endDate in my test less than today’s date?
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:03:13+00:00Added an answer on June 1, 2026 at 8:03 pm

    As far as I know, GORM does not auto-populate relationships, by following a belongsTo relationship.

    I always do the following.

    def u=new User(...)
    u.addToTasks(
       title:"testingwork",
       startDate:(new Date()-4),
       endDate:...
    )
    u.save()
    

    Note that I have not created a task object. I have passed the Map of values directly to addToX… this emphasizes that the added object belongs to User and should be instantiated and saved by GORM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have string like this: string = The stock item 28031 (111111: Test product)
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have this function: void receive_message(int sock, char buffer[]) { int test = recv(sock,
I have the following application which get launched as below: Runtime.getRuntime().exec(java -cp /var/dist/Test.jar System.V
I have this source XML: <?xml version=1.0?> <root> <item1> <name>test</name> <price>160</price> <stock>4</stock> <country>Belgium</country> </item1>
i have a program which is .net.when i execute the program am getting this
I have a PHP-driven site that includes an XML stock feed, which is remotely
I have a company name and i want to get the stock symbol of
I have made one project which is showing the inventory of the stock of
I have a data set from a text file, 5000 stock's with 751 data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.