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