fix: fix flaky scaffolding Geb tests and User.getAuthorities() bug#15480
Merged
jamesfredley merged 1 commit into7.0.xfrom Mar 13, 2026
Merged
fix: fix flaky scaffolding Geb tests and User.getAuthorities() bug#15480jamesfredley merged 1 commit into7.0.xfrom
jamesfredley merged 1 commit into7.0.xfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an incorrect authority parsing implementation in the scaffolding example User domain and stabilizes two flaky Geb integration specs by performing login inside each test rather than in Spock setup().
Changes:
- Fix
User.getAuthorities()to split role strings on commas (and trim entries). - Replace
setup()-based login with anensureLoggedIn()helper called from each spec’swhen:block. - Apply the same test stabilization pattern to both
UserControllerSpecandUserCommunityControllerSpec.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
grails-test-examples/scaffolding/grails-app/domain/com/example/User.groovy |
Adjusts role parsing logic used to build Spring Security GrantedAuthority instances. |
grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserControllerSpec.groovy |
Moves login into the feature method to avoid session loss between Spock lifecycle phases. |
grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/UserCommunityControllerSpec.groovy |
Same login timing change to remove intermittent “Please sign in” failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jdaugherty
reviewed
Mar 4, 2026
Clear cookies before login in setup() to eliminate stale session state
from a previous spec's logout, which caused the second spec to see
'Please sign in' instead of the expected page.
Also fix User.getAuthorities() which incorrectly used roles.split('')
splitting each character into a separate GrantedAuthority instead of
splitting by comma delimiter.
Assisted-by: Claude Code <Claude@Claude.ai>
35492ea to
cc72ad5
Compare
✅ All tests passed ✅🏷️ Commit: cc72ad5 Learn more about TestLens at testlens.app. |
jdaugherty
approved these changes
Mar 13, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UserControllerSpecandUserCommunityControllerSpecGeb tests by clearing stale session cookies insetup()before login viaclearCookiesQuietly()User.getAuthorities()which incorrectly usedroles.split('')splitting each character into a separateGrantedAuthorityinstead of splitting by comma delimiterRoot Cause
CI logs showed the specs run sequentially with a shared browser instance:
The first spec's
cleanup()logs out, leaving stale session cookies. When the second spec'ssetup()navigates to/loginand submits the form, the inconsistent session state causes the login to silently fail - the browser ends up back on the login page instead of being authenticated.Adding
clearCookiesQuietly()before login insetup()ensures each spec starts with a clean browser state, eliminating the stale session interference.CI Failures
This test has been failing intermittently across multiple CI runs on
7.0.x:UserControllerSpec > User list FAILEDUserControllerSpec > User list FAILEDUserControllerSpec > User list FAILEDUserControllerSpec > User list FAILEDChanges
User.groovyroles.split('')-> proper comma-split with null/blank guardUserControllerSpec.groovyclearCookiesQuietly()insetup()before loginUserCommunityControllerSpec.groovyclearCookiesQuietly()insetup()before login