diff --git a/app/models/project.rb b/app/models/project.rb index 4bc16771323bc312503efbea55385e630f6b8fbe..16a3f1ba649792da15886e97bd533d973a63a293 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -129,41 +129,15 @@ class Project < ApplicationRecord after_create :check_repository_absence! acts_as_ordered_taggable_on :topics - # The 'tag_list' alias and the 'has_many' associations are required during the 'tags -> topics' migration - # TODO: eliminate 'tag_list', 'topic_taggings' and 'tags' in the further process of the migration - # https://gitlab.com/gitlab-org/gitlab/-/issues/331081 + # The 'tag_list' alias and the 'tags' association are required during the 'tags -> topics' migration + # TODO: eliminate 'tag_list' and 'tags' in the further process of the migration + # https://gitlab.com/gitlab-org/gitlab/-/issues/328226 alias_attribute :tag_list, :topic_list - has_many :topic_taggings, -> { includes(:tag).order("#{ActsAsTaggableOn::Tagging.table_name}.id") }, - as: :taggable, - class_name: 'ActsAsTaggableOn::Tagging', - after_add: :dirtify_tag_list, - after_remove: :dirtify_tag_list - has_many :topics, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") }, - class_name: 'ActsAsTaggableOn::Tag', - through: :topic_taggings, - source: :tag has_many :tags, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") }, class_name: 'ActsAsTaggableOn::Tag', through: :topic_taggings, source: :tag - # Overwriting 'topic_list' and 'topic_list=' is necessary to ensure functionality during the background migration [1]. - # [1] https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61237 - # TODO: remove 'topic_list' and 'topic_list=' once the background migration is complete - # https://gitlab.com/gitlab-org/gitlab/-/issues/331081 - def topic_list - # Return both old topics (context 'tags') and new topics (context 'topics') - tag_list_on('tags') + tag_list_on('topics') - end - - def topic_list=(new_tags) - # Old topics with context 'tags' are added as new topics with context 'topics' - super(new_tags) - - # Remove old topics with context 'tags' - set_tag_list_on('tags', '') - end - attr_accessor :old_path_with_namespace attr_accessor :template_name attr_writer :pipeline_status diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8e606a00144fdc4f33ecb7d1c9723211bfb7472b..7b9eed7fb255793930d1d937d376bedf2c65e121 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -6888,31 +6888,6 @@ def enable_lfs expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3]) end end - - context 'intermediate state during background migration' do - before do - project.taggings.first.update!(context: 'tags') - project.instance_variable_set("@tag_list", nil) - project.reload - end - - it 'tag_list returns string array including old and new topics' do - expect(project.tag_list).to match_array(%w[topic1 topic2 topic3]) - end - - it 'tags returns old and new tag records' do - expect(project.tags.first.class.name).to eq('ActsAsTaggableOn::Tag') - expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3]) - expect(project.taggings.map(&:context)).to match_array(%w[tags topics topics]) - end - - it 'update tag_list adds new topics and removes old topics' do - project.update!(tag_list: 'topic1, topic2, topic3, topic4') - - expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3 topic4]) - expect(project.taggings.map(&:context)).to match_array(%w[topics topics topics topics]) - end - end end def finish_job(export_job)