            
class TestController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ testList: Test.list( params ) ]
    }

    def show = {
        def test = Test.get( params.id )

        if(!test) {
            flash.message = "Test not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ test : test ] }
    }

    def delete = {
        def test = Test.get( params.id )
        if(test) {
            test.delete()
            flash.message = "Test ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Test not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def test = Test.get( params.id )

        if(!test) {
            flash.message = "Test not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ test : test ]
        }
    }

    def update = {
        def test = Test.get( params.id )
        if(test) {
            test.properties = params
            if(!test.hasErrors() && test.save()) {
                flash.message = "Test ${params.id} updated"
                redirect(action:show,id:test.id)
            }
            else {
                render(view:'edit',model:[test:test])
            }
        }
        else {
            flash.message = "Test not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def test = new Test()
        test.properties = params
        return ['test':test]
    }

    def save = {
        def test = new Test(params)
        if(!test.hasErrors() && test.save()) {
            flash.message = "Test ${test.id} created"
            redirect(action:show,id:test.id)
        }
        else {
            render(view:'create',model:[test:test])
        }
    }
}