2020-03-13 15:44:24 +05:30
|
|
|
# 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 }
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
initialize_with { new(**attributes) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
trait :moved do
|
|
|
|
new_path { 'path/to/new.file' }
|
|
|
|
end
|
|
|
|
|
|
|
|
factory :text_diff_position do
|
|
|
|
position_type { 'text' }
|
|
|
|
old_line { 10 }
|
|
|
|
new_line { 10 }
|
2020-04-22 19:07:51 +05:30
|
|
|
line_range { nil }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
trait :added do
|
|
|
|
old_line { nil }
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
trait :multi_line do
|
|
|
|
line_range do
|
|
|
|
{
|
|
|
|
start_line_code: Gitlab::Git.diff_line_code(file, 10, 10),
|
|
|
|
end_line_code: Gitlab::Git.diff_line_code(file, 12, 13)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
factory :image_diff_position do
|
|
|
|
position_type { 'image' }
|
|
|
|
x { 1 }
|
2020-11-24 15:15:51 +05:30
|
|
|
# Fix:
|
|
|
|
# NoMethodError: undefined method `end_line=' for nil:NilClass
|
|
|
|
# from /usr/lib/ruby/2.6.0/psych/tree_builder.rb:133:in `set_end_location'
|
|
|
|
add_attribute(:y) { 1 }
|
2020-03-13 15:44:24 +05:30
|
|
|
width { 10 }
|
|
|
|
height { 10 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|