Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Merge e2c8ac7 into 2845659
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Suschlik committed May 14, 2013
2 parents 2845659 + e2c8ac7 commit dbc2ef3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
30 changes: 14 additions & 16 deletions lib/gitlab_git/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
module Gitlab
module Git
class Commit
attr_accessor :raw_commit, :head, :refs,
:id, :authored_date, :committed_date, :message,
:author_name, :author_email, :parent_ids,
:committer_name, :committer_email
attr_accessor :raw_commit, :head, :refs

SERIALIZE_KEYS = [
:id, :message, :parent_ids,
:authored_date, :author_name, :author_email,
:committed_date, :committer_name, :committer_email
]
attr_accessor *SERIALIZE_KEYS

def initialize(raw_commit, head = nil)
raise "Nil as raw commit passed" unless raw_commit
Expand All @@ -21,10 +25,6 @@ def initialize(raw_commit, head = nil)
@head = head
end

def serialize_keys
@serialize_keys ||= %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids).map(&:to_sym)
end

def sha
id
end
Expand Down Expand Up @@ -78,15 +78,9 @@ def no_commit_message
end

def to_hash
hash = {}

keys = serialize_keys

keys.each do |key|
serialize_keys.map.with_object({}) do |key, hash|
hash[key] = send(key)
end

hash
end

def date
Expand Down Expand Up @@ -132,9 +126,13 @@ def init_from_hash(hash)
raw_commit = hash.symbolize_keys

serialize_keys.each do |key|
send(:"#{key}=", raw_commit[key.to_sym])
send("#{key}=", raw_commit[key])
end
end

def serialize_keys
SERIALIZE_KEYS
end
end
end
end
26 changes: 25 additions & 1 deletion spec/commit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,39 @@
name: 'John Smith'
)

@tree = double

@parents = [ double(id: "8716fc78f3c65bbf7bcf7b574febd583bc5d2812") ]

@raw_commit = double(
id: "bcf03b5de6abcf03b5de6c",
author: @author,
committer: @committer,
committed_date: Date.today.prev_day,
authored_date: Date.today.prev_day,
parents: [],
tree: @tree,
parents: @parents,
message: 'Refactoring specs'
)

@commit = Gitlab::Git::Commit.new(@raw_commit)
end

it { @commit.short_id.should == "bcf03b5de6a" }
it { @commit.id.should == @raw_commit.id }
it { @commit.sha.should == @raw_commit.id }
it { @commit.safe_message.should == @raw_commit.message }
it { @commit.created_at.should == @raw_commit.committed_date }
it { @commit.date.should == @raw_commit.committed_date }
it { @commit.author_email.should == @author.email }
it { @commit.author_name.should == @author.name }
it { @commit.committer_name.should == @committer.name }
it { @commit.committer_email.should == @committer.email }
it { @commit.different_committer?.should be_true }
it { @commit.parents.should == @parents }
it { @commit.parent_id.should == @parents.first.id }
it { @commit.no_commit_message.should == "--no commit message" }
it { @commit.tree.should == @tree }
end

describe :init_from_hash do
Expand All @@ -61,6 +73,10 @@
it { should include 'diff --git a/app/assets/stylesheets/tree.scss b/app/assets/stylesheets/tree.scss'}
end

describe :has_zero_stats? do
it { commit.has_zero_stats?.should == false }
end

describe :to_patch do
subject { commit.to_patch }

Expand All @@ -76,6 +92,14 @@
its(:keys) { should =~ sample_commit_hash.keys }
end

describe :diffs do
subject { commit.diffs }

it { should be_kind_of Array }
its(:size) { should eq(2) }
its(:first) { should be_kind_of Gitlab::Git::Diff }
end

def sample_commit_hash
{
author_email: "dmitriy.zaporozhets@gmail.com",
Expand Down

0 comments on commit dbc2ef3

Please sign in to comment.