Commit 84e6b80b authored by Rémy Coutable's avatar Rémy Coutable Committed by Ruben Davila

Merge branch 'add_spec_for_committer_hash' into 'master'

Add spec covering 'committer_hash'

Adds a missing spec from changes added in !5822

See merge request !6433
parent b9e02703
......@@ -29,6 +29,7 @@ v 8.12.0 (unreleased)
- Instructions for enabling Git packfile bitmaps !6104
- Use Search::GlobalService.new in the `GET /projects/search/:query` endpoint
- Fix long comments in diffs messing with table width
- Add spec covering 'Gitlab::Git::committer_hash' !6433 (dandunckelman)
- Fix pagination on user snippets page
- Run CI builds with the permissions of users !5735
- Fix sorting of issues in API
......
......@@ -840,7 +840,7 @@ class Repository
def get_committer_and_author(user, email: nil, name: nil)
committer = user_to_committer(user)
author = name && email ? Gitlab::Git::committer_hash(email: email, name: name) : committer
author = Gitlab::Git::committer_hash(email: email, name: name) || committer
{
author: author,
......
......@@ -19,6 +19,8 @@ module Gitlab
end
def committer_hash(email:, name:)
return if email.nil? || name.nil?
{
email: email,
name: name,
......
require 'spec_helper'
describe Gitlab::Git, lib: true do
let(:committer_email) { FFaker::Internet.email }
# I have to remove periods from the end of the name
# This happened when the user's name had a suffix (i.e. "Sr.")
# This seems to be what git does under the hood. For example, this commit:
#
# $ git commit --author='Foo Sr. <foo@example.com>' -m 'Where's my trailing period?'
#
# results in this:
#
# $ git show --pretty
# ...
# Author: Foo Sr <foo@example.com>
# ...
let(:committer_name) { FFaker::Name.name.chomp("\.") }
describe 'committer_hash' do
it "returns a hash containing the given email and name" do
committer_hash = Gitlab::Git::committer_hash(email: committer_email, name: committer_name)
expect(committer_hash[:email]).to eq(committer_email)
expect(committer_hash[:name]).to eq(committer_name)
expect(committer_hash[:time]).to be_a(Time)
end
context 'when email is nil' do
it "returns nil" do
committer_hash = Gitlab::Git::committer_hash(email: nil, name: committer_name)
expect(committer_hash).to be_nil
end
end
context 'when name is nil' do
it "returns nil" do
committer_hash = Gitlab::Git::committer_hash(email: committer_email, name: nil)
expect(committer_hash).to be_nil
end
end
end
end
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