Skip to content

Instantly share code, notes, and snippets.

View alvarosanchez's full-sized avatar

Álvaro Sánchez-Mariscal alvarosanchez

View GitHub Profile
@alvarosanchez
alvarosanchez / BuildConfig.groovy
Created June 2, 2014 00:00
Dependencies and plugins
dependencies {
runtime 'com.github.groovy-wslite:groovy-wslite:0.8.0'
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.50"
// plugins for the compile step
compile ":scaffolding:2.0.1"
class GameSpec extends Specification {
@Shared
RESTClient restClient = new RESTClient("http://localhost:8080/restful-gr8conf-2014")
def "it returns a list of games in JSON"() {
when:
Response response = restClient.get(path: "/games", accept: ContentType.JSON)
then:
def castleBuilder = new Game(name: 'Castle Builder').save()
def amazingCircus = new Game(name: 'The Amazing Circus').save()
def pokerDrop = new Game(name: 'Poker Drop Riches').save()
def petsPayDay = new Game(name: "Pet's Pay Day").save()
def grandBlackjack = new Game(name: 'Grand Blackjack').save()
def "it creates games"() {
when:
Response response = restClient.post(path: "/games") {
json name:"New game"
}
then:
response.statusCode == 201
response.headers['Location']
}
import com.odobo.gr8conf.Category
import com.odobo.gr8conf.Game
class BootStrap {
def init = { servletContext ->
def slot = new Category(name: 'Slot').save()
def instantWin = new Category(name: 'Instant Win').save()
def card = new Category(name: 'Card').save()
"/categories"(resources:"category")
"/games"(resources: "game") {
"/categories"(resources:"category")
}
def "it returns just the categories of a game when is a nested resource"() {
when:
Response response = restClient.get(path: "/games/5/categories", accept: ContentType.JSON)
println response.json
then:
response.json.size() == 2
}
package com.odobo.gr8conf
import grails.rest.RestfulController
import grails.transaction.Transactional
@Transactional(readOnly = true)
class CategoryController extends RestfulController {
static responseFormats = ['json', 'xml']
package com.odobo.gr8conf
import grails.rest.RestfulController
import grails.transaction.Transactional
@Transactional(readOnly = true)
class CategoryController extends RestfulController {
static responseFormats = ['json', 'xml']
package com.odobo.gr8conf
import spock.lang.Shared
import spock.lang.Specification
import wslite.rest.ContentType
import wslite.rest.RESTClient
import wslite.rest.Response
class CategorySpec extends Specification {