Commit e58ee359 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Fix import of snippets with `award_emoji`

Snippets having `award_emoji` failed being imported.
It happened because `award_emoji` model validation failed.
It also prevented other snippets being imported as the process silently
failed mid-iteration.
parent 39e3f64d
......@@ -6,11 +6,14 @@ class AwardEmoji < ApplicationRecord
include Participable
include GhostUser
include Importable
belongs_to :awardable, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
belongs_to :user
validates :awardable, :user, presence: true
validates :user, presence: true
validates :awardable, presence: true, unless: [:importing?]
validates :name, presence: true, inclusion: { in: Gitlab::Emoji.emojis_names }
validates :name, uniqueness: { scope: [:user, :awardable_type, :awardable_id] }, unless: :ghost_user?
......
......@@ -2260,7 +2260,41 @@
]
}
],
"snippets": [],
"snippets": [
{
"id": 1,
"title": "Test snippet title",
"content": "x = 1",
"author_id": 1,
"project_id": 1,
"created_at": "2019-11-05T15:06:06.579Z",
"updated_at": "2019-11-05T15:06:06.579Z",
"file_name": "",
"visibility_level": 20,
"description": "Test snippet description",
"award_emoji": [
{
"id": 1,
"name": "thumbsup",
"user_id": 1,
"awardable_type": "Snippet",
"awardable_id": 1,
"created_at": "2019-11-05T15:37:21.287Z",
"updated_at": "2019-11-05T15:37:21.287Z"
},
{
"id": 2,
"name": "coffee",
"user_id": 1,
"awardable_type": "Snippet",
"awardable_id": 1,
"created_at": "2019-11-05T15:37:24.645Z",
"updated_at": "2019-11-05T15:37:24.645Z"
}
],
"notes": []
}
],
"releases": [],
"project_members": [
{
......
......@@ -210,6 +210,17 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(@project.project_badges.count).to eq(2)
end
it 'has snippets' do
expect(@project.snippets.count).to eq(1)
end
it 'has award emoji for a snippet' do
award_emoji = @project.snippets.first.award_emoji
expect(award_emoji.count).to eq(2)
expect(award_emoji.map(&:name)).to match_array(%w[thumbsup coffee])
end
it 'restores the correct service' do
expect(CustomIssueTrackerService.first).not_to be_nil
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