BigW Consortium Gitlab

Commit a97ff8aa by Alejandro Rodríguez

Add a factory for `Gitaly::GitCommit`s

parent 171714c9
FactoryGirl.define do
sequence(:gitaly_commit_id) { Digest::SHA1.hexdigest(Time.now.to_f.to_s) }
factory :gitaly_commit, class: Gitaly::GitCommit do
skip_create
id { generate(:gitaly_commit_id) }
parent_ids do
ids = [generate(:gitaly_commit_id), generate(:gitaly_commit_id)]
Google::Protobuf::RepeatedField.new(:string, ids)
end
subject { "My commit" }
body { subject + "\nMy body" }
author { build(:gitaly_commit_author) }
committer { build(:gitaly_commit_author) }
end
end
FactoryGirl.define do
factory :gitaly_commit_author, class: Gitaly::CommitAuthor do
skip_create
name { generate(:name) }
email { generate(:email) }
date { Google::Protobuf::Timestamp.new(seconds: Time.now.to_i) }
end
end
......@@ -65,34 +65,12 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
describe "Commit info from gitaly commit" do
let(:id) { 'f00' }
let(:parent_ids) { %w(b45 b46) }
let(:subject) { "My commit".force_encoding('ASCII-8BIT') }
let(:body) { subject + "My body".force_encoding('ASCII-8BIT') }
let(:committer) do
Gitaly::CommitAuthor.new(
name: generate(:name),
email: generate(:email),
date: Google::Protobuf::Timestamp.new(seconds: 123)
)
end
let(:author) do
Gitaly::CommitAuthor.new(
name: generate(:name),
email: generate(:email),
date: Google::Protobuf::Timestamp.new(seconds: 456)
)
end
let(:gitaly_commit) do
Gitaly::GitCommit.new(
id: id,
subject: subject,
body: body,
author: author,
committer: committer,
parent_ids: parent_ids
)
end
let(:gitaly_commit) { build(:gitaly_commit, subject: subject, body: body) }
let(:id) { gitaly_commit.id }
let(:committer) { gitaly_commit.committer }
let(:author) { gitaly_commit.author }
let(:commit) { described_class.new(repository, gitaly_commit) }
it { expect(commit.short_id).to eq(id[0..10]) }
......@@ -104,7 +82,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
it { expect(commit.author_name).to eq(author.name) }
it { expect(commit.committer_name).to eq(committer.name) }
it { expect(commit.committer_email).to eq(committer.email) }
it { expect(commit.parent_ids).to eq(parent_ids) }
it { expect(commit.parent_ids).to eq(gitaly_commit.parent_ids) }
context 'no body' do
let(:body) { "".force_encoding('ASCII-8BIT') }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment