diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-07 12:11:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-07 12:11:43 +0300 |
commit | 378308b6cde44eb1a320b9202ff8946a911f35f6 (patch) | |
tree | 3031a645455dbbcdb2961dd09c15100fa28ed8e1 /spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb | |
parent | 777dc3053f8433a9f5c9cc868325e16eac5d93e5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb')
-rw-r--r-- | spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb b/spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb new file mode 100644 index 00000000000..b9cc9de88cc --- /dev/null +++ b/spec/migrations/20210831203408_upsert_base_work_item_types_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration!('upsert_base_work_item_types') + +RSpec.describe UpsertBaseWorkItemTypes, :migration do + let!(:work_item_types) { table(:work_item_types) } + + context 'when no default types exist' do + it 'creates default data' do + expect(work_item_types.count).to eq(0) + + reversible_migration do |migration| + migration.before -> { + # Depending on whether the migration has been run before, + # the size could be 4, or 0, so we don't set any expectations + # as we don't delete base types on migration reverse + } + + migration.after -> { + expect(work_item_types.count).to eq(4) + expect(work_item_types.all.pluck(:base_type)).to match_array(WorkItem::Type.base_types.values) + } + end + end + end + + context 'when default types already exist' do + before do + Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.import + end + + it 'does not create default types again' do + expect(work_item_types.all.pluck(:base_type)).to match_array(WorkItem::Type.base_types.values) + + reversible_migration do |migration| + migration.before -> { + expect(work_item_types.all.pluck(:base_type)).to match_array(WorkItem::Type.base_types.values) + } + + migration.after -> { + expect(work_item_types.count).to eq(4) + expect(work_item_types.all.pluck(:base_type)).to match_array(WorkItem::Type.base_types.values) + } + end + end + end +end |