Where queries in integration tests not filtering results
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Task List
- [x] Steps to reproduce provided
- [X] Example that reproduces the problem uploaded to Github
- [X] 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
}
Contributor guide
Assessment
This issue has not been assessed yet.