From 1bcf63a9b247bb8801bb0c39e764c1ef7f2df2dd Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 2 May 2023 03:09:17 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .rubocop_todo/lint/unused_block_argument.yml | 1 - Gemfile | 2 +- Gemfile.checksum | 2 +- Gemfile.lock | 4 +- app/controllers/concerns/registrations_tracking.rb | 17 -- .../registrations/welcome_controller.rb | 8 +- app/controllers/registrations_controller.rb | 9 +- app/models/namespace/root_storage_statistics.rb | 2 +- app/views/devise/registrations/new.html.haml | 2 +- app/views/registrations/welcome/show.html.haml | 2 +- doc/administration/audit_events.md | 164 +++++----- doc/topics/awesome_co.md | 331 --------------------- doc/topics/data_seeder.md | 331 +++++++++++++++++++++ package.json | 2 +- .../registrations/welcome_controller_spec.rb | 10 +- spec/controllers/registrations_controller_spec.rb | 12 +- spec/frontend/oauth_remember_me_spec.js | 5 +- spec/support/helpers/callouts_test_helper.rb | 9 - .../db/seeds/awesome_co_shared_examples.rb | 111 ------- .../db/seeds/data_seeder_shared_examples.rb | 111 +++++++ .../registrations/welcome/show.html.haml_spec.rb | 2 +- yarn.lock | 8 +- 22 files changed, 582 insertions(+), 563 deletions(-) delete mode 100644 app/controllers/concerns/registrations_tracking.rb delete mode 100644 doc/topics/awesome_co.md create mode 100644 doc/topics/data_seeder.md delete mode 100644 spec/support/helpers/callouts_test_helper.rb delete mode 100644 spec/support/shared_examples/db/seeds/awesome_co_shared_examples.rb create mode 100644 spec/support/shared_examples/db/seeds/data_seeder_shared_examples.rb diff --git a/.rubocop_todo/lint/unused_block_argument.yml b/.rubocop_todo/lint/unused_block_argument.yml index 59e89969751..7676faf0275 100644 --- a/.rubocop_todo/lint/unused_block_argument.yml +++ b/.rubocop_todo/lint/unused_block_argument.yml @@ -37,7 +37,6 @@ Lint/UnusedBlockArgument: - 'app/models/customer_relations/organization.rb' - 'app/models/integration.rb' - 'app/models/merge_request.rb' - - 'app/models/namespace/root_storage_statistics.rb' - 'app/models/project.rb' - 'app/models/projects/build_artifacts_size_refresh.rb' - 'app/models/service_desk_setting.rb' diff --git a/Gemfile b/Gemfile index c95555ab707..fd447d3e3e2 100644 --- a/Gemfile +++ b/Gemfile @@ -482,7 +482,7 @@ gem 'gitlab-mail_room', '~> 0.0.23', require: 'mail_room' gem 'email_reply_trimmer', '~> 0.1' gem 'html2text' -gem 'stackprof', '~> 0.2.23', require: false +gem 'stackprof', '~> 0.2.25', require: false gem 'rbtrace', '~> 0.4', require: false gem 'memory_profiler', '~> 1.0', require: false gem 'activerecord-explain-analyze', '~> 0.1', require: false diff --git a/Gemfile.checksum b/Gemfile.checksum index f0c905fb063..822ca2aa076 100644 --- a/Gemfile.checksum +++ b/Gemfile.checksum @@ -607,7 +607,7 @@ {"name":"sqlite3","version":"1.6.0","platform":"x86_64-linux","checksum":"a2488dcf0e72928bab2b15b934113ce8d7a3b4031277e362d66e40956d5c709e"}, {"name":"ssh_data","version":"1.3.0","platform":"ruby","checksum":"ec7c1e95a3aebeee412147998f4c147b4b05da6ed0aafda6083f9449318eaac0"}, {"name":"ssrf_filter","version":"1.0.8","platform":"ruby","checksum":"03f49f54837e407d43ee93ec733a8a94dc1bcf8185647ac61606e63aaedaa0db"}, -{"name":"stackprof","version":"0.2.23","platform":"ruby","checksum":"5c930b229c27bc64a2a0eb5e7203d76756ba0567bad7bf5290921ee1ed50230b"}, +{"name":"stackprof","version":"0.2.25","platform":"ruby","checksum":"28db0e2d22b817ae35def7163822505a04a026b02ef119b6aa89d70b967b0d2e"}, {"name":"state_machines","version":"0.5.0","platform":"ruby","checksum":"23e6249d374a920b528dccade403518b4abbd83841a3e2c9ef13e6f1a009b102"}, {"name":"state_machines-activemodel","version":"0.8.0","platform":"ruby","checksum":"e932dab190d4be044fb5f9cab01a3ea0b092c5f113d4676c6c0a0d49bf738d2c"}, {"name":"state_machines-activerecord","version":"0.8.0","platform":"ruby","checksum":"072fb701b8ab03de0608297f6c55dc34ed096e556fa8f77e556f3c461c71aab6"}, diff --git a/Gemfile.lock b/Gemfile.lock index a523cffd594..722bca18861 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1490,7 +1490,7 @@ GEM mini_portile2 (~> 2.8.0) ssh_data (1.3.0) ssrf_filter (1.0.8) - stackprof (0.2.23) + stackprof (0.2.25) state_machines (0.5.0) state_machines-activemodel (0.8.0) activemodel (>= 5.1) @@ -1941,7 +1941,7 @@ DEPENDENCIES sprite-factory (~> 1.7) sprockets (~> 3.7.0) ssh_data (~> 1.3) - stackprof (~> 0.2.23) + stackprof (~> 0.2.25) state_machines-activerecord (~> 0.8.0) sys-filesystem (~> 1.4.3) tanuki_emoji (~> 0.6) diff --git a/app/controllers/concerns/registrations_tracking.rb b/app/controllers/concerns/registrations_tracking.rb deleted file mode 100644 index 6c83c57d9dd..00000000000 --- a/app/controllers/concerns/registrations_tracking.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module RegistrationsTracking - extend ActiveSupport::Concern - - included do - helper_method :glm_tracking_params - end - - private - - def glm_tracking_params - params.permit(:glm_source, :glm_content) - end -end - -RegistrationsTracking.prepend_mod diff --git a/app/controllers/registrations/welcome_controller.rb b/app/controllers/registrations/welcome_controller.rb index 87fcb499d21..158536b6ba1 100644 --- a/app/controllers/registrations/welcome_controller.rb +++ b/app/controllers/registrations/welcome_controller.rb @@ -4,12 +4,13 @@ module Registrations class WelcomeController < ApplicationController include OneTrustCSP include GoogleAnalyticsCSP - include RegistrationsTracking layout 'minimal' skip_before_action :authenticate_user!, :required_signup_info, :check_two_factor_requirement, only: [:show, :update] before_action :require_current_user + helper_method :welcome_update_params + feature_category :user_management def show @@ -98,6 +99,11 @@ module Registrations # overridden in EE def track_event(action); end + + # overridden in EE + def welcome_update_params + {} + end end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 5c67e056d66..9a1f1532d7f 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -9,7 +9,6 @@ class RegistrationsController < Devise::RegistrationsController include BizibleCSP include GoogleAnalyticsCSP include PreferredLanguageSwitcher - include RegistrationsTracking include Gitlab::Tracking::Helpers::WeakPasswordErrorEvent layout 'devise' @@ -30,6 +29,7 @@ class RegistrationsController < Devise::RegistrationsController feature_category :user_management helper_method :arkose_labs_enabled? + helper_method :registration_path_params def new @resource = build_resource @@ -150,7 +150,12 @@ class RegistrationsController < Devise::RegistrationsController private def after_sign_up_path - users_sign_up_welcome_path(glm_tracking_params) + users_sign_up_welcome_path + end + + # overridden in EE + def registration_path_params + {} end def track_creation(user:) diff --git a/app/models/namespace/root_storage_statistics.rb b/app/models/namespace/root_storage_statistics.rb index 6a932939ae9..0443e1d9231 100644 --- a/app/models/namespace/root_storage_statistics.rb +++ b/app/models/namespace/root_storage_statistics.rb @@ -47,7 +47,7 @@ class Namespace::RootStorageStatistics < ApplicationRecord attributes_from_namespace_statistics, attributes_for_container_registry_size, attributes_for_forks_statistics - ) { |key, v1, v2| v1 + v2 } + ) { |_, v1, v2| v1 + v2 } end def attributes_for_container_registry_size diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 3bd7147f195..e75449bf320 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -9,7 +9,7 @@ .signup-page = render signup_box_template, - url: registration_path(resource_name, glm_tracking_params.to_hash), + url: registration_path(resource_name, registration_path_params), button_text: _('Register'), borderless: Feature.enabled?(:restyle_login_page, @project), show_omniauth_providers: omniauth_enabled? && button_based_providers_enabled? diff --git a/app/views/registrations/welcome/show.html.haml b/app/views/registrations/welcome/show.html.haml index 45c23aa7190..f99485ad1eb 100644 --- a/app/views/registrations/welcome/show.html.haml +++ b/app/views/registrations/welcome/show.html.haml @@ -18,7 +18,7 @@ - else %p.gl-text-center= html_escape(_('%{gitlab_experience_text}. Don\'t worry, this information isn\'t shared outside of your self-managed GitLab instance.')) % { gitlab_experience_text: gitlab_experience_text } = gitlab_ui_form_for(current_user, - url: users_sign_up_welcome_path(glm_tracking_params), + url: users_sign_up_welcome_path(welcome_update_params), html: { class: 'gl-w-full! gl-p-5 js-users-signup-welcome', 'aria-live' => 'assertive', data: { testid: 'welcome-form' } }) do |f| diff --git a/doc/administration/audit_events.md b/doc/administration/audit_events.md index 0f9f7eae1aa..91a3afba5d2 100644 --- a/doc/administration/audit_events.md +++ b/doc/administration/audit_events.md @@ -237,98 +237,116 @@ The following actions on groups generate group audit events: The following actions on projects generate project audit events: -- Added or removed deploy keys -- Project created, deleted, renamed, moved (transferred), changed path -- Project changed visibility level -- User was added to project and with which [permissions](../user/permissions.md) -- Permission changes of a user assigned to a project -- User was removed from project -- Project export was downloaded -- Project repository was downloaded -- Project was archived -- Project was unarchived -- Branch protection was added, removed, or updated -- Release was added to a project -- Release was updated -- Release was deleted. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/94793/) in GitLab 15.3. -- Release milestone associations changed -- Permission to approve merge requests by committers was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. -- Permission to approve merge requests by committers was updated. - - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. - - Message for event [changed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72623/diffs) in GitLab 14.6. -- Permission to approve merge requests by authors was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. -- Number of required approvals was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. -- Added or removed users and groups from project approval groups. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/213603) in GitLab 13.2. -- Project CI/CD variable added, removed, or protected status changed. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/30857) in GitLab 13.4. -- Project access token was successfully created or revoked. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/230007) in GitLab 13.9. -- Failed attempt to create or revoke a project access token. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/230007) in GitLab 13.9. -- When default branch changes for a project. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/52339) in GitLab 13.9. -- Created, updated, or deleted DAST profiles, DAST scanner profiles, and DAST site profiles. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/217872) in GitLab 14.1. -- Changed a project's compliance framework. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/329362) in GitLab 14.1. -- User password required for approvals was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. -- Permission to modify merge requests approval rules in merge requests was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. -- New approvals requirement when new commits are added to an MR was updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. -- When [strategies for feature flags](../operations/feature_flags.md#feature-flag-strategies) are changed. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68408) in GitLab 14.3. -- Allowing force push to protected branch changed. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. -- Code owner approval requirement on merge requests targeting protected branch changed. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. -- Users and groups allowed to merge and push to protected branch added or removed. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. +#### Project management + +- Added or removed deploy keys. +- Project created, deleted, renamed, moved (transferred), changed path. +- Project changed visibility level. +- Project export was downloaded. +- Project repository was downloaded. +- Project was archived. +- Project was unarchived. +- Project had a security policy project linked, changed, or unlinked. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/377877) in GitLab 15.6. +- Project was scheduled for deletion due to inactivity. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85689) in GitLab 15.0. - Project deploy token was successfully created, revoked or deleted. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/353451) in GitLab 14.9. - Failed attempt to create a project deploy token. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/353451) in GitLab 14.9. -- When merge method is updated. +- When [strategies for feature flags](../operations/feature_flags.md#feature-flag-strategies) are changed. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68408) in GitLab 14.3. + +#### User management + +- User was added to project and with which [permissions](../user/permissions.md). +- Permission changes of a user assigned to a project. +- User was removed from project. +- Users and groups allowed to merge and push to protected branch added or removed. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. + +#### Access control + +- Branch protection was added, removed, or updated. +- Failed attempt to create or revoke a project access token. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/230007) in GitLab 13.9. +- Allowing force push to protected branch changed. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. +- An environment is protected or unprotected. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/216164) in GitLab 15.8. +- User password required for approvals was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. +- Project access token was successfully created or revoked. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/230007) in GitLab 13.9. + +#### Code collaboration + +- Default description template for merge requests is updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. +- Merge commit message template is updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. +- Squash commit message template is updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. +- Delete source branch option by default enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- Merged results pipelines enabled or disabled. +- Squash commits when merging is updated. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- Merge trains enabled or disabled. +- All discussions must be resolved enabled or disabled. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. +- Commit message suggestion is updated. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. - Automatically resolve merge request diff discussions enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. - Show link to create or view a merge request when pushing from the command line enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- Delete source branch option by default enabled or disabled. +- When merge method is updated. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- Squash commits when merging is updated. +- Merge trains enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. +- Code owner approval requirement on merge requests targeting protected branch changed. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/338873) in GitLab 14.3. +- Permission to modify merge requests approval rules in merge requests was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. +- New approvals requirement when new commits are added to an MR was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336211) in GitLab 14.2. +- Added or removed users and groups from project approval groups. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/213603) in GitLab 13.2. +- Permission to approve merge requests by committers was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. + - Message for event [changed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72623/diffs) in GitLab 14.6. +- Permission to approve merge requests by authors was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. +- Number of required approvals was updated. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7531) in GitLab 12.9. + +#### Release management + +- Release was added to a project. +- Release was updated. +- Release was deleted. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/94793/) in GitLab 15.3. +- Release milestone associations changed. + +#### CI/CD + +- Project CI/CD variable added, removed, or protected status changed. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/30857) in GitLab 13.4. +- When default branch changes for a project. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/52339) in GitLab 13.9. - Pipelines must succeed enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. - Skipped pipelines are considered successful enabled or disabled. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- All discussions must be resolved enabled or disabled. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. -- Commit message suggestion is updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. - Status check is added, edited, or deleted. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. -- Merge commit message template is updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. -- Squash commit message template is updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. -- Default description template for merge requests is updated. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/355805) in GitLab 15.0. -- Project was scheduled for deletion due to inactivity. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85689) in GitLab 15.0. -- Project had a security policy project linked, changed, or unlinked. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/377877) in GitLab 15.6. -- An environment is protected or unprotected. - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/216164) in GitLab 15.8. +- Merged results pipelines enabled or disabled. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/301124) in GitLab 14.9. + +#### Compliance and security + +- Created, updated, or deleted DAST profiles, DAST scanner profiles, and DAST site profiles. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/217872) in GitLab 14.1. +- Changed a project's compliance framework. + [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/329362) in GitLab 14.1. ### GitLab agent for Kubernetes events diff --git a/doc/topics/awesome_co.md b/doc/topics/awesome_co.md deleted file mode 100644 index 9a75490a0e3..00000000000 --- a/doc/topics/awesome_co.md +++ /dev/null @@ -1,331 +0,0 @@ ---- -stage: Manage -group: Foundations -info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments -description: AwesomeCo test data harness created by the Test Data Working Group https://about.gitlab.com/company/team/structure/working-groups/demo-test-data/ ---- - -# AwesomeCo - -AwesomeCo is a test data seeding harness, that can seed test data into a user or group namespace. - -AwesomeCo uses FactoryBot in the backend which makes maintenance extremely easy. When a Model is changed, -FactoryBot will already be reflected to account for the change. - -## Docker Setup - -See [AwesomeCo Docker Demo](https://gitlab.com/-/snippets/2390362) - -## GDK Setup - -```shell -$ gdk start db -ok: run: services/postgresql: (pid n) 0s, normally down -ok: run: services/redis: (pid n) 74s, normally down -$ bundle install -Bundle complete! -$ bundle exec rake db:migrate -main: migrated -ci: migrated -``` - -### Run - -The `ee:gitlab:seed:awesome_co` Rake task takes two arguments. `:name` and `:namespace_id`. - -```shell -$ bundle exec rake "ee:gitlab:seed:awesome_co[awesome_co,1]" -Seeding AwesomeCo for Administrator -``` - -#### `:name` - -Where `:name` is the name of the AwesomeCo. (This will reflect .rb files located in db/seeds/awesome_co/*.rb) - -#### `:namespace_id` - -Where `:namespace_id` is the ID of the User or Group Namespace - -## Develop - -AwesomeCo seeding uses FactoryBot definitions from `spec/factories` which ... - -1. Saves time on development -1. Are easy-to-read -1. Are easy to maintain -1. Do not rely on an API that may change in the future -1. Are always up-to-date -1. Execute on the lowest-level (`ActiveRecord`) possible to create data as quickly as possible - -> From the [FactoryBot README](https://github.com/thoughtbot/factory_bot#readme_) : `factory_bot` is a fixtures replacement with a straightforward definition syntax, support for multiple build -> strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class, including factory -> inheritance - -Factories reside in `spec/factories/*` and are fixtures for Rails models found in `app/models/*`. For example, For a model named `app/models/issue.rb`, the factory will -be named `spec/factories/issues.rb`. For a model named `app/models/project.rb`, the factory will be named `app/models/projects.rb`. - -There are currently three parsers that the GitLab Data Seeder supports. Ruby, YAML, and JSON. - -### Ruby - -All Ruby Seeds must define a `DataSeeder` class with a `#seed` instance method. You may structure your Ruby class as you wish. All FactoryBot [methods](https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Methods) (`create`, `build`, `create_list`) will be included in the class automatically and may be called. - -The `DataSeeder` class will have the following instance variables defined upon seeding: - -- `@seed_file` - The `File` object. -- `@owner` - The owner of the seed data. -- `@name` - The name of the seed. This will be the seed file name without the extension. -- `@group` - The root group that all seeded data will be created under. - -```ruby -# frozen_string_literal: true - -class DataSeeder - def seed - my_group = create(:group, name: 'My Group', path: 'my-group-path', parent: @group) - my_project = create(:project, :public, name: 'My Project', namespace: my_group, creator: @owner) - end -end -``` - -### YAML - -The YAML Parser is a DSL that supports Factory definitions and allows you to seed data using a human-readable format. - -```yaml -name: My Seeder -groups: - - _id: my_group - name: My Group - path: my-group-path - -projects: - - _id: my_project - name: My Project - namespace_id: <%= groups.my_group.id %> - creator_id: <%= @owner.id %> - traits: - - public -``` - -### JSON - -The JSON Parser allows you to house seed files in JSON format. - -```json -{ - "name": "My Seeder", - "groups": [ - { "_id": "my_group", "name": "My Group", "path": "my-group-path" } - ], - "projects": [ - { - "_id": "my_project", - "name": "My Project", - "namespace_id": "<%= groups.my_group.id %>", - "creator_id": "<%= @owner.id %>", - "traits": ["public"] - } - ] -} -``` - -### Taxonomy of a Factory - -Factories consist of three main parts - the **Name** of the factory, the **Traits** and the **Attributes**. - -Given: `create(:iteration, :with_title, :current, title: 'My Iteration')` - -||| -|:-|:-| -| **:iteration** | This is the **Name** of the factory. The file name will be the plural form of this **Name** and reside under either `spec/factories/iterations.rb` or `ee/spec/factories/iterations.rb`. | -| **:with_title** | This is a **Trait** of the factory. [See how it's defined](https://gitlab.com/gitlab-org/gitlab/-/blob/9c2a1f98483921dd006d70fdaed316e21fc5652f/ee/spec/factories/iterations.rb#L21-23). | -| **:current** | This is a **Trait** of the factory. [See how it's defined](https://gitlab.com/gitlab-org/gitlab/-/blob/9c2a1f98483921dd006d70fdaed316e21fc5652f/ee/spec/factories/iterations.rb#L29-31). | -| **title: 'My Iteration'** | This is an **Attribute** of the factory that will be passed to the Model for creation. | - -### Examples - -In these examples, you will see an instance variable `@owner`. This is the `root` user (`User.first`). - -#### Create a Group - -```ruby -my_group = create(:group, name: 'My Group', path: 'my-group-path') -``` - -#### Create a Project - -```ruby -# create a Project belonging to a Group -my_project = create(:project, :public, name: 'My Project', namespace: my_group, creator: @owner) -``` - -#### Create an Issue - -```ruby -# create an Issue belonging to a Project -my_issue = create(:issue, title: 'My Issue', project: my_project, weight: 2) -``` - -#### Create an Iteration - -```ruby -# create an Iteration under a Group -my_iteration = create(:iteration, :with_title, :current, title: 'My Iteration', group: my_group) -``` - -### Frequently encountered issues - -#### ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, Username has already been taken - -This is because, by default, our factories are written to backfill any data that is missing. For instance, when a project -is created, the project must have somebody that created it. If the owner is not specified, the factory attempts to create it. - -**How to fix** - -Check the respective Factory to find out what key is required. Usually `:author` or `:owner`. - -```ruby -# This throws ActiveRecord::RecordInvalid -create(:project, name: 'Throws Error', namespace: create(:group, name: 'Some Group')) - -# Specify the user where @owner is a [User] record -create(:project, name: 'No longer throws error', owner: @owner, namespace: create(:group, name: 'Some Group')) -create(:epic, group: create(:group), author: @owner) -``` - -#### `parsing id "my id" as "my_id"` - -See [specifying variables](#specify-a-variable) - -#### `id is invalid` - -Given that non-Ruby parsers parse IDs as Ruby Objects, the [naming conventions](https://docs.ruby-lang.org/en/2.0.0/syntax/methods_rdoc.html#label-Method+Names) of Ruby must be followed when specifying an ID. - -Examples of invalid IDs: - -- IDs that start with a number -- IDs that have special characters (-, !, $, @, `, =, <, >, ;, :) - -#### ActiveRecord::AssociationTypeMismatch: Model expected, got ... which is an instance of String - -This is currently a limitation for the seeder. - -See the issue for [allowing parsing of raw Ruby objects](https://gitlab.com/gitlab-org/gitlab/-/issues/403079). - -## YAML Factories - -### Generator to generate _n_ amount of records - -### [Group Labels](https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/factories/labels.rb) - -```yaml -group_labels: - # Group Label with Name and a Color - - name: Group Label 1 - group_id: <%= @group.id %> - color: "#FF0000" -``` - -### [Group Milestones](https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/factories/milestones.rb) - -```yaml -group_milestones: - # Past Milestone - - name: Past Milestone - group_id: <%= @group.id %> - group: - start_date: <%= 1.month.ago %> - due_date: <%= 1.day.ago %> - - # Ongoing Milestone - - name: Ongoing Milestone - group_id: <%= @group.id %> - group: - start_date: <%= 1.day.ago %> - due_date: <%= 1.month.from_now %> - - # Future Milestone - - name: Ongoing Milestone - group_id: <%= @group.id %> - group: - start_date: <%= 1.month.from_now %> - due_date: <%= 2.months.from_now %> -``` - -#### Quirks - -- You _must_ specify `group:` and have it be empty. This is because the Milestones factory will manipulate the factory in an `after(:build)`. If this is not present, the Milestone will not be associated properly with the Group. - -### [Epics](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/spec/factories/epics.rb) - -```yaml -epics: - # Simple Epic - - title: Simple Epic - group_id: <%= @group.id %> - author_id: <%= @owner.id %> - - # Epic with detailed Markdown description - - title: Detailed Epic - group_id: <%= @group.id %> - author_id: <%= @owner.id %> - description: | - # Markdown - - **Description** - - # Epic with dates - - title: Epic with dates - group_id: <%= @group.id %> - author_id: <%= @owner.id %> - start_date: <%= 1.day.ago %> - due_date: <%= 1.month.from_now %> -``` - -## Variables - -Each created factory can be assigned an identifier to be used in future seeding. - -You can specify an ID for any created factory that you may use later in the seed file. - -### Specify a variable - -You may pass an `_id` attribute on any factory to refer back to it later in non-Ruby parsers. - -Variables are under the factory definitions that they reside in. - -```yaml ---- -group_labels: - - _id: my_label #=> group_labels.my_label - -projects: - - _id: my_project #=> projects.my_project -``` - -Variables: - -NOTE: -It is not advised, but you may specify variables with spaces. These variables may be referred back to with underscores. - -### Referencing a variable - -Given a YAML seed file: - -```yaml ---- -group_labels: - - _id: my_group_label #=> group_labels.my_group_label - name: My Group Label - color: "#FF0000" - - _id: my_other_group_label #=> group_labels.my_other_group_label - color: <%= group_labels.my_group_label.color %> - -projects: - - _id: my_project #=> projects.my_project - name: My Project -``` - -When referring to a variable, the variable refers to the _already seeded_ models. In other words, the model's `id` attribute will -be populated. diff --git a/doc/topics/data_seeder.md b/doc/topics/data_seeder.md new file mode 100644 index 00000000000..19c0e05d8ed --- /dev/null +++ b/doc/topics/data_seeder.md @@ -0,0 +1,331 @@ +--- +stage: Manage +group: Foundations +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments +description: Data Seeder test data harness created by the Test Data Working Group https://about.gitlab.com/company/team/structure/working-groups/demo-test-data/ +--- + +# GitLab Data Seeder + +GitLab Data Seeder (GDS) is a test data seeding harness, that can seed test data into a user or group namespace. + +The Data Seeder uses FactoryBot in the backend which makes maintenance extremely easy. When a Model is changed, +FactoryBot will already be reflected to account for the change. + +## Docker Setup + +See [Data Seeder Docker Demo](https://gitlab.com/-/snippets/2390362) + +## GDK Setup + +```shell +$ gdk start db +ok: run: services/postgresql: (pid n) 0s, normally down +ok: run: services/redis: (pid n) 74s, normally down +$ bundle install +Bundle complete! +$ bundle exec rake db:migrate +main: migrated +ci: migrated +``` + +### Run + +The `ee:gitlab:seed:data_seeder` Rake task takes two arguments. `:name` and `:namespace_id`. + +```shell +$ bundle exec rake "ee:gitlab:seed:data_seeder[data_seeder,1]" +Seeding Data for Administrator +``` + +#### `:name` + +Where `:name` is the file name. (This will reflect relative `.rb`, `.yml`, or `.json` files located in `ee/db/seeds/data_seeder`, or absolute paths to seed files) + +#### `:namespace_id` + +Where `:namespace_id` is the ID of the User or Group Namespace + +## Develop + +The Data Seeder uses FactoryBot definitions from `spec/factories` which ... + +1. Saves time on development +1. Are easy-to-read +1. Are easy to maintain +1. Do not rely on an API that may change in the future +1. Are always up-to-date +1. Execute on the lowest-level (`ActiveRecord`) possible to create data as quickly as possible + +> From the [FactoryBot README](https://github.com/thoughtbot/factory_bot#readme_) : `factory_bot` is a fixtures replacement with a straightforward definition syntax, support for multiple build +> strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class, including factory +> inheritance + +Factories reside in `spec/factories/*` and are fixtures for Rails models found in `app/models/*`. For example, For a model named `app/models/issue.rb`, the factory will +be named `spec/factories/issues.rb`. For a model named `app/models/project.rb`, the factory will be named `app/models/projects.rb`. + +There are currently three parsers that the GitLab Data Seeder supports. Ruby, YAML, and JSON. + +### Ruby + +All Ruby Seeds must define a `DataSeeder` class with a `#seed` instance method. You may structure your Ruby class as you wish. All FactoryBot [methods](https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Methods) (`create`, `build`, `create_list`) will be included in the class automatically and may be called. + +The `DataSeeder` class will have the following instance variables defined upon seeding: + +- `@seed_file` - The `File` object. +- `@owner` - The owner of the seed data. +- `@name` - The name of the seed. This will be the seed file name without the extension. +- `@group` - The root group that all seeded data will be created under. + +```ruby +# frozen_string_literal: true + +class DataSeeder + def seed + my_group = create(:group, name: 'My Group', path: 'my-group-path', parent: @group) + my_project = create(:project, :public, name: 'My Project', namespace: my_group, creator: @owner) + end +end +``` + +### YAML + +The YAML Parser is a DSL that supports Factory definitions and allows you to seed data using a human-readable format. + +```yaml +name: My Seeder +groups: + - _id: my_group + name: My Group + path: my-group-path + +projects: + - _id: my_project + name: My Project + namespace_id: <%= groups.my_group.id %> + creator_id: <%= @owner.id %> + traits: + - public +``` + +### JSON + +The JSON Parser allows you to house seed files in JSON format. + +```json +{ + "name": "My Seeder", + "groups": [ + { "_id": "my_group", "name": "My Group", "path": "my-group-path" } + ], + "projects": [ + { + "_id": "my_project", + "name": "My Project", + "namespace_id": "<%= groups.my_group.id %>", + "creator_id": "<%= @owner.id %>", + "traits": ["public"] + } + ] +} +``` + +### Taxonomy of a Factory + +Factories consist of three main parts - the **Name** of the factory, the **Traits** and the **Attributes**. + +Given: `create(:iteration, :with_title, :current, title: 'My Iteration')` + +||| +|:-|:-| +| **:iteration** | This is the **Name** of the factory. The file name will be the plural form of this **Name** and reside under either `spec/factories/iterations.rb` or `ee/spec/factories/iterations.rb`. | +| **:with_title** | This is a **Trait** of the factory. [See how it's defined](https://gitlab.com/gitlab-org/gitlab/-/blob/9c2a1f98483921dd006d70fdaed316e21fc5652f/ee/spec/factories/iterations.rb#L21-23). | +| **:current** | This is a **Trait** of the factory. [See how it's defined](https://gitlab.com/gitlab-org/gitlab/-/blob/9c2a1f98483921dd006d70fdaed316e21fc5652f/ee/spec/factories/iterations.rb#L29-31). | +| **title: 'My Iteration'** | This is an **Attribute** of the factory that will be passed to the Model for creation. | + +### Examples + +In these examples, you will see an instance variable `@owner`. This is the `root` user (`User.first`). + +#### Create a Group + +```ruby +my_group = create(:group, name: 'My Group', path: 'my-group-path') +``` + +#### Create a Project + +```ruby +# create a Project belonging to a Group +my_project = create(:project, :public, name: 'My Project', namespace: my_group, creator: @owner) +``` + +#### Create an Issue + +```ruby +# create an Issue belonging to a Project +my_issue = create(:issue, title: 'My Issue', project: my_project, weight: 2) +``` + +#### Create an Iteration + +```ruby +# create an Iteration under a Group +my_iteration = create(:iteration, :with_title, :current, title: 'My Iteration', group: my_group) +``` + +### Frequently encountered issues + +#### ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, Username has already been taken + +This is because, by default, our factories are written to backfill any data that is missing. For instance, when a project +is created, the project must have somebody that created it. If the owner is not specified, the factory attempts to create it. + +**How to fix** + +Check the respective Factory to find out what key is required. Usually `:author` or `:owner`. + +```ruby +# This throws ActiveRecord::RecordInvalid +create(:project, name: 'Throws Error', namespace: create(:group, name: 'Some Group')) + +# Specify the user where @owner is a [User] record +create(:project, name: 'No longer throws error', owner: @owner, namespace: create(:group, name: 'Some Group')) +create(:epic, group: create(:group), author: @owner) +``` + +#### `parsing id "my id" as "my_id"` + +See [specifying variables](#specify-a-variable) + +#### `id is invalid` + +Given that non-Ruby parsers parse IDs as Ruby Objects, the [naming conventions](https://docs.ruby-lang.org/en/2.0.0/syntax/methods_rdoc.html#label-Method+Names) of Ruby must be followed when specifying an ID. + +Examples of invalid IDs: + +- IDs that start with a number +- IDs that have special characters (-, !, $, @, `, =, <, >, ;, :) + +#### ActiveRecord::AssociationTypeMismatch: Model expected, got ... which is an instance of String + +This is currently a limitation for the seeder. + +See the issue for [allowing parsing of raw Ruby objects](https://gitlab.com/gitlab-org/gitlab/-/issues/403079). + +## YAML Factories + +### Generator to generate _n_ amount of records + +### [Group Labels](https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/factories/labels.rb) + +```yaml +group_labels: + # Group Label with Name and a Color + - name: Group Label 1 + group_id: <%= @group.id %> + color: "#FF0000" +``` + +### [Group Milestones](https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/factories/milestones.rb) + +```yaml +group_milestones: + # Past Milestone + - name: Past Milestone + group_id: <%= @group.id %> + group: + start_date: <%= 1.month.ago %> + due_date: <%= 1.day.ago %> + + # Ongoing Milestone + - name: Ongoing Milestone + group_id: <%= @group.id %> + group: + start_date: <%= 1.day.ago %> + due_date: <%= 1.month.from_now %> + + # Future Milestone + - name: Ongoing Milestone + group_id: <%= @group.id %> + group: + start_date: <%= 1.month.from_now %> + due_date: <%= 2.months.from_now %> +``` + +#### Quirks + +- You _must_ specify `group:` and have it be empty. This is because the Milestones factory will manipulate the factory in an `after(:build)`. If this is not present, the Milestone will not be associated properly with the Group. + +### [Epics](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/spec/factories/epics.rb) + +```yaml +epics: + # Simple Epic + - title: Simple Epic + group_id: <%= @group.id %> + author_id: <%= @owner.id %> + + # Epic with detailed Markdown description + - title: Detailed Epic + group_id: <%= @group.id %> + author_id: <%= @owner.id %> + description: | + # Markdown + + **Description** + + # Epic with dates + - title: Epic with dates + group_id: <%= @group.id %> + author_id: <%= @owner.id %> + start_date: <%= 1.day.ago %> + due_date: <%= 1.month.from_now %> +``` + +## Variables + +Each created factory can be assigned an identifier to be used in future seeding. + +You can specify an ID for any created factory that you may use later in the seed file. + +### Specify a variable + +You may pass an `_id` attribute on any factory to refer back to it later in non-Ruby parsers. + +Variables are under the factory definitions that they reside in. + +```yaml +--- +group_labels: + - _id: my_label #=> group_labels.my_label + +projects: + - _id: my_project #=> projects.my_project +``` + +Variables: + +NOTE: +It is not advised, but you may specify variables with spaces. These variables may be referred back to with underscores. + +### Referencing a variable + +Given a YAML seed file: + +```yaml +--- +group_labels: + - _id: my_group_label #=> group_labels.my_group_label + name: My Group Label + color: "#FF0000" + - _id: my_other_group_label #=> group_labels.my_other_group_label + color: <%= group_labels.my_group_label.color %> + +projects: + - _id: my_project #=> projects.my_project + name: My Project +``` + +When referring to a variable, the variable refers to the _already seeded_ models. In other words, the model's `id` attribute will +be populated. diff --git a/package.json b/package.json index 93a52a13f24..d7d9736a056 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@gitlab/cluster-client": "^1.2.0", "@gitlab/favicon-overlay": "2.0.0", "@gitlab/fonts": "^1.2.0", - "@gitlab/svgs": "3.42.0", + "@gitlab/svgs": "3.43.0", "@gitlab/ui": "62.5.1", "@gitlab/visual-review-tools": "1.7.3", "@gitlab/web-ide": "0.0.1-dev-20230425040132", diff --git a/spec/controllers/registrations/welcome_controller_spec.rb b/spec/controllers/registrations/welcome_controller_spec.rb index 3c631362119..4118754144c 100644 --- a/spec/controllers/registrations/welcome_controller_spec.rb +++ b/spec/controllers/registrations/welcome_controller_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Registrations::WelcomeController, feature_category: :system_access do let(:user) { create(:user) } - describe '#welcome' do + describe '#show' do subject(:show) { get :show } context 'without a signed in user' do @@ -27,6 +27,14 @@ RSpec.describe Registrations::WelcomeController, feature_category: :system_acces end it { is_expected.to render_template(:show) } + + render_views + + it 'has the expected submission url' do + show + + expect(response.body).to include("action=\"#{users_sign_up_welcome_path}\"") + end end context 'when role and setup_for_company is set' do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 92329b10426..9aa8a2ae605 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -12,15 +12,23 @@ RSpec.describe RegistrationsController, feature_category: :user_profile do end describe '#new' do - subject { get :new } + subject(:new) { get :new } it 'renders new template and sets the resource variable' do - expect(subject).to render_template(:new) + expect(new).to render_template(:new) expect(response).to have_gitlab_http_status(:ok) expect(assigns(:resource)).to be_a(User) end it_behaves_like "switches to user preferred language", 'Sign up' + + render_views + + it 'has the expected registration url' do + new + + expect(response.body).to include("action=\"#{user_registration_path}\"") + end end describe '#create' do diff --git a/spec/frontend/oauth_remember_me_spec.js b/spec/frontend/oauth_remember_me_spec.js index 7be3d441eb3..33295d46fea 100644 --- a/spec/frontend/oauth_remember_me_spec.js +++ b/spec/frontend/oauth_remember_me_spec.js @@ -1,5 +1,6 @@ import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import htmlOauthRememberMe from 'test_fixtures_static/oauth_remember_me.html'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import OAuthRememberMe from '~/pages/sessions/new/oauth_remember_me'; describe('OAuthRememberMe', () => { @@ -8,7 +9,7 @@ describe('OAuthRememberMe', () => { }; beforeEach(() => { - loadHTMLFixture('static/oauth_remember_me.html'); + setHTMLFixture(htmlOauthRememberMe); new OAuthRememberMe({ container: $('#oauth-container') }).bindEvents(); }); diff --git a/spec/support/helpers/callouts_test_helper.rb b/spec/support/helpers/callouts_test_helper.rb deleted file mode 100644 index 8c7faa71d9f..00000000000 --- a/spec/support/helpers/callouts_test_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module CalloutsTestHelper - def callouts_trials_link_path - '/-/trial_registrations/new?glm_content=gold-callout&glm_source=gitlab.com' - end -end - -CalloutsTestHelper.prepend_mod diff --git a/spec/support/shared_examples/db/seeds/awesome_co_shared_examples.rb b/spec/support/shared_examples/db/seeds/awesome_co_shared_examples.rb deleted file mode 100644 index ae0fe19f6b9..00000000000 --- a/spec/support/shared_examples/db/seeds/awesome_co_shared_examples.rb +++ /dev/null @@ -1,111 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'raises an error when specifying an invalid factory' do - it 'raises an error' do - expect { parser.parse }.to raise_error(RuntimeError, /invalids.*to a valid registered Factory/) - end -end - -RSpec.shared_examples 'specifying invalid traits to a factory' do - it 'raises an error', :aggregate_failures do - expect { parser.parse }.to raise_error do |error| - expect(error).to be_a(RuntimeError) - expect(error.message).to include('Trait not registered: \\"invalid\\"') - expect(error.message).to include('for Factory \\"issue\\"') - end - end -end - -RSpec.shared_examples 'specifying invalid attributes to a factory' do - it 'raises an error' do - expect { parser.parse }.to raise_error(RuntimeError, /is not a valid attribute/) - end - - it 'contains possible alternatives' do - expect { parser.parse }.to raise_error(RuntimeError, /Did you mean/) - end -end - -RSpec.shared_examples 'an id already exists' do - it 'raises a validation error' do - expect { parser.parse }.to raise_error(/id `my_label` must be unique/) - end -end - -RSpec.shared_examples 'name is not specified' do - it 'raises an error when name is not specified' do - expect { parser.parse }.to raise_error(/Seed file must specify a name/) - end -end - -RSpec.shared_examples 'factory definitions' do - it 'has exactly two definitions' do - parser.parse - - expect(parser.definitions.size).to eq(2) - end - - it 'creates the group label' do - expect { parser.parse }.to change { GroupLabel.count }.by(1) - end - - it 'creates the project' do - expect { parser.parse }.to change { Project.count }.by(1) - end -end - -RSpec.shared_examples 'passes traits' do - it 'passes traits' do - expect_next_instance_of(AwesomeCo::FactoryDefinitions::FactoryDefinition) do |instance| - # `described` trait will automaticaly generate a description - expect(instance.build(binding).description).to eq('Description of Test Label') - end - - parser.parse - end -end - -RSpec.shared_examples 'has a name' do - it 'has a name' do - parser.parse - - expect(parser.name).to eq('Test') - end -end - -RSpec.shared_examples 'definition has an id' do - it 'binds the object', :aggregate_failures do - parser.parse - - expect(group_labels).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse - expect(group_labels.my_label).to be_a(GroupLabel) - expect(group_labels.my_label.title).to eq('My Label') - end -end - -RSpec.shared_examples 'id has spaces' do - it 'binds to an underscored variable', :aggregate_failures do - parser.parse - - expect(group_labels).to respond_to(:id_with_spaces) - expect(group_labels.id_with_spaces.title).to eq('With Spaces') - end - - it 'renders a warning' do - expect { parser.parse }.to output(%(parsing id "id with spaces" as "id_with_spaces"\n)).to_stderr - end -end - -RSpec.shared_examples 'definition does not have an id' do - it 'does not bind the object' do - parser.parse - - expect(group_labels.to_h).to be_empty - end -end - -RSpec.shared_examples 'invalid id' do |message| - it 'raises an error' do - expect { parser.parse }.to raise_error(message) - end -end diff --git a/spec/support/shared_examples/db/seeds/data_seeder_shared_examples.rb b/spec/support/shared_examples/db/seeds/data_seeder_shared_examples.rb new file mode 100644 index 00000000000..4e8d65ac25e --- /dev/null +++ b/spec/support/shared_examples/db/seeds/data_seeder_shared_examples.rb @@ -0,0 +1,111 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'raises an error when specifying an invalid factory' do + it 'raises an error' do + expect { parser.parse }.to raise_error(RuntimeError, /invalids.*to a valid registered Factory/) + end +end + +RSpec.shared_examples 'specifying invalid traits to a factory' do + it 'raises an error', :aggregate_failures do + expect { parser.parse }.to raise_error do |error| + expect(error).to be_a(RuntimeError) + expect(error.message).to include('Trait not registered: \\"invalid\\"') + expect(error.message).to include('for Factory \\"issue\\"') + end + end +end + +RSpec.shared_examples 'specifying invalid attributes to a factory' do + it 'raises an error' do + expect { parser.parse }.to raise_error(RuntimeError, /is not a valid attribute/) + end + + it 'contains possible alternatives' do + expect { parser.parse }.to raise_error(RuntimeError, /Did you mean/) + end +end + +RSpec.shared_examples 'an id already exists' do + it 'raises a validation error' do + expect { parser.parse }.to raise_error(/id `my_label` must be unique/) + end +end + +RSpec.shared_examples 'name is not specified' do + it 'raises an error when name is not specified' do + expect { parser.parse }.to raise_error(/Seed file must specify a name/) + end +end + +RSpec.shared_examples 'factory definitions' do + it 'has exactly two definitions' do + parser.parse + + expect(parser.definitions.size).to eq(2) + end + + it 'creates the group label' do + expect { parser.parse }.to change { GroupLabel.count }.by(1) + end + + it 'creates the project' do + expect { parser.parse }.to change { Project.count }.by(1) + end +end + +RSpec.shared_examples 'passes traits' do + it 'passes traits' do + expect_next_instance_of(Gitlab::DataSeeder::FactoryDefinitions::FactoryDefinition) do |instance| + # `described` trait will automaticaly generate a description + expect(instance.build(binding).description).to eq('Description of Test Label') + end + + parser.parse + end +end + +RSpec.shared_examples 'has a name' do + it 'has a name' do + parser.parse + + expect(parser.name).to eq('Test') + end +end + +RSpec.shared_examples 'definition has an id' do + it 'binds the object', :aggregate_failures do + parser.parse + + expect(group_labels).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse + expect(group_labels.my_label).to be_a(GroupLabel) + expect(group_labels.my_label.title).to eq('My Label') + end +end + +RSpec.shared_examples 'id has spaces' do + it 'binds to an underscored variable', :aggregate_failures do + parser.parse + + expect(group_labels).to respond_to(:id_with_spaces) + expect(group_labels.id_with_spaces.title).to eq('With Spaces') + end + + it 'renders a warning' do + expect { parser.parse }.to output(%(parsing id "id with spaces" as "id_with_spaces"\n)).to_stderr + end +end + +RSpec.shared_examples 'definition does not have an id' do + it 'does not bind the object' do + parser.parse + + expect(group_labels.to_h).to be_empty + end +end + +RSpec.shared_examples 'invalid id' do |message| + it 'raises an error' do + expect { parser.parse }.to raise_error(message) + end +end diff --git a/spec/views/registrations/welcome/show.html.haml_spec.rb b/spec/views/registrations/welcome/show.html.haml_spec.rb index 372dbf01a64..e229df555b1 100644 --- a/spec/views/registrations/welcome/show.html.haml_spec.rb +++ b/spec/views/registrations/welcome/show.html.haml_spec.rb @@ -7,7 +7,7 @@ RSpec.describe 'registrations/welcome/show' do before do allow(view).to receive(:current_user).and_return(user) - allow(view).to receive(:glm_tracking_params).and_return({}) + allow(view).to receive(:welcome_update_params).and_return({}) render end diff --git a/yarn.lock b/yarn.lock index 4b5184c246e..ec89202c67e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1110,10 +1110,10 @@ stylelint-declaration-strict-value "1.8.0" stylelint-scss "4.2.0" -"@gitlab/svgs@3.42.0": - version "3.42.0" - resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-3.42.0.tgz#3168eb46ed9f87abc02b749cc1468902aee8e964" - integrity sha512-hOZtSWKndBP7WO7UxOe+dlMtWK+4J9srLBEAro8ZNcRufm+esF8N8HBPgFvx4ef6GVAW7Ej7qe1wW9kiQQGDyQ== +"@gitlab/svgs@3.43.0": + version "3.43.0" + resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-3.43.0.tgz#7789e6e5e8cd7d97489d9cfb021e0f25ddcfa829" + integrity sha512-o5P8T42qXh38DU0Px7rnVCV86cDfrsKHNczdNQAIGeyw5Ci7orsL/0f1M4BVtOSgU0VOoHuB0Yb/HyQjjmwt6A== "@gitlab/ui@62.5.1": version "62.5.1" -- cgit v1.2.1