Commit 057c094d authored by Stan Hu's avatar Stan Hu

Remove circular dependency on Redactable in migration

Gitlab::BackgroundMigration::RedactLinks was prepending
EE::Gitlab::BackgroundMigration::RedactLinks, while
EE::Gitlab::BackgroundMigration::RedactLinks was trying to include
Gitlab::BackgroundMigration::RedactLinks::Redactable. Ruby 2.5.3 failed
with an uninitialized constant
(https://gitlab.com/gitlab-org/gitlab-ee/-/jobs/118388511).
parent c756b66b
# frozen_string_literal: true
# rubocop:disable Style/Documentation
require_relative 'redact_links/redactable'
module Gitlab
module BackgroundMigration
class RedactLinks
prepend EE::Gitlab::BackgroundMigration::RedactLinks
module Redactable
extend ActiveSupport::Concern
def redact_field!(field)
self[field].gsub!(%r{/sent_notifications/\h{32}/unsubscribe}, '/sent_notifications/REDACTED/unsubscribe')
if self.changed?
self.update_columns(field => self[field],
"#{field}_html" => nil)
end
end
end
class Note < ActiveRecord::Base
include EachBatch
include Redactable
include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'notes'
self.inheritance_column = :_type_disabled
......@@ -29,7 +18,7 @@ module Gitlab
class Issue < ActiveRecord::Base
include EachBatch
include Redactable
include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'issues'
self.inheritance_column = :_type_disabled
......@@ -37,7 +26,7 @@ module Gitlab
class MergeRequest < ActiveRecord::Base
include EachBatch
include Redactable
include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'merge_requests'
self.inheritance_column = :_type_disabled
......@@ -45,7 +34,7 @@ module Gitlab
class Snippet < ActiveRecord::Base
include EachBatch
include Redactable
include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'snippets'
self.inheritance_column = :_type_disabled
......
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
class RedactLinks
module Redactable
extend ActiveSupport::Concern
def redact_field!(field)
self[field].gsub!(%r{/sent_notifications/\h{32}/unsubscribe}, '/sent_notifications/REDACTED/unsubscribe')
if self.changed?
self.update_columns(field => self[field],
"#{field}_html" => nil)
end
end
end
end
end
end
......@@ -4,6 +4,7 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:issues) { table(:issues) }
let(:epics) { table(:epics) }
let(:notes) { table(:notes) }
let(:snippets) { table(:snippets) }
let(:users) { table(:users) }
......@@ -41,6 +42,12 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
snippets.create(params)
end
def create_epic(id, params)
params.merge!(id: id, iid: id, title: "epic#{id}", title_html: "epic#{id}", author_id: user.id, group_id: namespace.id)
epics.create(params)
end
def create_resource(model, id, params)
send("create_#{model.name.underscore}", id, params)
end
......@@ -93,4 +100,11 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
let(:field) { :description }
end
end
context 'resource is Epic' do
it_behaves_like 'redactable resource' do
let(:model) { Epic }
let(:field) { :description }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment