2019-07-25 05:11:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-29 09:47:54 +00:00
|
|
|
require_relative '../support/helpers/repo_helpers'
|
2016-04-13 09:25:42 +00:00
|
|
|
|
2017-12-14 00:13:44 +00:00
|
|
|
FactoryBot.define do
|
2016-04-13 09:25:42 +00:00
|
|
|
factory :commit do
|
2017-11-18 14:06:55 +00:00
|
|
|
transient do
|
2019-10-02 00:06:26 +00:00
|
|
|
author { nil }
|
2017-11-18 14:06:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
git_commit do
|
|
|
|
commit = RepoHelpers.sample_commit
|
|
|
|
|
|
|
|
if author
|
|
|
|
commit.author_email = author.email
|
|
|
|
commit.author_name = author.name
|
|
|
|
end
|
|
|
|
|
|
|
|
commit
|
|
|
|
end
|
2019-02-06 12:33:11 +00:00
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
project
|
2016-04-13 09:25:42 +00:00
|
|
|
|
2019-02-06 12:33:11 +00:00
|
|
|
skip_create # Commits cannot be persisted
|
|
|
|
|
2016-04-13 09:25:42 +00:00
|
|
|
initialize_with do
|
|
|
|
new(git_commit, project)
|
|
|
|
end
|
2017-01-18 10:38:59 +00:00
|
|
|
|
2017-11-18 14:06:55 +00:00
|
|
|
after(:build) do |commit, evaluator|
|
2022-05-26 06:08:37 +00:00
|
|
|
author = evaluator.author || build_stubbed(:author)
|
|
|
|
stub_method(commit, :author) { author }
|
|
|
|
stub_method(commit, :parent_ids) { [] }
|
2019-02-06 12:33:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :merge_commit do
|
|
|
|
after(:build) do |commit|
|
2022-05-26 06:08:37 +00:00
|
|
|
stub_method(commit, :parent_ids) { Array.new(2) { SecureRandom.hex(20) } }
|
2019-02-06 12:33:11 +00:00
|
|
|
end
|
2017-07-17 19:26:41 +00:00
|
|
|
end
|
|
|
|
|
2017-01-18 10:38:59 +00:00
|
|
|
trait :without_author do
|
2017-07-17 19:26:41 +00:00
|
|
|
after(:build) do |commit|
|
2022-05-26 06:08:37 +00:00
|
|
|
stub_method(commit, :author) { nil }
|
2017-07-17 19:26:41 +00:00
|
|
|
end
|
2017-01-18 10:38:59 +00:00
|
|
|
end
|
2016-04-13 09:25:42 +00:00
|
|
|
end
|
|
|
|
end
|