Skip to content
Browse files

fix for GRAILS-9696 "Some integration testing that involves GormStati…

…cApi calls is broken"
  • Loading branch information...
1 parent 5a7c092 commit 7c0a59ff0f304ec0507e48afc190ced60d5c0650 @graemerocher graemerocher committed Feb 5, 2013
View
4 ...ls-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/UpdateWithProxyPresentSpec.groovy
@@ -87,6 +87,10 @@ class Person implements Serializable, Comparable<Person> {
// pets.age > 9
// }
+ static Person getByFirstNameAndLastNameAndAge(String firstName, String lastName, int age) {
+ find( new Person(firstName: firstName, lastName: lastName, age: age) )
+ }
+
static mapping = {
firstName index:true
lastName index:true
View
12 grails-datastore-gorm-test/src/test/groovy/grails/gorm/tests/WhereMethodSpec.groovy
@@ -81,6 +81,18 @@ class Project {
Person.where { lastName == "Simpson" }.list()
}
+ @Issue('GRAILS-9696')
+ def "Test that a call to a static find method from within the class resolves correctly"() {
+ given:"Some people"
+ createPeople()
+
+ when:"A method is called that calls the find method from within the class"
+ def bart = Person.getByFirstNameAndLastNameAndAge("Bart", "Simpson", 9)
+
+ then:"The data returned is correct"
+ bart != null
+ bart.firstName == "Bart"
+ }
@Issue('GRAILS-8256')
def "Test query with 3 level deep domain association"() {
given:"create people and faces"
View
21 ...rc/main/groovy/org/grails/datastore/gorm/query/transform/DetachedCriteriaTransformer.java
@@ -413,7 +413,26 @@ private boolean isCandidateWhereMethod(String methodName, Expression arguments)
}
private boolean isCandidateMethod(String methodName, Expression arguments, Set<String> candidateMethods) {
- return (candidateMethods.contains(methodName)) && (arguments instanceof ArgumentListExpression);
+ if(candidateMethods.contains(methodName)) {
+ if(arguments instanceof ArgumentListExpression) {
+ ArgumentListExpression ale = (ArgumentListExpression) arguments;
+ List<Expression> expressions = ale.getExpressions();
+ if(expressions.size()>0) {
+ Expression expression = expressions.get(expressions.size()-1);
+ if(expression instanceof ClosureExpression) {
+ return true;
+ }
+ else if(expression instanceof VariableExpression) {
+ VariableExpression ve = (VariableExpression) expression;
+ if(detachedCriteriaVariables.containsKey(ve.getName()) || DETACHED_CRITERIA_CLASS_NODE.getName().equals(ve.getType().getName())) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ return false;
}
@Override

0 comments on commit 7c0a59f

Please sign in to comment.
Something went wrong with that request. Please try again.