debian-mirror-gitlab/spec/factories/notes.rb

213 lines
5.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
require_relative '../support/helpers/repo_helpers'
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2014-09-02 18:07:02 +05:30
factory :note do
2017-09-10 17:25:29 +05:30
project
2017-08-17 22:00:37 +05:30
note { generate(:title) }
2021-03-11 19:13:27 +05:30
author { project&.creator || association(:user) }
on_issue
2022-01-26 12:08:38 +05:30
updated_by { author }
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
factory :note_on_commit, traits: [:on_commit]
factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
factory :note_on_merge_request, traits: [:on_merge_request]
factory :note_on_project_snippet, traits: [:on_project_snippet]
2017-08-17 22:00:37 +05:30
factory :note_on_personal_snippet, traits: [:on_personal_snippet]
2020-05-24 23:13:21 +05:30
factory :note_on_design, traits: [:on_design]
2020-06-23 00:09:42 +05:30
factory :note_on_alert, traits: [:on_alert]
2015-09-11 14:41:01 +05:30
factory :system_note, traits: [:system]
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
factory :discussion_note, class: 'DiscussionNote'
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
factory :discussion_note_on_merge_request, traits: [:on_merge_request], class: 'DiscussionNote' do
2017-08-17 22:00:37 +05:30
association :project, :repository
end
2020-03-13 15:44:24 +05:30
factory :track_mr_picking_note, traits: [:on_merge_request, :system] do
association :system_note_metadata, action: 'cherry_pick'
commit_id { RepoHelpers.sample_commit.id }
end
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
factory :discussion_note_on_issue, traits: [:on_issue], class: 'DiscussionNote'
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
factory :discussion_note_on_commit, traits: [:on_commit], class: 'DiscussionNote'
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
factory :discussion_note_on_personal_snippet, traits: [:on_personal_snippet], class: 'DiscussionNote'
2018-03-27 19:54:05 +05:30
2020-04-22 19:07:51 +05:30
factory :discussion_note_on_project_snippet, traits: [:on_project_snippet], class: 'DiscussionNote'
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
factory :legacy_diff_note_on_commit, traits: [:on_commit, :legacy_diff_note], class: 'LegacyDiffNote'
factory :legacy_diff_note_on_merge_request, traits: [:on_merge_request, :legacy_diff_note], class: 'LegacyDiffNote' do
2017-08-17 22:00:37 +05:30
association :project, :repository
2019-12-21 20:55:43 +05:30
position { '' }
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
2020-03-13 15:44:24 +05:30
factory :diff_note_on_merge_request, traits: [:on_merge_request], class: 'DiffNote' do
2017-08-17 22:00:37 +05:30
association :project, :repository
transient do
2019-12-21 20:55:43 +05:30
line_number { 14 }
2017-08-17 22:00:37 +05:30
diff_refs { noteable.try(:diff_refs) }
end
2016-08-24 12:49:21 +05:30
position do
2021-03-11 19:13:27 +05:30
association(:text_diff_position,
2020-03-13 15:44:24 +05:30
file: "files/ruby/popen.rb",
old_line: nil,
new_line: line_number,
diff_refs: diff_refs)
2016-08-24 12:49:21 +05:30
end
2016-09-29 09:46:39 +05:30
2019-12-21 20:55:43 +05:30
trait :folded_position do
position do
2021-03-11 19:13:27 +05:30
association(:text_diff_position,
2020-03-13 15:44:24 +05:30
file: "files/ruby/popen.rb",
old_line: 1,
new_line: 1,
diff_refs: diff_refs)
2019-12-21 20:55:43 +05:30
end
end
2019-02-15 15:39:39 +05:30
factory :image_diff_note_on_merge_request do
position do
2021-03-11 19:13:27 +05:30
association(:image_diff_position,
2020-03-13 15:44:24 +05:30
file: "files/images/any_image.png",
diff_refs: diff_refs)
2019-02-15 15:39:39 +05:30
end
end
2016-08-24 12:49:21 +05:30
end
2020-03-13 15:44:24 +05:30
factory :diff_note_on_commit, traits: [:on_commit], class: 'DiffNote' do
2017-08-17 22:00:37 +05:30
association :project, :repository
2018-03-17 18:26:18 +05:30
transient do
2019-12-21 20:55:43 +05:30
line_number { 14 }
2018-03-17 18:26:18 +05:30
diff_refs { project.commit(commit_id).try(:diff_refs) }
end
2016-08-24 12:49:21 +05:30
position do
2021-03-11 19:13:27 +05:30
association(:text_diff_position,
2020-03-13 15:44:24 +05:30
file: "files/ruby/popen.rb",
2016-08-24 12:49:21 +05:30
old_line: nil,
2018-03-17 18:26:18 +05:30
new_line: line_number,
diff_refs: diff_refs
2016-08-24 12:49:21 +05:30
)
end
end
2020-05-24 23:13:21 +05:30
factory :diff_note_on_design, parent: :note, traits: [:on_design], class: 'DiffNote' do
2021-03-11 19:13:27 +05:30
position do
association(:image_diff_position,
file: noteable.full_path,
diff_refs: noteable.diff_refs)
end
2020-05-24 23:13:21 +05:30
end
2014-09-02 18:07:02 +05:30
trait :on_commit do
2017-08-17 22:00:37 +05:30
association :project, :repository
2019-12-21 20:55:43 +05:30
noteable { nil }
noteable_type { 'Commit' }
noteable_id { nil }
2018-12-05 23:21:45 +05:30
commit_id { RepoHelpers.sample_commit.id }
2014-09-02 18:07:02 +05:30
end
2016-08-24 12:49:21 +05:30
trait :legacy_diff_note do
2019-12-21 20:55:43 +05:30
line_code { "0_184_184" }
2014-09-02 18:07:02 +05:30
end
trait :on_issue do
2020-04-22 19:07:51 +05:30
noteable { association(:issue, project: project) }
2018-03-27 19:54:05 +05:30
end
trait :on_merge_request do
2020-04-22 19:07:51 +05:30
noteable { association(:merge_request, source_project: project) }
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
trait :on_project_snippet do
2020-04-22 19:07:51 +05:30
noteable { association(:project_snippet, project: project) }
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
trait :on_personal_snippet do
2020-04-22 19:07:51 +05:30
noteable { association(:personal_snippet) }
2019-12-21 20:55:43 +05:30
project { nil }
2017-08-17 22:00:37 +05:30
end
2020-05-24 23:13:21 +05:30
trait :on_design do
transient do
issue { association(:issue, project: project) }
end
noteable { association(:design, :with_file, issue: issue) }
after(:build) do |note|
next if note.project == note.noteable.project
# note validations require consistency between these two objects
note.project = note.noteable.project
end
end
2020-06-23 00:09:42 +05:30
trait :on_alert do
noteable { association(:alert_management_alert, project: project) }
end
trait :resolved do
resolved_at { Time.now }
resolved_by { association(:user) }
end
2015-09-11 14:41:01 +05:30
trait :system do
2019-12-21 20:55:43 +05:30
system { true }
2015-09-11 14:41:01 +05:30
end
2020-07-28 23:09:34 +05:30
trait :with_system_note_metadata do
system
system_note_metadata
end
2016-04-02 18:10:28 +05:30
trait :downvote do
2019-12-21 20:55:43 +05:30
note { "thumbsdown" }
2016-04-02 18:10:28 +05:30
end
trait :upvote do
2019-12-21 20:55:43 +05:30
note { "thumbsup" }
2016-04-02 18:10:28 +05:30
end
2014-09-02 18:07:02 +05:30
trait :with_attachment do
2018-11-08 19:23:39 +05:30
attachment { fixture_file_upload("spec/fixtures/dk.png", "image/png") }
2017-08-17 22:00:37 +05:30
end
trait :with_svg_attachment do
2018-11-08 19:23:39 +05:30
attachment { fixture_file_upload("spec/fixtures/unsanitized.svg", "image/svg+xml") }
2017-08-17 22:00:37 +05:30
end
2020-01-01 13:55:28 +05:30
trait :with_pdf_attachment do
attachment { fixture_file_upload("spec/fixtures/git-cheat-sheet.pdf", "application/pdf") }
end
2020-04-08 14:13:33 +05:30
trait :confidential do
confidential { true }
end
2020-06-23 00:09:42 +05:30
trait :with_review do
review
end
2017-08-17 22:00:37 +05:30
transient do
2019-12-21 20:55:43 +05:30
in_reply_to { nil }
2017-08-17 22:00:37 +05:30
end
before(:create) do |note, evaluator|
discussion = evaluator.in_reply_to
next unless discussion
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
discussion = discussion.to_discussion if discussion.is_a?(Note)
next unless discussion
note.assign_attributes(discussion.reply_attributes.merge(project: discussion.project))
2014-09-02 18:07:02 +05:30
end
end
end