This is an automated email from the ASF dual-hosted git repository. jamesfredley pushed a commit to branch fix/scaffolding-test-flaky-login in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 8e7838bf301675e7ee5340adf582c79e632faf15 Author: James Fredley <[email protected]> AuthorDate: Mon Mar 2 20:06:27 2026 -0500 fix: fix flaky scaffolding Geb tests and roles.split bug Fix User.getAuthorities() which used roles.split('') splitting each character into a separate authority instead of splitting by comma. Changed to roles.split(',') with trim() for correct role parsing. Move login from Spock setup() into each test's when block to avoid session loss between the lifecycle boundary and the test method, which caused flaky failures on Java 25 where the browser would see 'Please sign in' instead of the expected page. Assisted-by: Claude Code <[email protected]> --- .../scaffolding/grails-app/domain/com/example/User.groovy | 2 +- .../groovy/com/example/UserCommunityControllerSpec.groovy | 5 +++-- .../src/integrationTest/groovy/com/example/UserControllerSpec.groovy | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/grails-test-examples/scaffolding/grails-app/domain/com/example/User.groovy b/grails-test-examples/scaffolding/grails-app/domain/com/example/User.groovy index 6ed3fb0df0..1a030f9562 100644 --- a/grails-test-examples/scaffolding/grails-app/domain/com/example/User.groovy +++ b/grails-test-examples/scaffolding/grails-app/domain/com/example/User.groovy @@ -56,7 +56,7 @@ class User implements UserDetails { @Override Collection<? extends GrantedAuthority> getAuthorities() { - roles.split('').collect { new SimpleGrantedAuthority(it) } + roles.split(',').collect { new SimpleGrantedAuthority(it.trim()) } } @Override diff --git a/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserCommunityControllerSpec.groovy b/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserCommunityControllerSpec.groovy index c88b7f74e6..0681e8dd34 100644 --- a/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserCommunityControllerSpec.groovy +++ b/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserCommunityControllerSpec.groovy @@ -28,7 +28,7 @@ import grails.testing.mixin.integration.Integration @Integration class UserCommunityControllerSpec extends ContainerGebSpec { - void setup() { + private void ensureLoggedIn() { to(LoginPage).login() } @@ -42,9 +42,10 @@ class UserCommunityControllerSpec extends ContainerGebSpec { void "User list"() { when: + ensureLoggedIn() def page = to(CommunityUserListPage) then: !page.scaffoldTable } -} \ No newline at end of file +} diff --git a/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserControllerSpec.groovy b/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserControllerSpec.groovy index da1f9f3409..246af2e7fc 100644 --- a/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserControllerSpec.groovy +++ b/grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserControllerSpec.groovy @@ -28,7 +28,7 @@ import grails.testing.mixin.integration.Integration @Integration class UserControllerSpec extends ContainerGebSpec { - void setup() { + private void ensureLoggedIn() { to(LoginPage).login() } @@ -42,9 +42,10 @@ class UserControllerSpec extends ContainerGebSpec { void "User list"() { when: + ensureLoggedIn() to(UserListPage) then: $('table.scaffold') } -} \ No newline at end of file +}
