diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb')
-rw-r--r-- | spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb b/spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb new file mode 100644 index 00000000000..ee1f718849f --- /dev/null +++ b/spec/migrations/cleanup_projects_with_bad_has_external_wiki_data_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe CleanupProjectsWithBadHasExternalWikiData, :migration do + let(:namespace) { table(:namespaces).create!(name: 'foo', path: 'bar') } + let(:projects) { table(:projects) } + let(:services) { table(:services) } + + def create_projects!(num) + Array.new(num) do + projects.create!(namespace_id: namespace.id) + end + end + + def create_active_external_wiki_integrations!(*projects) + projects.each do |project| + services.create!(type: 'ExternalWikiService', project_id: project.id, active: true) + end + end + + def create_disabled_external_wiki_integrations!(*projects) + projects.each do |project| + services.create!(type: 'ExternalWikiService', project_id: project.id, active: false) + end + end + + def create_active_other_integrations!(*projects) + projects.each do |project| + services.create!(type: 'NotAnExternalWikiService', project_id: project.id, active: true) + end + end + + it 'sets `projects.has_external_wiki` correctly' do + allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + + project_with_external_wiki_1, + project_with_external_wiki_2, + project_with_disabled_external_wiki_1, + project_with_disabled_external_wiki_2, + project_without_external_wiki_1, + project_without_external_wiki_2 = create_projects!(6) + + create_active_external_wiki_integrations!( + project_with_external_wiki_1, + project_with_external_wiki_2 + ) + + create_disabled_external_wiki_integrations!( + project_with_disabled_external_wiki_1, + project_with_disabled_external_wiki_2 + ) + + create_active_other_integrations!( + project_without_external_wiki_1, + project_without_external_wiki_2 + ) + + # PG triggers on the services table added in a previous migration + # will have set the `has_external_wiki` columns to correct data when + # the services records were created above. + # + # We set the `has_external_wiki` columns for projects to incorrect + # data manually below to emulate projects in a state before the PG + # triggers were added. + project_with_external_wiki_2.update!(has_external_wiki: false) + project_with_disabled_external_wiki_2.update!(has_external_wiki: true) + project_without_external_wiki_2.update!(has_external_wiki: true) + + migrate! + + expected_true = [ + project_with_external_wiki_1, + project_with_external_wiki_2 + ].each(&:reload).map(&:has_external_wiki) + + expected_not_true = [ + project_without_external_wiki_1, + project_without_external_wiki_2, + project_with_disabled_external_wiki_1, + project_with_disabled_external_wiki_2 + ].each(&:reload).map(&:has_external_wiki) + + expect(expected_true).to all(eq(true)) + expect(expected_not_true).to all(be_falsey) + end +end |