BigW Consortium Gitlab

notes.rb 2.87 KB
Newer Older
1 2
require_relative '../support/repo_helpers'

3 4
include ActionDispatch::TestProcess

5 6
FactoryGirl.define do
  factory :note do
7
    project factory: :empty_project
8 9
    note "Note"
    author
Grzegorz Bizon committed
10
    on_issue
11

12 13 14 15
    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]
16
    factory :note_on_personal_snippet,   traits: [:on_personal_snippet]
17
    factory :system_note,                traits: [:system]
18

19 20 21 22 23 24 25
    factory :legacy_diff_note_on_commit, traits: [:on_commit, :legacy_diff_note], class: LegacyDiffNote do
      association :project, :repository
    end

    factory :legacy_diff_note_on_merge_request, traits: [:on_merge_request, :legacy_diff_note], class: LegacyDiffNote do
      association :project, :repository
    end
Douwe Maan committed
26 27

    factory :diff_note_on_merge_request, traits: [:on_merge_request], class: DiffNote do
28
      association :project, :repository
Douwe Maan committed
29 30 31 32 33 34 35 36 37
      position do
        Gitlab::Diff::Position.new(
          old_path: "files/ruby/popen.rb",
          new_path: "files/ruby/popen.rb",
          old_line: nil,
          new_line: 14,
          diff_refs: noteable.diff_refs
        )
      end
38 39 40 41 42

      trait :resolved do
        resolved_at { Time.now }
        resolved_by { create(:user) }
      end
Douwe Maan committed
43 44 45
    end

    factory :diff_note_on_commit, traits: [:on_commit], class: DiffNote do
46
      association :project, :repository
Douwe Maan committed
47 48 49 50 51 52 53 54 55 56 57
      position do
        Gitlab::Diff::Position.new(
          old_path: "files/ruby/popen.rb",
          new_path: "files/ruby/popen.rb",
          old_line: nil,
          new_line: 14,
          diff_refs: project.commit(commit_id).try(:diff_refs)
        )
      end
    end

58
    trait :on_commit do
59
      association :project, :repository
60
      noteable nil
Grzegorz Bizon committed
61
      noteable_type 'Commit'
Douwe Maan committed
62
      noteable_id nil
63 64 65
      commit_id RepoHelpers.sample_commit.id
    end

Douwe Maan committed
66
    trait :legacy_diff_note do
67 68 69
      line_code "0_184_184"
    end

70 71
    trait :on_issue do
      noteable { create(:issue, project: project) }
72 73 74
    end

    trait :on_merge_request do
Grzegorz Bizon committed
75
      noteable { create(:merge_request, source_project: project) }
76 77
    end

78
    trait :on_project_snippet do
79
      noteable { create(:project_snippet, project: project) }
80 81
    end

82 83 84 85 86
    trait :on_personal_snippet do
      noteable { create(:personal_snippet) }
      project nil
    end

87 88 89 90
    trait :system do
      system true
    end

91 92 93 94 95 96 97 98
    trait :downvote do
      note "thumbsdown"
    end

    trait :upvote do
      note "thumbsup"
    end

99
    trait :with_attachment do
100 101 102 103 104
      attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png") }
    end

    trait :with_svg_attachment do
      attachment { fixture_file_upload(Rails.root + "spec/fixtures/unsanitized.svg", "image/svg+xml") }
105 106 107
    end
  end
end