Run feature specs with organization-scoped URLs (remove scoped_paths? mock and 'with Organization URL helpers' context)
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Background
!241405 (merged) aligned Rails path helpers in feature specs with the JavaScript path helpers by mocking Organizations::Organization#scoped_paths? to false in every feature spec (shared context 'with unscoped Organization paths for feature specs'). This removed a mismatch where JavaScript path helpers produced organization-scoped URLs (/o/:organization_path/...) while Rails path helpers produced unscoped URLs.
That MR is the right short-term fix for consistency, but it aligns everything in the unscoped direction. This issue tracks the follow-up: align everything in the scoped direction, so feature specs run the application exactly as a user in a non-default organization experiences it.
Problem
After !241405 (merged), feature specs never exercise organization-scoped URLs in the browser:
scoped_paths?is mocked tofalsefor everyOrganizations::Organizationinstance in every feature spec, viaallow_any_instance_of(which our testing guidelines forbid). The application under test is altered by the test suite.- The
'with Organization URL helpers'shared context (spec/support/shared_contexts/current_organization_context.rb) re-implements organization resolution inside the spec suite by stubbingRouting::OrganizationsHelper::MappedHelpers.current_organizationbased on the last captured request. Specs should not re-derive application behavior; they should observe it.
Note for implementers: before !241405 (merged), that MappedHelpers.current_organization stub was not a no-op for feature specs. RSpec stubs apply process-wide, so the Capybara server threads also received nil from it, which is what disabled organization-scoped Rails URL generation in served pages. Removing stubs here changes what the app renders, not only what the specs compute.
Proposal
- Remove the
scoped_paths?mock ('with unscoped Organization paths for feature specs'). - Remove the
'with Organization URL helpers'shared context and its request-capture machinery. - Align example-side URL helpers with the server through
Currentinstead: with the stubs gone, the realMappedHelpers.current_organizationreadsCurrent.organization, so including'with current_organization setting'(or equivalent) for feature specs makes helpers likeroot_pathreturn the same scoped paths the application renders. No per-specorganization_path:arguments needed. - Update specs that assert unscoped paths or that behave differently under
/o/routes. - Remove
spec/support/organization_url_header_fallback.rb(introduced by !258716 (merged), which removed theextended_organization_url_scopingflag). It stubsMappedHelpers.header_organizationtonilfor feature specs, so API responses stay unscoped even though the browser sendsX-GitLab-Organization-IDforcommon-org. Without it, feature specs fail withexpected "/o/common-org/..." to equal "/...". Once specs run scoped, this stub must go too.
Evidence from local experiments (2026-07-08)
- With the
MappedHelpersstub skipped for feature specs and no other mocks,spec/features/dashboard/projects_spec.rbpasses 24/24 using plain global helpers (for exampletopic_explore_projects_path), with all navigation and assertions on scoped URLs. This works because the file is tagged:with_current_organization, so example-side helpers and the server agree. - Feature specs without that tag fail when they assert paths, for example
spec/features/users/terms_spec.rb:expected "/o/common-org" to equal "/". These need theCurrentalignment from step 3 (or updated assertions). - Removing the context suite-wide also affects request specs: 15 examples in
spec/requests/verifies_with_email_spec.rbfailed because sign-in requests started going to/o/:organization_path/users/sign_in, where the flow responded differently (200 instead of a redirect). This difference should be investigated — it may be a real behavioral gap on scoped routes rather than a test artifact.
Acceptance criteria
-
'with unscoped Organization paths for feature specs'is removed; noallow_any_instance_of(Organizations::Organization)remains in spec support. -
'with Organization URL helpers'and the request-capture shared contexts are removed. - Feature specs run against the unmodified application and exercise organization-scoped URLs by default.
- Behavioral differences found on scoped routes (for example the sign-in flow above) are triaged as app bugs or expected behavior.
References
- #601550
- !241405 (merged) (the consistency fix this issue follows up on)
spec/support/shared_contexts/current_organization_context.rbapp/helpers/routing/organizations_helper.rb