summaryrefslogtreecommitdiff
path: root/spec/factories
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-17 18:09:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-17 18:09:00 +0000
commiteb1f5a3e087b7d6a3e85f2724b5a475cc9d9d37d (patch)
treed572a6d931152ae0dd10427237f5811893438552 /spec/factories
parentb304a72312465ed4c0a568ee6a6ea5e97f705c9b (diff)
downloadgitlab-ce-eb1f5a3e087b7d6a3e85f2724b5a475cc9d9d37d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/factories')
-rw-r--r--spec/factories/diff_position.rb51
-rw-r--r--spec/factories/notes.rb42
2 files changed, 66 insertions, 27 deletions
diff --git a/spec/factories/diff_position.rb b/spec/factories/diff_position.rb
new file mode 100644
index 00000000000..a43c5afdff4
--- /dev/null
+++ b/spec/factories/diff_position.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :diff_position, class: 'Gitlab::Diff::Position' do
+ skip_create # non-model factories (i.e. without #save)
+
+ transient do
+ file { 'path/to/file' }
+
+ # Allow diff to be passed as a single object.
+ diff_refs do
+ ::Gitlab::Diff::DiffRefs.new(
+ base_sha: Digest::SHA1.hexdigest(SecureRandom.hex),
+ head_sha: Digest::SHA1.hexdigest(SecureRandom.hex),
+ start_sha: Digest::SHA1.hexdigest(SecureRandom.hex)
+ )
+ end
+ end
+
+ old_path { file }
+ new_path { file }
+
+ base_sha { diff_refs&.base_sha }
+ head_sha { diff_refs&.head_sha }
+ start_sha { diff_refs&.start_sha }
+
+ initialize_with { new(attributes) }
+
+ trait :moved do
+ new_path { 'path/to/new.file' }
+ end
+
+ factory :text_diff_position do
+ position_type { 'text' }
+ old_line { 10 }
+ new_line { 10 }
+
+ trait :added do
+ old_line { nil }
+ end
+ end
+
+ factory :image_diff_position do
+ position_type { 'image' }
+ x { 1 }
+ y { 1 }
+ width { 10 }
+ height { 10 }
+ end
+ end
+end
diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb
index ec89a5904f5..848590efabc 100644
--- a/spec/factories/notes.rb
+++ b/spec/factories/notes.rb
@@ -58,24 +58,20 @@ FactoryBot.define do
end
position do
- Gitlab::Diff::Position.new(
- old_path: "files/ruby/popen.rb",
- new_path: "files/ruby/popen.rb",
- old_line: nil,
- new_line: line_number,
- diff_refs: diff_refs
- )
+ build(:text_diff_position,
+ file: "files/ruby/popen.rb",
+ old_line: nil,
+ new_line: line_number,
+ diff_refs: diff_refs)
end
trait :folded_position do
position do
- Gitlab::Diff::Position.new(
- old_path: "files/ruby/popen.rb",
- new_path: "files/ruby/popen.rb",
- old_line: 1,
- new_line: 1,
- diff_refs: diff_refs
- )
+ build(:text_diff_position,
+ file: "files/ruby/popen.rb",
+ old_line: 1,
+ new_line: 1,
+ diff_refs: diff_refs)
end
end
@@ -86,16 +82,9 @@ FactoryBot.define do
factory :image_diff_note_on_merge_request do
position do
- Gitlab::Diff::Position.new(
- old_path: "files/images/any_image.png",
- new_path: "files/images/any_image.png",
- width: 10,
- height: 10,
- x: 1,
- y: 1,
- diff_refs: diff_refs,
- position_type: "image"
- )
+ build(:image_diff_position,
+ file: "files/images/any_image.png",
+ diff_refs: diff_refs)
end
end
end
@@ -109,9 +98,8 @@ FactoryBot.define do
end
position do
- Gitlab::Diff::Position.new(
- old_path: "files/ruby/popen.rb",
- new_path: "files/ruby/popen.rb",
+ build(:text_diff_position,
+ file: "files/ruby/popen.rb",
old_line: nil,
new_line: line_number,
diff_refs: diff_refs