2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-29 05:47:54 -04:00
|
|
|
require_relative '../support/helpers/repo_helpers'
|
2014-08-01 10:54:44 -04:00
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
include ActionDispatch::TestProcess
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2014-08-01 10:54:44 -04:00
|
|
|
factory :note do
|
2017-08-02 15:55:11 -04:00
|
|
|
project
|
2017-04-27 06:41:26 -04:00
|
|
|
note { generate(:title) }
|
2017-08-04 13:14:04 -04:00
|
|
|
author { project&.creator || create(:user) }
|
2016-05-18 13:38:52 -04:00
|
|
|
on_issue
|
2014-08-01 10:54:44 -04:00
|
|
|
|
2015-04-30 23:16:19 -04:00
|
|
|
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-01-05 08:36:06 -05:00
|
|
|
factory :note_on_personal_snippet, traits: [:on_personal_snippet]
|
2015-04-30 23:16:19 -04:00
|
|
|
factory :system_note, traits: [:system]
|
2014-08-01 10:54:44 -04:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note, class: 'DiscussionNote'
|
2018-02-28 02:48:23 -05:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note_on_merge_request, traits: [:on_merge_request], class: 'DiscussionNote' do
|
2017-03-09 20:29:11 -05:00
|
|
|
association :project, :repository
|
2017-03-13 18:13:12 -04:00
|
|
|
|
2017-03-09 20:29:11 -05:00
|
|
|
trait :resolved do
|
|
|
|
resolved_at { Time.now }
|
|
|
|
resolved_by { create(:user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-22 16:08:48 -05:00
|
|
|
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
|
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note_on_issue, traits: [:on_issue], class: 'DiscussionNote'
|
2017-03-17 15:25:52 -04:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note_on_commit, traits: [:on_commit], class: 'DiscussionNote'
|
2017-03-17 15:25:52 -04:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note_on_personal_snippet, traits: [:on_personal_snippet], class: 'DiscussionNote'
|
2017-05-03 04:48:01 -04:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :discussion_note_on_snippet, traits: [:on_snippet], class: 'DiscussionNote'
|
2018-02-28 02:48:23 -05:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :legacy_diff_note_on_commit, traits: [:on_commit, :legacy_diff_note], class: 'LegacyDiffNote'
|
2017-01-25 14:52:12 -05:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :legacy_diff_note_on_merge_request, traits: [:on_merge_request, :legacy_diff_note], class: 'LegacyDiffNote' do
|
2017-01-25 14:52:12 -05:00
|
|
|
association :project, :repository
|
2019-10-01 20:06:26 -04:00
|
|
|
position { '' }
|
2017-01-25 14:52:12 -05:00
|
|
|
end
|
2016-06-20 13:20:39 -04:00
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :diff_note_on_merge_request, traits: [:on_merge_request], class: 'DiffNote' do
|
2017-01-25 14:52:12 -05:00
|
|
|
association :project, :repository
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
line_number { 14 }
|
2017-04-10 16:17:47 -04:00
|
|
|
diff_refs { noteable.try(:diff_refs) }
|
2016-12-22 07:31:12 -05:00
|
|
|
end
|
|
|
|
|
2016-06-20 13:20:39 -04:00
|
|
|
position do
|
2020-02-17 13:09:00 -05:00
|
|
|
build(:text_diff_position,
|
|
|
|
file: "files/ruby/popen.rb",
|
|
|
|
old_line: nil,
|
|
|
|
new_line: line_number,
|
|
|
|
diff_refs: diff_refs)
|
2016-06-20 13:20:39 -04:00
|
|
|
end
|
2016-09-02 16:29:47 -04:00
|
|
|
|
2019-10-09 20:06:44 -04:00
|
|
|
trait :folded_position do
|
|
|
|
position do
|
2020-02-17 13:09:00 -05:00
|
|
|
build(:text_diff_position,
|
|
|
|
file: "files/ruby/popen.rb",
|
|
|
|
old_line: 1,
|
|
|
|
new_line: 1,
|
|
|
|
diff_refs: diff_refs)
|
2019-10-09 20:06:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-02 16:29:47 -04:00
|
|
|
trait :resolved do
|
|
|
|
resolved_at { Time.now }
|
|
|
|
resolved_by { create(:user) }
|
|
|
|
end
|
2018-12-20 09:22:58 -05:00
|
|
|
|
|
|
|
factory :image_diff_note_on_merge_request do
|
|
|
|
position do
|
2020-02-17 13:09:00 -05:00
|
|
|
build(:image_diff_position,
|
|
|
|
file: "files/images/any_image.png",
|
|
|
|
diff_refs: diff_refs)
|
2018-12-20 09:22:58 -05:00
|
|
|
end
|
|
|
|
end
|
2016-06-20 13:20:39 -04:00
|
|
|
end
|
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :diff_note_on_commit, traits: [:on_commit], class: 'DiffNote' do
|
2017-01-24 20:30:56 -05:00
|
|
|
association :project, :repository
|
2017-12-01 14:08:30 -05:00
|
|
|
|
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
line_number { 14 }
|
2017-12-01 14:08:30 -05:00
|
|
|
diff_refs { project.commit(commit_id).try(:diff_refs) }
|
|
|
|
end
|
|
|
|
|
2016-06-20 13:20:39 -04:00
|
|
|
position do
|
2020-02-17 13:09:00 -05:00
|
|
|
build(:text_diff_position,
|
|
|
|
file: "files/ruby/popen.rb",
|
2016-06-20 13:20:39 -04:00
|
|
|
old_line: nil,
|
2017-12-01 14:08:30 -05:00
|
|
|
new_line: line_number,
|
|
|
|
diff_refs: diff_refs
|
2016-06-20 13:20:39 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-01 10:54:44 -04:00
|
|
|
trait :on_commit do
|
2017-01-25 14:52:12 -05:00
|
|
|
association :project, :repository
|
2019-10-01 20:06:26 -04:00
|
|
|
noteable { nil }
|
|
|
|
noteable_type { 'Commit' }
|
|
|
|
noteable_id { nil }
|
2018-09-20 13:02:36 -04:00
|
|
|
commit_id { RepoHelpers.sample_commit.id }
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
|
|
|
|
2016-06-20 13:20:39 -04:00
|
|
|
trait :legacy_diff_note do
|
2019-10-01 20:06:26 -04:00
|
|
|
line_code { "0_184_184" }
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
|
|
|
|
2016-05-04 05:17:16 -04:00
|
|
|
trait :on_issue do
|
|
|
|
noteable { create(:issue, project: project) }
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
|
|
|
|
2018-02-28 02:48:23 -05:00
|
|
|
trait :on_snippet do
|
|
|
|
noteable { create(:snippet, project: project) }
|
|
|
|
end
|
|
|
|
|
2014-08-01 10:54:44 -04:00
|
|
|
trait :on_merge_request do
|
2016-05-18 12:21:14 -04:00
|
|
|
noteable { create(:merge_request, source_project: project) }
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
trait :on_project_snippet do
|
2016-12-08 20:56:31 -05:00
|
|
|
noteable { create(:project_snippet, project: project) }
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
2017-01-05 08:36:06 -05:00
|
|
|
trait :on_personal_snippet do
|
|
|
|
noteable { create(:personal_snippet) }
|
2019-10-01 20:06:26 -04:00
|
|
|
project { nil }
|
2017-01-05 08:36:06 -05:00
|
|
|
end
|
|
|
|
|
2015-04-30 23:16:19 -04:00
|
|
|
trait :system do
|
2019-10-01 20:06:26 -04:00
|
|
|
system { true }
|
2015-04-30 23:16:19 -04:00
|
|
|
end
|
|
|
|
|
2016-02-17 08:32:02 -05:00
|
|
|
trait :downvote do
|
2019-10-01 20:06:26 -04:00
|
|
|
note { "thumbsdown" }
|
2016-02-17 08:32:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :upvote do
|
2019-10-01 20:06:26 -04:00
|
|
|
note { "thumbsup" }
|
2016-02-17 08:32:02 -05:00
|
|
|
end
|
|
|
|
|
2014-08-01 10:54:44 -04:00
|
|
|
trait :with_attachment do
|
2018-06-05 17:18:06 -04:00
|
|
|
attachment { fixture_file_upload("spec/fixtures/dk.png", "image/png") }
|
2017-02-13 17:42:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_svg_attachment do
|
2018-06-05 17:18:06 -04:00
|
|
|
attachment { fixture_file_upload("spec/fixtures/unsanitized.svg", "image/svg+xml") }
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
2017-03-13 18:13:12 -04:00
|
|
|
|
2019-12-16 13:08:22 -05:00
|
|
|
trait :with_pdf_attachment do
|
|
|
|
attachment { fixture_file_upload("spec/fixtures/git-cheat-sheet.pdf", "application/pdf") }
|
|
|
|
end
|
|
|
|
|
2017-03-13 18:13:12 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
in_reply_to { nil }
|
2017-03-13 18:13:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before(:create) do |note, evaluator|
|
|
|
|
discussion = evaluator.in_reply_to
|
|
|
|
next unless discussion
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2017-03-13 18:13:12 -04:00
|
|
|
discussion = discussion.to_discussion if discussion.is_a?(Note)
|
|
|
|
next unless discussion
|
2017-03-17 15:25:52 -04:00
|
|
|
|
|
|
|
note.assign_attributes(discussion.reply_attributes.merge(project: discussion.project))
|
2017-03-13 18:13:12 -04:00
|
|
|
end
|
2014-08-01 10:54:44 -04:00
|
|
|
end
|
|
|
|
end
|