Skip to content

Commit 7218506

Browse files
committed
Fixed defaultAction in controllers to be url converter aware. Removed addViewPrefix that was not url converter aware
1 parent bd491e2 commit 7218506

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

grails-core/src/main/groovy/org/grails/core/DefaultGrailsControllerClass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public void registerUrlConverter(UrlConverter urlConverter) {
169169
actionUriToViewName.put(urlConverter.toUrlElement(actionName), actionName);
170170
actions.put( urlConverter.toUrlElement(actionName), actions.remove(actionName));
171171
}
172+
defaultActionName = urlConverter.toUrlElement(defaultActionName);
172173
}
173174

174175
/**

grails-test-suite-web/src/test/groovy/org/grails/web/taglib/CoreTagsTests.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class CoreTagsTests extends AbstractGrailsTagTests {
1313

1414
@Override
1515
protected void onSetUp() {
16+
System.setProperty(Environment.KEY, "dev")
17+
}
18+
19+
@Override
20+
protected void onDestroy() {
1621
System.setProperty(Environment.KEY, "")
1722
}
1823

grails-web-gsp/src/main/groovy/org/grails/web/servlet/view/GroovyPageViewResolver.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ public GroovyPageViewResolver(GroovyPagesTemplateEngine templateEngine,
8282
public void setGroovyPageLocator(GrailsConventionGroovyPageLocator groovyPageLocator) {
8383
this.groovyPageLocator = groovyPageLocator;
8484
}
85-
86-
@Override
87-
public View resolveViewName(String viewName, Locale locale) throws Exception {
88-
return super.resolveViewName(WebUtils.addViewPrefix(viewName), locale);
89-
}
9085

9186
@Override
9287
protected View loadView(String viewName, Locale locale) throws Exception {

grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/mvc/UrlMappingsHandlerMappingSpec.groovy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,41 @@ class UrlMappingsHandlerMappingSpec extends AbstractUrlMappingsSpec {
160160
then:"The model and view is correct"
161161
result.viewName == 'fooBar'
162162
!result.model
163+
}
164+
165+
void "Test that a matched URL returns a URLMappingInfo with controller with defaultAction"() {
166+
167+
given:
168+
def grailsApplication = new DefaultGrailsApplication(FooController)
169+
grailsApplication.initialise()
170+
def holder = getUrlMappingsHolder {
171+
"/foo"(controller:"foo")
172+
}
173+
def urlConverter = new HyphenatedUrlConverter()
174+
holder = new GrailsControllerUrlMappings(grailsApplication, holder, urlConverter)
175+
def handler = new UrlMappingsHandlerMapping(holder)
176+
177+
when:"A URI is matched"
163178

179+
def webRequest = GrailsWebMockUtil.bindMockWebRequest()
180+
webRequest.renderView = true
181+
def request = webRequest.request
182+
request.setRequestURI("/foo")
183+
def handlerChain = handler.getHandler(request)
184+
185+
then:"A handlerChain is created"
186+
handlerChain != null
187+
188+
when:"A HandlerAdapter is used with a hyphenated url converter"
189+
def handlerAdapter = new UrlMappingsInfoHandlerAdapter()
190+
def result = handlerAdapter.handle(request, webRequest.response, handlerChain.handler)
191+
192+
then:"The model and view is correct"
193+
result.viewName == 'fooBar'
194+
!result.model
164195
}
165196

197+
166198
void "test modelAndView is returned for URI"() {
167199
given:
168200
def grailsApplication = new DefaultGrailsApplication(FooController)
@@ -186,6 +218,9 @@ class UrlMappingsHandlerMappingSpec extends AbstractUrlMappingsSpec {
186218

187219
@Artefact('Controller')
188220
class FooController {
221+
222+
static defaultAction = 'fooBar'
223+
189224
@Action
190225
def bar() {
191226
[foo:"bar"]

0 commit comments

Comments
 (0)