Use common organization for User factory
What does this MR do and why?
This is split off from Withdraw abilities when organization does not m... (!196700 - merged)
grouporganizations is working on isolating organization data. This means that related data should be part of the same organization.
This MR will introduce the concept of a "Common Organization" for the Users factory. I also had to apply a similar to the Namespace factory.
It also introduce specs for the Users factory. This helps refactoring the logic in the code
Summary of changes
Application logic
- Removal of
Organizations::Organization.create_default_organization_record_formethod: it is no longer use - Addition of
Organization#inspectmethod: It will a shorter representation:#<Organizations::Organization id:1000 path:my-org>
Test changes
- Introduction of Common Organization:
- It will be created if no organization is specified
- It will be re-used if needed again
- It will also be used by other factories, in follow-up MR's
- Simplified setup for Personal Namespace:
user.namespace.organization == user.organization - Traits removal:
- Removal of
with_organizationtrait inUserfactory: no longer needed - Removal of
without_default_orgtrait inUserfactory: no longer needed
- Removal of
- Test setup changes:
- When you don't want a user to be member of any organization, we need to explicitly supply an empty array:
create(:user, organizations: []) - When you want to be sure that some objects are in different organizations, you need to explicitly assign organizations
- When you don't want a user to be member of any organization, we need to explicitly supply an empty array:
References
How to set up and validate locally
I asked our AI chat to create a script that would parse our spec files using parser gem and find usages of create(:user) and variations.
Based on that, I ran a subset of spec files, with different variations of `create(:user)`:
spec/controllers/admin/users_controller_spec.rb
spec/controllers/oauth/authorizations_controller_spec.rb
spec/factories_specs/users_spec.rb
spec/features/admin/admin_users_impersonation_tokens_spec.rb
spec/features/admin/users/users_spec.rb
spec/features/file_uploads/group_import_spec.rb
spec/features/groups_spec.rb
spec/features/ide_spec.rb
spec/features/oauth_provider_authorize_spec.rb
spec/features/participants_autocomplete_spec.rb
spec/features/users/show_spec.rb
spec/finders/issuables/crm_organization_filter_spec.rb
spec/finders/organizations/user_organizations_finder_spec.rb
spec/finders/personal_access_tokens_finder_spec.rb
spec/finders/projects_finder_spec.rb
spec/frontend/fixtures/organizations.rb
spec/graphql/resolvers/topics_resolver_spec.rb
spec/graphql/resolvers/users/organizations_resolver_spec.rb
spec/helpers/admin/users_helper_spec.rb
spec/helpers/namespaces_helper_spec.rb
spec/helpers/organizations/organization_helper_spec.rb
spec/helpers/users_helper_spec.rb
spec/lib/banzai/filter/references/user_reference_filter_spec.rb
spec/lib/gitlab/auth_spec.rb
spec/lib/gitlab/current/organization_spec.rb
spec/lib/gitlab/github_gists_import/importer/gist_importer_spec.rb
spec/lib/gitlab/seeders/ci/runner/runner_fleet_seeder_spec.rb
spec/lib/gitlab/spamcheck/client_spec.rb
spec/lib/mattermost/session_spec.rb
spec/lib/sidebars/organizations/menus/manage_menu_spec.rb
spec/lib/sidebars/organizations/menus/scope_menu_spec.rb
spec/lib/sidebars/organizations/menus/settings_menu_spec.rb
spec/lib/sidebars/organizations/panel_spec.rb
spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb
spec/lib/sidebars/your_work/menus/organizations_menu_spec.rb
spec/lib/users/internal_spec.rb
spec/models/namespace_spec.rb
spec/models/organizations/organization_spec.rb
spec/models/organizations/organization_user_detail_spec.rb
spec/models/organizations/organization_user_spec.rb
spec/models/user_spec.rb
spec/policies/organizations/organization_policy_spec.rb
spec/policies/organizations/organization_user_policy_spec.rb
spec/requests/admin/impersonation_tokens_controller_spec.rb
spec/requests/admin/organizations_controller_spec.rb
spec/requests/api/graphql/editor_extensions_spec.rb
spec/requests/api/graphql/mutations/organizations/create_spec.rb
spec/requests/api/graphql/organizations/organizations_query_spec.rb
spec/requests/api/group_import_spec.rb
spec/requests/api/group_milestones_spec.rb
spec/requests/api/groups_spec.rb
spec/requests/api/helpers_spec.rb
spec/requests/api/import_bitbucket_server_spec.rb
spec/requests/api/internal/base_spec.rb
spec/requests/api/invitations_spec.rb
spec/requests/oauth/authorizations_controller_spec.rb
spec/requests/oauth/flows/authorization_code_pkce_spec.rb
spec/requests/oauth/flows/authorization_code_spec.rb
spec/requests/oauth/flows/device_grant_spec.rb
spec/requests/oauth/flows/oidc_code_spec.rb
spec/requests/oauth/flows/resource_owner_password_spec.rb
spec/requests/oauth/tokens_controller_spec.rb
spec/requests/organizations/groups_controller_spec.rb
spec/requests/organizations/organizations_controller_spec.rb
spec/requests/organizations/projects_controller_spec.rb
spec/requests/organizations/settings_controller_spec.rb
spec/requests/user_avatar_spec.rb
spec/services/snippets/create_service_spec.rb
spec/support/shared_contexts/policies/project_policy_shared_context.rb
spec/support/shared_examples/features/secure_oauth_authorizations_shared_examples.rb
spec/support/shared_examples/requests/admin_mode_shared_examples.rb
spec/tasks/gitlab/seed/group_seed_rake_spec.rb
spec/tasks/gitlab/seed/runner_fleet_rake_spec.rb
spec/views/layouts/organization.html.haml_spec.rb
spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb
These tests should pass
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.