-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAILS-11044 - fix command object error handling for the legacy sprin…
…g data binder
- Loading branch information
Jeff Scott Brown
committed
Feb 6, 2014
1 parent
0c5dd05
commit 74504da
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...est/groovy/org/codehaus/groovy/grails/web/binding/SpringDataBinderBindingErrorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.codehaus.groovy.grails.web.binding | ||
|
||
import grails.test.mixin.TestMixin | ||
import grails.test.mixin.support.GrailsUnitTestMixin | ||
import grails.util.GrailsWebUtil | ||
import grails.validation.Validateable | ||
|
||
import org.codehaus.groovy.grails.commons.GrailsApplication | ||
import org.codehaus.groovy.grails.support.MockApplicationContext | ||
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes | ||
import org.springframework.web.context.request.RequestContextHolder | ||
|
||
import spock.lang.Issue | ||
import spock.lang.Specification | ||
|
||
|
||
@TestMixin(GrailsUnitTestMixin) | ||
class SpringDataBinderBindingErrorSpec extends Specification { | ||
|
||
@Issue('GRAILS-11044') | ||
void 'Test binding errors when using the Spring binder'() { | ||
given: 'The spring binder is being used' | ||
def appCtx = new MockApplicationContext() | ||
appCtx.registerMockBean(GrailsApplication.APPLICATION_ID, grailsApplication) | ||
appCtx.getServletContext().setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, appCtx) | ||
GrailsWebUtil.bindMockWebRequest(appCtx) | ||
grailsApplication.config.grails.databinding.useSpringBinder=true | ||
grailsApplication.configChanged() | ||
|
||
when: 'a binding error occurs' | ||
RequestContextHolder.getRequestAttributes().currentRequest.setParameter 'number', 'forty two' | ||
def house = new House() | ||
DataBindingUtils.bindObjectToInstance(house, null) | ||
|
||
then: ' the non-domain class object has the expected binding error associated with it' | ||
house.hasErrors() | ||
house.errors.errorCount == 1 | ||
house.errors.getFieldError('number').code == 'typeMismatch' | ||
} | ||
} | ||
|
||
@Validateable | ||
class House { | ||
Integer number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters