Skip to content
Commits on Jul 16, 2014
  1. @jeffbrown

    GRAILS-11585 - improve allowedMethods for command object actions

    There are 2 parts to this.
    
    When a command object is a domain object and an error occurs retrieving the instance from the data store, instead of throwing that exception the framework should catch the exception, add an error to the controller and invoke the action with a null value for the command object.
    
    When a controller action accepts a command object argument the compiler creates a no-arg version of the method which creates an instance of the command object, initializes it and passes it as an argument to the method which accepts the command object.  The allowedMethods handling code was being added to the method which accepts the argument.  This means that the allowedMethods check is happening after the command object is initialized.  This commit changes that so the allowedMethods check is added to the no-arg method and is done before the command object is initialialized.  The allowedMethods checking code is still in the method which accepts the argument as well, which allows unit tests which explicitly pass a command object argument to still take advantage of allowedMethods checks.  The code which imposes the allowedMethods check sets a request attribute indicating that the work has been done so when the no-arg method invokes the method which accepts the argument the check is actually only done once.
    
    With this change, the following unit tests will all pass.
    
    A controller which accepts a domain class command object:
    
        // grails-app/controllers/grails11585/RegisterController.groovy
        package grails11585
    
        class RegisterController {
    
            static allowedMethods = [register: 'POST']
    
            // Person is a domain class
            def register(Person p) {
                if(p) {
                    render "Name: ${p.name}"
                } else {
                    render 'p is null'
                }
            }
        }
    
    A unit test:
    
        // test/unit/grails11585/RegisterControllerSpec.groovy
        package grails11585
    
        import grails.test.mixin.TestFor
        import spock.lang.Specification
        import grails.test.mixin.hibernate.HibernateTestMixin
        import grails.test.mixin.gorm.Domain
    
        @TestFor(RegisterController)
        @Domain(Person)
        @TestMixin(HibernateTestMixin)
        class RegisterControllerSpec extends Specification {
    
            void "test register with valid request method"() {
                when: 'the id is of the wrong type and the request method is valid'
                params.id = 'bogus'
                params.name = 'Zack'
                request.method = 'POST'
                controller.register()
    
                then: 'the response code is 200'
                response.status == 200
    
                and: 'the command object is null'
                response.contentAsString == 'p is null'
    
                and: 'an error is added to the controller'
                controller.hasErrors()
                controller.errors.errorCount == 1
                controller.errors.allErrors[0].code == 'grails11585.RegisterController.commandObject.p.error'
                controller.errors.allErrors[0].defaultMessage == 'Provided id of the wrong type for class grails11585.Person. Expected: class java.lang.Long, got class java.lang.String; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class grails11585.Person. Expected: class java.lang.Long, got class java.lang.String'
            }
    
            void "test register with invalid request method"() {
                when: 'the id is of the wrong type and the request method is invalid'
                params.id = 'bogus'
                params.name = 'Zack'
                request.method = 'GET'
                controller.register()
    
                then: 'the response code is 405'
                response.status == 405
            }
    
            void "test register with explicit command object argument and a valid request method"() {
                when: 'request method is valid'
                request.method = 'POST'
                controller.register(new Person(name: 'Zack'))
    
                then: 'the response code is 200'
                response.status == 200
    
                and: 'the response content is correct'
                response.contentAsString == 'Name: Zack'
            }
    
            void "test register with explicit command object argument and invalid request method"() {
                when: 'request method is invalid'
                request.method = 'GET'
                controller.register(new Person(name: 'Zack'))
    
                then: 'the response code is 405'
                response.status == 405
            }
        }
    
    Note that this unit test is using @HibernateTestMixin because the default in memory GORM implementation does not throw an exception for type mismatch of the id.
    jeffbrown committed Jul 16, 2014
  2. @jeffbrown
Commits on Jul 15, 2014
  1. @jeffbrown

    temporarily comment out checkDuplicateDependencies code

    This is incompatible with Gradle 2.0
    jeffbrown committed Jul 15, 2014
  2. @jeffbrown
  3. @jeffbrown

    Use Gradle 2.0

    jeffbrown committed Jul 15, 2014
  4. @lhotari

    GRAILS-11534 GRAILS-11538 startGrails.bat doesn't set file.encoding t…

    …o UTF-8 which breaks GSP compilation on Windows
    lhotari committed Jul 15, 2014
  5. @lhotari

    Merge branch '2.3.x' into 2.4.x

    Conflicts:
    	grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/FormTagLibTests.groovy
    lhotari committed Jul 15, 2014
  6. @lhotari
  7. @lhotari

    GRAILS-11579 fix test, publish resetGrailsApplication event explicitl…

    …y since that is intended behaviour in this test
    lhotari committed Jul 15, 2014
  8. @lhotari

    Merge branch '2.3.x' into 2.4.x

    Conflicts:
    	grails-plugin-gsp/src/ast/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllerTagLibraryApi.java
    lhotari committed Jul 15, 2014
  9. @lhotari
  10. @lhotari
  11. @lhotari

    use LinkedHashSet in place of List for loadedClasses in DefaultGrails…

    …Application to prevent duplicates in tests
    lhotari committed Jul 15, 2014
  12. @lhotari
Commits on Jul 14, 2014
  1. @lhotari
Commits on Jul 11, 2014
  1. @bobbywarner
  2. @lhotari
  3. @lhotari

    Merge branch '2.3.x' into 2.4.x

    Conflicts:
    	grails-plugin-testing/src/main/groovy/grails/test/mixin/web/ControllerUnitTestMixin.groovy
    lhotari committed Jul 11, 2014
  4. @lhotari
  5. @lhotari

    use aspectj version 1.8.1

    - spring-aop 4.0.6.RELEASE uses 1.8.1 version
    lhotari committed Jul 11, 2014
Commits on Jul 10, 2014
  1. @jeffbrown
  2. @jeffbrown

    GRAILS-11571 - allow addTo* and removeFrom* methods to work with Grai…

    …lsTypeChecked and GrailsCompileStatic
    jeffbrown committed Jul 10, 2014
  3. @bobbywarner
  4. @lhotari

    update to Groovy 2.3.4

    lhotari committed Jul 10, 2014
  5. @lhotari

    use Spring 4.0.6.RELEASE

    lhotari committed Jul 10, 2014
Commits on Jul 9, 2014
  1. @graemerocher

    Merge pull request #513 from candrews/patch-11

    Fix Java 7 WatchService implementation of DirectoryWatcher
    graemerocher committed Jul 9, 2014
Commits on Jul 8, 2014
  1. @candrews

    Revert "disable the Java 7 WatchService implementation for now, since…

    … it simply doesn't work in testing"
    
    Since the problem with the Java 7 WatchService implementation has been fixed, enable it.
    
    This reverts commit b8c4140.
    candrews committed Jul 8, 2014
  2. @candrews

    Account for WatchKey reuse

    The same WatchKey can be reused in a WatchService. When that happens, add on to (instead of replace) the file extensions associated with that WatchKey.
    candrews committed Jul 8, 2014
Commits on Jul 2, 2014
  1. @jeffbrown
Commits on Jul 1, 2014
  1. @jeffbrown
  2. @jeffbrown
  3. @jeffbrown
Commits on Jun 30, 2014
  1. @jeffbrown

    2.4.3.BUILD-SNAPSHOT

    jeffbrown committed Jun 30, 2014
Commits on Jun 28, 2014
  1. @bobbywarner
Commits on Jun 25, 2014
  1. @graemerocher
Something went wrong with that request. Please try again.