matrei commented on code in PR #15562:
URL: https://github.com/apache/grails-core/pull/15562#discussion_r3051490516


##########
grails-test-examples/geb-context-path/src/integration-test/groovy/org/demo/contextpath/ContextPathSpec.groovy:
##########
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.demo.contextpath
+
+import org.demo.contextpath.pages.GreetingPage
+import org.demo.contextpath.pages.HomePage
+
+import grails.plugin.geb.ContainerGebSpec
+import grails.testing.mixin.integration.Integration
+
+/**
+ * Verifies that ContainerGebSpec correctly includes the server's
+ * context path in the browser's base URL. Without the context path
+ * in the base URL, page navigation would result in 404 errors.
+ */
+@Integration
+class ContextPathSpec extends ContainerGebSpec {
+
+    void 'should navigate to the home page under the configured context 
path'() {
+        when: 'visiting the home page'
+        to(HomePage)
+
+        then: 'the page loads successfully'
+        title == 'Welcome to Grails'
+    }
+
+    void 'should navigate to a controller under the configured context path'() 
{
+        when: 'visiting a controller page'
+        to(GreetingPage)
+
+        then: 'the controller action is reached and renders correctly'
+        title == 'Greeting'

Review Comment:
   This is actually already verified by `to(GreetingPage)`



##########
grails-doc/src/en/guide/upgrading/upgrading71x.adoc:
##########
@@ -698,6 +698,43 @@ Nested groups merge defaults — inner groups inherit and 
can extend or override
 
 For full details, see the 
link:{guidePath}theWebLayer/urlmappings/mappingToControllersAndActions.html#_group_defaults[Group
 Defaults] documentation.
 
+===== 2.10 ContainerGebSpec Context Path Support
+
+`ContainerGebSpec` now automatically includes the server's servlet context 
path in the browser's base URL. Previously, if your application configured a 
context path via `server.servlet.context-path`, the `ContainerGebSpec` base URL 
would only include the protocol, hostname, and port — causing all page 
navigations to miss the context path and result in 404 errors.
+
+Starting in Grails 7.1, the context path is looked up from the Spring 
`Environment` at test setup time and appended to the base URL automatically. No 
changes are required in your test code — Geb page URLs should remain relative 
to the context root (e.g., `static url = '/greeting'`), and the framework 
handles prepending the context path.
+
+====== Example
+
+[source,yaml]
+.application.yml
+----
+server:
+  servlet:
+    context-path: /myapp
+----
+
+[source,groovy]
+----
+// Page URL is relative — no need to include /myapp
+class GreetingPage extends Page {
+    static url = '/greeting'
+    static at = { title == 'Greeting' }
+}
+
+// Navigation automatically resolves to http://host:port/myapp/greeting
+@Integration
+class MySpec extends ContainerGebSpec {
+    void 'should reach the greeting page'() {
+        when:
+        to(GreetingPage)
+
+        then:
+        at(GreetingPage)

Review Comment:
   This is not the best example as it uses an anti-pattern.
   `to(GreetingPage)` implictly includes `at(GreetingPage)`.



##########
grails-doc/src/en/guide/upgrading/upgrading71x.adoc:
##########
@@ -698,6 +698,43 @@ Nested groups merge defaults — inner groups inherit and 
can extend or override
 
 For full details, see the 
link:{guidePath}theWebLayer/urlmappings/mappingToControllersAndActions.html#_group_defaults[Group
 Defaults] documentation.
 
+===== 2.10 ContainerGebSpec Context Path Support

Review Comment:
   The heading numbers are out of order.



##########
grails-test-examples/geb-context-path/src/integration-test/groovy/org/demo/contextpath/ContextPathSpec.groovy:
##########
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.demo.contextpath
+
+import org.demo.contextpath.pages.GreetingPage
+import org.demo.contextpath.pages.HomePage
+
+import grails.plugin.geb.ContainerGebSpec
+import grails.testing.mixin.integration.Integration
+
+/**
+ * Verifies that ContainerGebSpec correctly includes the server's
+ * context path in the browser's base URL. Without the context path
+ * in the base URL, page navigation would result in 404 errors.
+ */
+@Integration
+class ContextPathSpec extends ContainerGebSpec {
+
+    void 'should navigate to the home page under the configured context 
path'() {
+        when: 'visiting the home page'
+        to(HomePage)
+
+        then: 'the page loads successfully'
+        title == 'Welcome to Grails'

Review Comment:
   This is actually already verified by `to(HomePage)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to