BigW Consortium Gitlab

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

3 4
include ActionDispatch::TestProcess

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

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

Douwe Maan committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    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

    factory :diff_note_on_merge_request, traits: [:on_merge_request], class: DiffNote do
      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
    end

    factory :diff_note_on_commit, traits: [:on_commit], class: DiffNote do
      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

45
    trait :on_commit do
46
      noteable nil
Grzegorz Bizon committed
47
      noteable_type 'Commit'
Douwe Maan committed
48
      noteable_id nil
49 50 51
      commit_id RepoHelpers.sample_commit.id
    end

Douwe Maan committed
52
    trait :legacy_diff_note do
53 54 55
      line_code "0_184_184"
    end

56 57
    trait :on_issue do
      noteable { create(:issue, project: project) }
58 59 60
    end

    trait :on_merge_request do
Grzegorz Bizon committed
61
      noteable { create(:merge_request, source_project: project) }
62 63
    end

64
    trait :on_project_snippet do
65
      noteable { create(:snippet, project: project) }
66 67
    end

68 69 70 71
    trait :system do
      system true
    end

72 73 74 75 76 77 78 79
    trait :downvote do
      note "thumbsdown"
    end

    trait :upvote do
      note "thumbsup"
    end

80 81 82 83 84
    trait :with_attachment do
      attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "`/png") }
    end
  end
end