Skip to content

Commit

Permalink
added tests and support for #git#trees and #git#commits
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhryan committed Apr 7, 2012
1 parent 2a330a2 commit 02ee577
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 11 deletions.
27 changes: 27 additions & 0 deletions lib/ghee/api/git_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ module API
#
module Repos

# The Commits module handles repo commit endpoints
#
module Commits
class Proxy < ::Ghee::ResourceProxy
include Ghee::CUD
end
end

# The Git module handles all of the raw git data endpoints
#
module Git
Expand All @@ -30,6 +38,14 @@ class Proxy < ::Ghee::ResourceProxy
end
end

# The Trees module handles all of the commit methods
#
module Trees
class Proxy < ::Ghee::ResourceProxy
include Ghee::CUD
end
end

class Proxy < ::Ghee::ResourceProxy

# Get the blob by a provided sha
Expand All @@ -47,6 +63,17 @@ def commits(sha=nil, params={})
prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/commits/#{sha}" : "#{path_prefix}/commits"
Ghee::API::Repos::Git::Commits::Proxy.new(connection, prefix, params)
end

def refs(ref=nil)

end

# Get tree by a given sha
#
def trees(sha, params={})
prefix = "#{path_prefix}/trees/#{sha}"
Ghee::API::Repos::Git::Trees::Proxy.new(connection, prefix, params)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/ghee/api/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def hooks(number=nil, params={})
Ghee::API::Repos::Hooks::Proxy.new(connection, prefix, params)
end

def commits(sha=nil, params={})
params = sha if sha.is_a?Hash
prefix = (!sha.is_a?(Hash) and sha) ? "#{path_prefix}/commits/#{sha}" : "#{path_prefix}/commits"
Ghee::API::Repos::Commits::Proxy.new(connection, prefix, params)
end

def git
Ghee::API::Repos::Git::Proxy.new(connection, "#{path_prefix}/git")
end
Expand Down
49 changes: 38 additions & 11 deletions spec/ghee/api/gitdata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Ghee::API::Repos::Git do
subject { Ghee.new(GH_AUTH) }
subject { Ghee.new(GH_AUTH).repos(GH_USER,GH_REPO) }

def should_be_a_blob(blob)
blob["content"].should_not be_nil
Expand All @@ -10,14 +10,29 @@ def should_be_a_blob(blob)

def should_be_a_commit(commit)
# assert its a commit
commit["sha"].should_not be_nil
end

def should_be_a_tree(tree)
tree["sha"].should_not be_nil
tree["tree"].size.should > 0
end

describe "#repos()#commits" do
it "should return an array of commits" do
VCR.use_cassette "#repos()#commits" do
commits = subject.commits
commits.size.should > 0
end
end
end

describe "#repos(login,name)#git" do
describe "#blobs" do
context "with a test blob" do
before :all do
VCR.use_cassette "repos()#git#blobs#create" do
@test_blob = subject.repos(GH_USER, GH_REPO).git.blobs.create({
@test_blob = subject.git.blobs.create({
:content => "Oh hello!",
:encoding => "utf-8"
});
Expand All @@ -28,25 +43,37 @@ def should_be_a_commit(commit)

it "should return a blob" do
VCR.use_cassette "repos()#git#blobs#sha" do
blob = subject.repos(GH_USER, GH_REPO).git.blobs(test_blob["sha"])
blob = subject.git.blobs(test_blob["sha"])
should_be_a_blob blob
end
end
end
end
describe "#commits" do
context "with a test commit" do
before :all do
VCR.use_cassette "repos()#git#commits#create" do
# create a commit
context "with a test commit" do
before :all do
VCR.use_cassette "repos()#commits#first" do
# create a commit
@test_commit = subject.commits.first
end
end
let(:test_commit) {@test_commit}

describe "#trees" do

it "should return a tree for the commit sha" do
VCR.use_cassette "repos()#git#trees:sha" do
tree = subject.git.trees test_commit["sha"]
tree.should_not be_nil
end
end
let(:test_commit) {@test_commit}
end

describe "#commits" do

it "should return a commit" do
VCR.use_cassette "repos()#git#commit#sha" do
#commit = subject.repos(GH_USER, GH_REPO).git.commits(test_commit["sha"])
#should_be_a_commit commit
commit = subject.git.commits(test_commit["sha"])
should_be_a_commit commit
end
end
end
Expand Down

0 comments on commit 02ee577

Please sign in to comment.