diff options
Diffstat (limited to 'spec/migrations/20230418215853_add_assignee_widget_to_incidents_spec.rb')
-rw-r--r-- | spec/migrations/20230418215853_add_assignee_widget_to_incidents_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/migrations/20230418215853_add_assignee_widget_to_incidents_spec.rb b/spec/migrations/20230418215853_add_assignee_widget_to_incidents_spec.rb new file mode 100644 index 00000000000..d809d0e6a54 --- /dev/null +++ b/spec/migrations/20230418215853_add_assignee_widget_to_incidents_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe AddAssigneeWidgetToIncidents, :migration, feature_category: :team_planning do + let(:migration) { described_class.new } + let(:work_item_definitions) { table(:work_item_widget_definitions) } + let(:work_item_types) { table(:work_item_types) } + + let(:widget_name) { 'Assignees' } + let(:work_item_type) { 'Incident' } + + describe '#up' do + it 'creates widget definition' do + type = work_item_types.find_by_name_and_namespace_id(work_item_type, nil) + work_item_definitions.where(work_item_type_id: type, name: widget_name).delete_all if type + + expect { migrate! }.to change { work_item_definitions.count }.by(1) + + type = work_item_types.find_by_name_and_namespace_id(work_item_type, nil) + + expect(work_item_definitions.where(work_item_type_id: type, name: widget_name).count).to eq 1 + end + + it 'logs a warning if the type is missing' do + allow(described_class::WorkItemType).to receive(:find_by_name_and_namespace_id).and_call_original + allow(described_class::WorkItemType).to receive(:find_by_name_and_namespace_id) + .with(work_item_type, nil).and_return(nil) + + expect(Gitlab::AppLogger).to receive(:warn).with(AddAssigneeWidgetToIncidents::FAILURE_MSG) + migrate! + end + end + + describe '#down' do + it 'removes definitions for widget' do + migrate! + + expect { migration.down }.to change { work_item_definitions.count }.by(-1) + + type = work_item_types.find_by_name_and_namespace_id(work_item_type, nil) + + expect(work_item_definitions.where(work_item_type_id: type, name: widget_name).count).to eq 0 + end + end +end |