Permalink
Browse files

added tests and support for #git#trees and #git#commits

  • Loading branch information...
1 parent 2a330a2 commit 02ee5777d2b47902db35f0d17b8a91617172f08e @rauhryan rauhryan committed Apr 5, 2012
Showing with 71 additions and 11 deletions.
  1. +27 −0 lib/ghee/api/git_data.rb
  2. +6 −0 lib/ghee/api/repos.rb
  3. +38 −11 spec/ghee/api/gitdata_spec.rb
View
@@ -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
@@ -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
@@ -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
View
@@ -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
@@ -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
@@ -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"
});
@@ -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

0 comments on commit 02ee577

Please sign in to comment.