Permalink
Browse files

introducing Saint Peter

  • Loading branch information...
1 parent 43eba7e commit 41157771c74361d07e449a800b7a7d873a0bffcd @fabiooshiro committed Oct 6, 2013
@@ -1,5 +1,5 @@
class PlasticCriteriaGrailsPlugin {
- def version = "1.2"
+ def version = "1.3"
def grailsVersion = "1.3 > *"
def pluginExcludes = [
'grails-app/domain/**',
@@ -642,4 +642,19 @@ class CriteriaDocTests {
assert ['Autorretrato Com Mulata', 'Paisagem de Brodowski', 'Retirantes'] == rs.name
}
+ // next release 1.3
+ void test_avg_division_undefined(){
+ def artitst = new Artist(name: 'Brilhante').save()
+ new Portrait(artist: artitst, name: 'Soleil levant', value: 1.0).save()
+ new Portrait(artist: artitst, name: 'The Madonna of Port Lligat', value: 2.0).save()
+ new Portrait(artist: artitst, name: "Les Demoiselles d'Avignon", value: 3.0).save()
+ def average = Portrait.createCriteria().get{
+ eq('name', 'not exists')
+ projections{
+ avg('value')
+ }
+ }
+ assert null == average
+ }
+
}
@@ -19,6 +19,8 @@ class PlasticCriteria {
def uniqueResult
+ static _SaintPeter = new SaintPeter()
+
def theImplementations = [
"le":{ _instanceValue <= _criteriaValue },
"lt":{ _instanceValue < _criteriaValue },
@@ -197,7 +199,7 @@ class PlasticCriteria {
}else if(prop.startsWith('rowCount ')){
rsItem.add(vls.size())
}else if(prop.startsWith('avg ')){
- rsItem.add(vls.sum(0.0){it."${prop.substring(4)}"} / vls.size())
+ rsItem.add(vls.size() ? (vls.sum(0.0){it."${prop.substring(4)}"} / vls.size() ) : null)
}else if(prop.startsWith('min ')){
def min
vls.each{ if(min == null || it."${prop.substring(4)}" < min) min = it."${prop.substring(4)}" }
@@ -266,7 +268,9 @@ class PlasticCriteria {
}
_instanceValue = _getProp(obj, cri.prop)
_critOptions = cri.opt
- return theImplementations[cri.criteriaName]()
+ def result = theImplementations[cri.criteriaName]()
+ _SaintPeter.tell(" ${cri.criteriaName}('${_instanceValue}', '${_criteriaValue}') == ${result}")
+ return result
}
def knokinOnHeavensDoor(criList, obj){
@@ -315,9 +319,14 @@ class PlasticCriteria {
def _filteredList(){
def r = []
+ if(_clazz.list().size() == 0) _SaintPeter.tell "Hey the ${_clazz.simpleName}.list() is empty!"
_clazz.list().each{ obj ->
+ _SaintPeter.tell obj
if(knokinOnHeavensDoor(_leCriticalList, obj)){
r.add(obj)
+ _SaintPeter.tell " welcome to heaven"
+ }else{
+ _SaintPeter.tell " sorry"
}
}
_orders.each{
@@ -0,0 +1,16 @@
+package plastic.criteria
+
+class SaintPeter{
+
+ def phrases = []
+
+ def tell(str){
+ println str
+ phrases.add(str.toString())
+ }
+
+ def didYouSay(str){
+ return phrases.contains(str.toString())
+ }
+
+}
@@ -1,14 +1,38 @@
package plastic.criteria
import static plastic.criteria.PlasticCriteria.*
+import groovy.ui.SystemOutputInterceptor
import org.junit.Before
@Mock([Artist, City, Portrait])
class PlasticCriteriaTests extends CriteriaDocTests{
+ def saintPeter
+
@Before
void setUp(){
mockCriteria([Artist, Portrait])
+ saintPeter = PlasticCriteria._SaintPeter
+ }
+
+ // next release 1.3
+ void test_why_not_in_result(){
+ def artitst = new Artist(name: 'Brilhante').save()
+ def soleil = new Portrait(artist: artitst, name: 'Soleil levant', value: 1.0).save()
+
+ def results = Portrait.withCriteria{
+ eq('name', 'not exists')
+ }
+
+ assert saintPeter.didYouSay(" eq('Soleil levant', 'not exists') == false")
+ }
+
+ void test_Saint_Peter_should_say_Hey_the_list_is_empty(){
+ def results = Portrait.withCriteria{
+ eq('name', 'not exists')
+ }
+ assert saintPeter.didYouSay('Hey the Portrait.list() is empty!')
}
+
}

0 comments on commit 4115777

Please sign in to comment.