Skip to content

Where queries in integration tests not filtering results #11202

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

Open
3 tasks done
tircnf opened this issue Dec 7, 2018 · 3 comments
Open
3 tasks done

Where queries in integration tests not filtering results #11202

tircnf opened this issue Dec 7, 2018 · 3 comments
Assignees

Comments

@tircnf
Copy link

tircnf commented Dec 7, 2018

Task List

  • Steps to reproduce provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Using grails 3.3.8, create a simple domain class. ('Thing' with a single property, name)
  2. Create an integration or unit test that creates two things... "Thing 1" and "Thing 2".
  3. Then search for those things with a where query.
    expect: Thing.where { name == "thing 1" }.list().size() == 1

Expected Behaviour

The test should run a query similar to: "select ... from thing where this_.name=?"
and pass.

Actual Behaviour

The query runs a query similar to "select ... from thing", returns both things, and the test fails.

Environment Information

  • Operating System: Windows
  • **Grails Version: 3.3.8
  • **JDK Version: 1.8
  • Container Version (If Applicable): running tests with gradle test.

Example Application

git@github.com:tircnf/grailsWhereIntegrationTest.git

More information

The same behavior is found in both unit and integration tests.

I wrote some tests that show some weird behavior. For instance,
if you push the where query into a closure, it works.

In the below test, the first expect line will pass, which runs the Where clause in a closure.
The 2nd expect line will fail, which runs the where query directly.

void "test where -- fails, and the sql doesn't filter by name"() {

    given: "two things"
    new Thing(name: "thing 1").save(flush: true, failOnError: true)
    new Thing(name: "thing 2").save(flush: true, failOnError: true)
 
    def queryClosure = { -> Thing.where { name == "thing 1" } }

    expect:
    queryClosure.call().list().size() == 1  // works
    Thing.where { name == "thing 1" }.list().size() == 1   // fails
}
@tircnf
Copy link
Author

tircnf commented Dec 8, 2018

This has been around for a while. The same thing happens with grails 2.3.11

@tircnf
Copy link
Author

tircnf commented Dec 8, 2018

This appears to be an issue with the spock testing framework.

It just doesn't like it if you have a test comparison and a where query.

expect:
def result=Thing.where { name == "thing 1" }.list().size()
result==1  // works.
Thing.where { eq 'name', 'thing 1' }.list().size() == 1   // works
Thing.where { name == "thing 1" }.list().size() == 1   // fails

I'm going out on a limb and say it has something to do with the code that generates the diff view when comparisons fail.

Hibernate: select this_.id as id1_0_0_, this_.version as version2_0_0_, this_.name as name3_0_0_ from thing this_

Condition not satisfied:

Thing.where { name == "thing 1" }.list().size()==1
      |                           |      |     |
      |                           |      2     false
      |                           [wheretest.Thing : 7, wheretest.Thing : 8]
      grails.gorm.DetachedCriteria@4db3b321

whatever magic is used to process that closure doesn't play well with testing.

@zyro23
Copy link
Contributor

zyro23 commented Dec 11, 2018

@niravassar niravassar self-assigned this Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants