diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb')
-rw-r--r-- | spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb b/spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb new file mode 100644 index 00000000000..41cf35b40f4 --- /dev/null +++ b/spec/migrations/update_integrations_trigger_type_new_on_insert_spec.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe UpdateIntegrationsTriggerTypeNewOnInsert do + let(:migration) { described_class.new } + let(:integrations) { table(:integrations) } + + shared_examples 'transforms known types' do + # This matches Gitlab::Integrations::StiType at the time the original trigger + # was added in db/migrate/20210721135638_add_triggers_to_integrations_type_new.rb + let(:namespaced_integrations) do + %w[ + Asana Assembla Bamboo Bugzilla Buildkite Campfire Confluence CustomIssueTracker Datadog + Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat Irker Jenkins Jira Mattermost + MattermostSlashCommands MicrosoftTeams MockCi MockMonitoring Packagist PipelinesEmail Pivotaltracker + Prometheus Pushover Redmine Slack SlackSlashCommands Teamcity UnifyCircuit WebexTeams Youtrack + + Github GitlabSlackApplication + ] + end + + it 'sets `type_new` to the transformed `type` class name' do + namespaced_integrations.each do |type| + integration = integrations.create!(type: "#{type}Service") + + expect(integration.reload).to have_attributes( + type: "#{type}Service", + type_new: "Integrations::#{type}" + ) + end + end + end + + describe '#up' do + before do + migrate! + end + + describe 'INSERT trigger with dynamic mapping' do + it_behaves_like 'transforms known types' + + it 'transforms unknown types if it ends in "Service"' do + integration = integrations.create!(type: 'AcmeService') + + expect(integration.reload).to have_attributes( + type: 'AcmeService', + type_new: 'Integrations::Acme' + ) + end + + it 'ignores "Service" occurring elsewhere in the type' do + integration = integrations.create!(type: 'ServiceAcmeService') + + expect(integration.reload).to have_attributes( + type: 'ServiceAcmeService', + type_new: 'Integrations::ServiceAcme' + ) + end + + it 'copies unknown types if it does not end with "Service"' do + integration = integrations.create!(type: 'Integrations::Acme') + + expect(integration.reload).to have_attributes( + type: 'Integrations::Acme', + type_new: 'Integrations::Acme' + ) + end + end + end + + describe '#down' do + before do + migration.up + migration.down + end + + describe 'INSERT trigger with static mapping' do + it_behaves_like 'transforms known types' + + it 'ignores types that are already namespaced' do + integration = integrations.create!(type: 'Integrations::Asana') + + expect(integration.reload).to have_attributes( + type: 'Integrations::Asana', + type_new: nil + ) + end + + it 'ignores types that are unknown' do + integration = integrations.create!(type: 'FooBar') + + expect(integration.reload).to have_attributes( + type: 'FooBar', + type_new: nil + ) + end + end + end +end |