Skip to content

dtamm/plastic-criteria

 
 

Repository files navigation

PlasticCriteria

Build Status

From FakePlasticCriteria renamed to just PlasticCriteria.

The project is licensed under the WTFPL. http://sam.zoy.org/wtfpl/COPYING

Installation

For grails 1.3.x

grails install-plugin plastic-criteria

Grails 2.x edit your /grails-app/conf/BuildConfig.groovy

    // (...)
    plugins {
        // (...) another plugins

        // add this line
        test ":plastic-criteria:1.6.1"
    }
    // (...)

Sample usage

package plastic.test

import grails.test.mixin.*

// import mockCriteria() static method
import static plastic.criteria.PlasticCriteria.*

@TestFor(Product)
class ProductTests {

    void testSomething() {
		new Product(name: 'Foo', value: 10).save()
		new Product(name: 'Foo', value: 20).save()
		new Product(name: 'Bar', value: 200).save()
		new Product(name: 'Bar', value: 100).save()

		// replace default criteria mock
		mockCriteria([Product])

		def results = Product.withCriteria{
			projections{
				groupProperty('name') // now you have groupProperty
				sum('value')
			}
		}

		assert [['Foo', 30 ], ['Bar', 300]] == results
    }
}

just

import static plastic.criteria.PlasticCriteria.*;

and

mockCriteria([Product])

Full docs at:

https://github.com/fabiooshiro/plastic-criteria/blob/master/src/groovy/plastic/criteria/CriteriaDocTests.groovy

How to Contribute

Edit online! https://ide.c9.io/fabiooshiro/plastic-criteria

or clone in your machine

write a test in CriteriaDocTests.groovy run ./wgrails test-app if you see "tests passed" make me a pull request ;-)

Committers

Sr. Oshiro, Max Mustang, Danilo Tuler

Special thx

dtamm, frozenspider, srybakov

About

Mock Grails Criteria Unit Test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Groovy 90.0%
  • Batchfile 10.0%