github_api 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,8 +118,8 @@ module Github
118
118
  return params
119
119
  end
120
120
 
121
+ # Removes any keys from nested hashes that don't match predefiend keys
121
122
  def _filter_params_keys(keys, params) # :nodoc:
122
- # params.reject! { |k,v| !keys.include? k }
123
123
  case params
124
124
  when Hash
125
125
  params.keys.each do |k, v|
@@ -156,6 +156,7 @@ module Github
156
156
  return hash
157
157
  end
158
158
 
159
+ # Ensures that hash values contain predefined values
159
160
  def _validate_params_values(options, params) # :nodoc:
160
161
  params.each do |k, v|
161
162
  next unless options.keys.include?(k)
@@ -15,6 +15,12 @@ module Github
15
15
  date
16
16
  ].freeze
17
17
 
18
+ REQUIRED_COMMIT_PARAMS = %w[
19
+ message
20
+ tree
21
+ parents
22
+ ].freeze
23
+
18
24
  # Get a commit
19
25
  #
20
26
  # = Examples
@@ -29,6 +35,7 @@ module Github
29
35
 
30
36
  get("/repos/#{user}/#{repo}/git/commits/#{sha}", params)
31
37
  end
38
+ alias :get_commit :commit
32
39
 
33
40
  # Create a commit
34
41
  #
@@ -62,13 +69,13 @@ module Github
62
69
  # ],
63
70
  # "tree": "827efc6d56897b048c772eb4087f854f46256132"]
64
71
  #
65
- def create_commit(user_name=nil, repo_name=nil, params={})
72
+ def create_commit(user_name, repo_name, params={})
66
73
  _update_user_repo_params(user_name, repo_name)
67
74
  _validate_user_repo_params(user, repo) unless user? && repo?
68
75
  _normalize_params_keys(params)
69
76
  _filter_params_keys(VALID_COMMIT_PARAM_NAMES, params)
70
77
 
71
- raise ArgumentError, "Required params are: message, tree, parents" unless _validate_inputs(%w[ message tree parents ], params)
78
+ raise ArgumentError, "Required params are: message, tree, parents" unless _validate_inputs(REQUIRED_COMMIT_PARAMS, params)
72
79
 
73
80
  post("/repos/#{user}/#{repo}/git/commits", params)
74
81
  end
@@ -10,26 +10,6 @@ module Github
10
10
  'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
11
11
  }
12
12
 
13
- # Get a reference
14
- #
15
- # The ref in the URL must be formatted as <tt>heads/branch</tt>,
16
- # not just branch. For example, the call to get the data for a
17
- # branch named <tt>sc/featureA</tt> would be formatted as
18
- # <tt>heads/sc/featureA</tt>
19
- #
20
- # = Examples
21
- # @github = Github.new
22
- # @github.git_data.reference 'user-name', 'repo-name', 'reference'
23
- #
24
- def reference(user_name, repo_name, ref, params={})
25
- _update_user_repo_params(user_name, repo_name)
26
- _validate_user_repo_params(user, repo) unless user? && repo?
27
- _validate_presence_of ref
28
- _normalize_params_keys(params)
29
-
30
- get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
31
- end
32
-
33
13
  # Get all references
34
14
  #
35
15
  # This will return an array of all the references on the system,
@@ -49,6 +29,7 @@ module Github
49
29
  _normalize_params_keys(params)
50
30
 
51
31
  response = if ref
32
+ _validate_reference ref
52
33
  get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
53
34
  else
54
35
  get("/repos/#{user}/#{repo}/git/refs", params)
@@ -56,6 +37,32 @@ module Github
56
37
  return response unless block_given?
57
38
  response.each { |el| yield el }
58
39
  end
40
+ alias :list_references :references
41
+ alias :get_all_references :references
42
+
43
+ # Get a reference
44
+ #
45
+ # The ref in the URL must be formatted as <tt>heads/branch</tt>,
46
+ # not just branch. For example, the call to get the data for a
47
+ # branch named <tt>sc/featureA</tt> would be formatted as
48
+ # <tt>heads/sc/featureA</tt>
49
+ #
50
+ # = Examples
51
+ # @github = Github.new
52
+ # @github.git_data.reference 'user-name', 'repo-name', 'reference'
53
+ #
54
+ def reference(user_name, repo_name, ref, params={})
55
+ _update_user_repo_params(user_name, repo_name)
56
+ _validate_user_repo_params(user, repo) unless user? && repo?
57
+
58
+ _validate_presence_of ref
59
+ _validate_reference ref
60
+ _normalize_params_keys params
61
+
62
+ get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
63
+ end
64
+ alias :get_reference :reference
65
+
59
66
 
60
67
  # Create a reference
61
68
  #
@@ -72,12 +79,12 @@ module Github
72
79
  def create_reference(user_name, repo_name, params={})
73
80
  _update_user_repo_params(user_name, repo_name)
74
81
  _validate_user_repo_params(user, repo) unless user? && repo?
75
- _normalize_params_keys(params)
76
82
 
77
- raise ArgumentError, "Required params are: ref, sha" unless _validate_inputs(%w[ ref sha ], params)
83
+ _normalize_params_keys params
84
+ _filter_params_keys VALID_REF_PARAM_NAMES, params
85
+ _validate_reference params['ref']
78
86
 
79
- _filter_params_keys(VALID_REF_PARAM_NAMES, params)
80
- _validate_params_values(VALID_REF_PARAM_VALUES, params)
87
+ raise ArgumentError, "Required params are: ref, sha" unless _validate_inputs(%w[ ref sha ], params)
81
88
 
82
89
  post("/repos/#{user}/#{repo}/git/refs", params)
83
90
  end
@@ -97,17 +104,25 @@ module Github
97
104
  def update_reference(user_name, repo_name, ref, params={})
98
105
  _update_user_repo_params(user_name, repo_name)
99
106
  _validate_user_repo_params(user, repo) unless user? && repo?
107
+
100
108
  _validate_presence_of ref
109
+ _validate_reference ref
101
110
  _normalize_params_keys(params)
111
+ _filter_params_keys(VALID_REF_PARAM_NAMES, params)
102
112
 
103
113
  raise ArgumentError, "Required params are: sha" unless _validate_inputs(%w[ sha ], params)
104
114
 
105
- _filter_params_keys(VALID_REF_PARAM_NAMES, params)
106
- _validate_params_values(VALID_REF_PARAM_VALUES, params)
107
-
108
115
  patch("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
109
116
  end
110
117
 
118
+ private
119
+
120
+ def _validate_reference ref
121
+ unless VALID_REF_PARAM_VALUES['ref'] =~ "refs/#{ref}"
122
+ raise ArgumentError, "Provided 'reference' is invalid"
123
+ end
124
+ end
125
+
111
126
  end # References
112
127
  end # GitData
113
128
  end # Github
@@ -13,7 +13,10 @@ module Github
13
13
  name
14
14
  email
15
15
  date
16
- ]
16
+ sha
17
+ url
18
+ tagger
19
+ ].freeze
17
20
 
18
21
  VALID_TAG_PARAM_VALUES = {
19
22
  'type' => %w[ blob tree commit ]
@@ -33,6 +36,7 @@ module Github
33
36
 
34
37
  get("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
35
38
  end
39
+ alias :get_tag :tag
36
40
 
37
41
  # Create a tag object
38
42
  # Note that creating a tag object does not create the reference that
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 3
7
- PATCH = 8
7
+ PATCH = 9
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,25 @@
1
+ {
2
+ "sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
3
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
4
+ "author": {
5
+ "date": "2010-04-10T14:10:01-07:00",
6
+ "name": "Scott Chacon",
7
+ "email": "schacon@gmail.com"
8
+ },
9
+ "committer": {
10
+ "date": "2010-04-10T14:10:01-07:00",
11
+ "name": "Scott Chacon",
12
+ "email": "schacon@gmail.com"
13
+ },
14
+ "message": "added readme, because im a good github citizen\n",
15
+ "tree": {
16
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
17
+ "sha": "691272480426f78a0138979dd3ce63b77f706feb"
18
+ },
19
+ "parents": [
20
+ {
21
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
22
+ "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
23
+ }
24
+ ]
25
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "ref": "refs/heads/sc/featureA",
4
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/sc/featureA",
5
+ "object": {
6
+ "type": "commit",
7
+ "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
8
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14"
9
+ }
10
+ }
11
+ ]
@@ -0,0 +1,29 @@
1
+ [
2
+ {
3
+ "ref": "refs/heads/master",
4
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/master",
5
+ "object": {
6
+ "type": "commit",
7
+ "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
8
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa"
9
+ }
10
+ },
11
+ {
12
+ "ref": "refs/heads/gh-pages",
13
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/gh-pages",
14
+ "object": {
15
+ "type": "commit",
16
+ "sha": "612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac",
17
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/612077ae6dffb4d2"
18
+ }
19
+ },
20
+ {
21
+ "ref": "refs/tags/v0.0.1",
22
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/tags/v0.0.1",
23
+ "object": {
24
+ "type": "tag",
25
+ "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac",
26
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/tags/940bd336248efae0f"
27
+ }
28
+ }
29
+ ]
@@ -0,0 +1,16 @@
1
+ {
2
+ "tag": "v0.0.1",
3
+ "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac",
4
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/tags/940bd336248efae0f9ee5bc7b2d5c985887b16ac",
5
+ "message": "initial version\n",
6
+ "tagger": {
7
+ "name": "Scott Chacon",
8
+ "email": "schacon@gmail.com",
9
+ "date": "2011-06-17T14:53:35-07:00"
10
+ },
11
+ "object": {
12
+ "type": "commit",
13
+ "sha": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
14
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c"
15
+ }
16
+ }
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Gists::Comments do
3
+ describe Github::Gists::Comments, :type => :base do
4
4
  pending
5
- end
5
+ end # Github::Gists::Comments
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::GitData::Blobs do
4
- include SpecHelpers::Base
3
+ describe Github::GitData::Blobs, :type => :base do
5
4
 
6
5
  let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
7
6
 
@@ -55,14 +54,15 @@ describe Github::GitData::Blobs do
55
54
  let(:inputs) {
56
55
  {
57
56
  "content" => "Content of the blob",
58
- "encoding" => "utf-8"
57
+ "encoding" => "utf-8",
58
+ "unrelated" => 'giberrish'
59
59
  }
60
60
  }
61
61
 
62
62
  context "resouce created" do
63
63
  before do
64
64
  stub_post("/repos/#{user}/#{repo}/git/blobs").
65
- with(:body => JSON.generate(inputs)).
65
+ with(:body => JSON.generate(inputs.except('unrelated'))).
66
66
  to_return(:body => fixture('git_data/blob_sha.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
67
67
  end
68
68
 
@@ -1,5 +1,126 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::GitData::Commits do
4
- pending
5
- end
3
+ describe Github::GitData::Commits, :type => :base do
4
+
5
+ let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
6
+
7
+ it { described_class::VALID_COMMIT_PARAM_NAMES.should_not be_nil }
8
+
9
+ describe "commit" do
10
+ it { github.git_data.should respond_to :commit }
11
+ it { github.git_data.should respond_to :get_commit }
12
+
13
+ context "resource found" do
14
+ before do
15
+ stub_get("/repos/#{user}/#{repo}/git/commits/#{sha}").
16
+ to_return(:body => fixture('git_data/commit.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
17
+ end
18
+
19
+ it "should fail to get resource without sha" do
20
+ expect { github.git_data.commit(user, repo, nil)}.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should get the resource" do
24
+ github.git_data.commit user, repo, sha
25
+ a_get("/repos/#{user}/#{repo}/git/commits/#{sha}").should have_been_made
26
+ end
27
+
28
+ it "should get commit information" do
29
+ commit = github.git_data.commit user, repo, sha
30
+ commit.author.name.should eql "Scott Chacon"
31
+ end
32
+
33
+ it "should return mash" do
34
+ commit = github.git_data.commit user, repo, sha
35
+ commit.should be_a Hashie::Mash
36
+ end
37
+ end
38
+
39
+ context "resource not found" do
40
+ before do
41
+ stub_get("/repos/#{user}/#{repo}/git/commits/#{sha}").
42
+ to_return(:body => fixture('git_data/commit.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
43
+ end
44
+
45
+ it "should fail to retrive resource" do
46
+ expect {
47
+ github.git_data.commit user, repo, sha
48
+ }.to raise_error(Github::ResourceNotFound)
49
+ end
50
+ end
51
+ end # commit
52
+
53
+ describe "create_commit" do
54
+ let(:inputs) {
55
+ {
56
+ "message" => "my commit message",
57
+ "author" => {
58
+ "name" => "Scott Chacon",
59
+ "email" => "schacon@gmail.com",
60
+ "date" => "2008-07-09T16:13:30+12:00"
61
+ },
62
+ "parents" => [
63
+ "7d1b31e74ee336d15cbd21741bc88a537ed063a0"
64
+ ],
65
+ "tree" => "827efc6d56897b048c772eb4087f854f46256132",
66
+ 'unrelated' => 'giberrish'
67
+ }
68
+ }
69
+
70
+ context "resouce created" do
71
+ before do
72
+ stub_post("/repos/#{user}/#{repo}/git/commits").
73
+ with(:body => JSON.generate(inputs.except('unrelated'))).
74
+ to_return(:body => fixture('git_data/commit.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
75
+ end
76
+
77
+ it "should fail to create resource if 'message' input is missing" do
78
+ expect {
79
+ github.git_data.create_commit user, repo, inputs.except('message')
80
+ }.to raise_error(ArgumentError)
81
+ end
82
+
83
+ it "should fail to create resource if 'tree' input is missing" do
84
+ expect {
85
+ github.git_data.create_commit user, repo, inputs.except('tree')
86
+ }.to raise_error(ArgumentError)
87
+ end
88
+
89
+ it "should fail to create resource if 'parents' input is missing" do
90
+ expect {
91
+ github.git_data.create_commit user, repo, inputs.except('parents')
92
+ }.to raise_error(ArgumentError)
93
+ end
94
+
95
+ it "should create resource successfully" do
96
+ github.git_data.create_commit user, repo, inputs
97
+ a_post("/repos/#{user}/#{repo}/git/commits").with(inputs).should have_been_made
98
+ end
99
+
100
+ it "should return the resource" do
101
+ commit = github.git_data.create_commit user, repo, inputs
102
+ commit.should be_a Hashie::Mash
103
+ end
104
+
105
+ it "should get the commit information" do
106
+ commit = github.git_data.create_commit user, repo, inputs
107
+ commit.author.name.should eql "Scott Chacon"
108
+ end
109
+ end
110
+
111
+ context "failed to create resource" do
112
+ before do
113
+ stub_post("/repos/#{user}/#{repo}/git/commits").with(inputs).
114
+ to_return(:body => fixture('git_data/commit.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
115
+
116
+ end
117
+
118
+ it "should faile to retrieve resource" do
119
+ expect {
120
+ github.git_data.create_commit user, repo, inputs
121
+ }.to raise_error(Github::ResourceNotFound)
122
+ end
123
+ end
124
+ end # create_commit
125
+
126
+ end # Github::GitData::Commits
@@ -1,5 +1,263 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::GitData::References do
4
- pending
5
- end
3
+ describe Github::GitData::References, :type => :base do
4
+
5
+ let(:ref) { "heads/master" }
6
+ let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
7
+
8
+ it { described_class::VALID_REF_PARAM_NAMES.should_not be_nil }
9
+ it { described_class::VALID_REF_PARAM_VALUES.should_not be_nil }
10
+
11
+ describe "references" do
12
+
13
+ context 'check aliases' do
14
+ it { github.git_data.should respond_to :references }
15
+ it { github.git_data.should respond_to :list_references }
16
+ it { github.git_data.should respond_to :get_all_references }
17
+ end
18
+
19
+ context "get all the refernces based on sub-namespace" do
20
+ before do
21
+ stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
22
+ to_return(:body => fixture('git_data/references.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
23
+ end
24
+
25
+ it "should fail to get resource without username" do
26
+ github.user, github.repo = nil, nil
27
+ expect { github.git_data.references }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should fail to call with invalid reference" do
31
+ expect {
32
+ github.git_data.references user, repo, 'branch'
33
+ }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it "should get the resources" do
37
+ github.git_data.references user, repo, ref
38
+ a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
39
+ end
40
+
41
+ it "should return array of resources" do
42
+ references = github.git_data.references user, repo, ref
43
+ references.should be_an Array
44
+ references.should have(3).items
45
+ end
46
+
47
+ it "should be a mash type" do
48
+ references = github.git_data.references user, repo, ref
49
+ references.first.should be_a Hashie::Mash
50
+ end
51
+
52
+ it "should get reference information" do
53
+ references = github.git_data.references user, repo, ref
54
+ references.first.ref.should eql 'refs/heads/master'
55
+ end
56
+
57
+ it "should yield to a block" do
58
+ github.git_data.should_receive(:references).with(user, repo, ref).and_yield('web')
59
+ github.git_data.references(user, repo, ref) { |param| 'web' }
60
+ end
61
+ end
62
+
63
+ context "get all the references on the system" do
64
+ before do
65
+ stub_get("/repos/#{user}/#{repo}/git/refs").
66
+ to_return(:body => fixture('git_data/references.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
67
+ end
68
+
69
+ it "should get the resources" do
70
+ github.git_data.references user, repo
71
+ a_get("/repos/#{user}/#{repo}/git/refs").should have_been_made
72
+ end
73
+ end
74
+
75
+ context "resource not found" do
76
+ before do
77
+ stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
78
+ to_return(:body => "", :status => [404, "Not Found"])
79
+ end
80
+
81
+ it "should return 404 with a message 'Not Found'" do
82
+ expect {
83
+ github.git_data.references user, repo, ref
84
+ }.to raise_error(Github::ResourceNotFound)
85
+ end
86
+ end
87
+ end # references
88
+
89
+ describe "reference" do
90
+ it { github.git_data.should respond_to :reference }
91
+ it { github.git_data.should respond_to :get_reference }
92
+
93
+ context "resource found" do
94
+ before do
95
+ stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
96
+ to_return(:body => fixture('git_data/reference.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
97
+ end
98
+
99
+ it "should fail to get resource without ref" do
100
+ expect { github.git_data.reference(user, repo, nil)}.to raise_error(ArgumentError)
101
+ end
102
+
103
+ it "should fail to get resource with wrong ref" do
104
+ expect {
105
+ github.git_data.reference user, repo, 'branch'
106
+ }.to raise_error(ArgumentError)
107
+ end
108
+
109
+ it "should get the resource" do
110
+ github.git_data.reference user, repo, ref
111
+ a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
112
+ end
113
+
114
+ it "should get reference information" do
115
+ reference = github.git_data.reference user, repo, ref
116
+ reference.first.ref.should eql "refs/heads/sc/featureA"
117
+ end
118
+
119
+ it "should return mash" do
120
+ reference = github.git_data.reference user, repo, ref
121
+ reference.first.should be_a Hashie::Mash
122
+ end
123
+ end
124
+
125
+ context "resource not found" do
126
+ before do
127
+ stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
128
+ to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
129
+ end
130
+
131
+ it "should fail to retrive resource" do
132
+ expect {
133
+ github.git_data.reference user, repo, ref
134
+ }.to raise_error(Github::ResourceNotFound)
135
+ end
136
+ end
137
+ end # reference
138
+
139
+ describe "create_reference" do
140
+ let(:inputs) {
141
+ {
142
+ "ref" => "refs/heads/master",
143
+ "sha" => "827efc6d56897b048c772eb4087f854f46256132",
144
+ "unrelated" => 'giberrish'
145
+ }
146
+ }
147
+
148
+ context "resouce created" do
149
+ before do
150
+ stub_post("/repos/#{user}/#{repo}/git/refs").
151
+ with(:body => JSON.generate(inputs.except('unrelated'))).
152
+ to_return(:body => fixture('git_data/reference.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
153
+ end
154
+
155
+ it "should fail to create resource if 'ref' input is missing" do
156
+ expect {
157
+ github.git_data.create_reference user, repo, inputs.except('ref')
158
+ }.to raise_error(ArgumentError)
159
+ end
160
+
161
+ it "should fail to create resource if 'sha' input is missing" do
162
+ expect {
163
+ github.git_data.create_reference user, repo, inputs.except('sha')
164
+ }.to raise_error(ArgumentError)
165
+ end
166
+
167
+ it "should fail to create resource if 'ref' is wrong" do
168
+ expect {
169
+ github.git_data.create_reference user, repo, 'branch'
170
+ }.to raise_error(ArgumentError)
171
+ end
172
+
173
+ it "should create resource successfully" do
174
+ github.git_data.create_reference user, repo, inputs
175
+ a_post("/repos/#{user}/#{repo}/git/refs").with(inputs).should have_been_made
176
+ end
177
+
178
+ it "should return the resource" do
179
+ reference = github.git_data.create_reference user, repo, inputs
180
+ reference.first.should be_a Hashie::Mash
181
+ end
182
+
183
+ it "should get the reference information" do
184
+ reference = github.git_data.create_reference user, repo, inputs
185
+ reference.first.ref.should eql 'refs/heads/sc/featureA'
186
+ end
187
+ end
188
+
189
+ context "failed to create resource" do
190
+ before do
191
+ stub_post("/repos/#{user}/#{repo}/git/refs").with(inputs).
192
+ to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
193
+
194
+ end
195
+
196
+ it "should faile to retrieve resource" do
197
+ expect {
198
+ github.git_data.create_reference user, repo, inputs
199
+ }.to raise_error(Github::ResourceNotFound)
200
+ end
201
+ end
202
+ end # create_reference
203
+
204
+ describe "update_reference" do
205
+ let(:inputs) {
206
+ {
207
+ "sha" => "827efc6d56897b048c772eb4087f854f46256132",
208
+ "force" => true,
209
+ "unrelated" => 'giberrish'
210
+ }
211
+ }
212
+
213
+ context "resouce updated" do
214
+ before do
215
+ stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").
216
+ with(:body => JSON.generate(inputs.except('unrelated'))).
217
+ to_return(:body => fixture('git_data/reference.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
218
+ end
219
+
220
+ it "should fail to create resource if 'sha' input is missing" do
221
+ expect {
222
+ github.git_data.update_reference user, repo, ref, inputs.except('sha')
223
+ }.to raise_error(ArgumentError)
224
+ end
225
+
226
+ it "should fail to create resource if 'ref' is wrong" do
227
+ expect {
228
+ github.git_data.update_reference user, repo, 'branch', inputs
229
+ }.to raise_error(ArgumentError)
230
+ end
231
+
232
+ it "should update resource successfully" do
233
+ github.git_data.update_reference user, repo, ref, inputs
234
+ a_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).should have_been_made
235
+ end
236
+
237
+ it "should return the resource" do
238
+ reference = github.git_data.update_reference user, repo, ref, inputs
239
+ reference.first.should be_a Hashie::Mash
240
+ end
241
+
242
+ it "should get the reference information" do
243
+ reference = github.git_data.update_reference user, repo, ref, inputs
244
+ reference.first.ref.should eql 'refs/heads/sc/featureA'
245
+ end
246
+ end
247
+
248
+ context "failed to create resource" do
249
+ before do
250
+ stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).
251
+ to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
252
+
253
+ end
254
+
255
+ it "should faile to retrieve resource" do
256
+ expect {
257
+ github.git_data.update_reference user, repo, ref, inputs
258
+ }.to raise_error(Github::ResourceNotFound)
259
+ end
260
+ end
261
+ end # update_reference
262
+
263
+ end # Github::GitData::References
@@ -1,5 +1,111 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::GitData::Tags do
4
- pending
5
- end
3
+ describe Github::GitData::Tags, :type => :base do
4
+
5
+ let(:sha) { "940bd336248efae0f9ee5bc7b2d5c985887b16ac" }
6
+
7
+ it { described_class::VALID_TAG_PARAM_NAMES.should_not be_nil }
8
+
9
+ describe "tag" do
10
+ it { github.git_data.should respond_to :tag }
11
+ it { github.git_data.should respond_to :get_tag }
12
+
13
+ context "resource found" do
14
+ before do
15
+ stub_get("/repos/#{user}/#{repo}/git/tags/#{sha}").
16
+ to_return(:body => fixture('git_data/tag.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
17
+ end
18
+
19
+ it "should fail to get resource without sha" do
20
+ expect { github.git_data.tag(user, repo, nil)}.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should get the resource" do
24
+ github.git_data.tag user, repo, sha
25
+ a_get("/repos/#{user}/#{repo}/git/tags/#{sha}").should have_been_made
26
+ end
27
+
28
+ it "should get tag information" do
29
+ tag = github.git_data.tag user, repo, sha
30
+ tag.tag.should eql "v0.0.1"
31
+ end
32
+
33
+ it "should return mash" do
34
+ tag = github.git_data.tag user, repo, sha
35
+ tag.should be_a Hashie::Mash
36
+ end
37
+ end
38
+
39
+ context "resource not found" do
40
+ before do
41
+ stub_get("/repos/#{user}/#{repo}/git/tags/#{sha}").
42
+ to_return(:body => fixture('git_data/tag.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
43
+ end
44
+
45
+ it "should fail to retrive resource" do
46
+ expect {
47
+ github.git_data.tag user, repo, sha
48
+ }.to raise_error(Github::ResourceNotFound)
49
+ end
50
+ end
51
+ end # tag
52
+
53
+ describe "create_tag" do
54
+ let(:inputs) {
55
+ {
56
+ "tag" => "v0.0.1",
57
+ "message" => "initial version\n",
58
+ "object" => {
59
+ "type" => "commit",
60
+ "sha" => "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
61
+ "url" => "https://api.github.com/repos/octocat/Hello-World/git/commits/c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c"
62
+ },
63
+ "tagger" => {
64
+ "name" => "Scott Chacon",
65
+ "email" => "schacon@gmail.com",
66
+ "date" => "2011-06-17T14:53:35-07:00"
67
+ },
68
+ 'unrelated' => 'giberrish'
69
+ }
70
+ }
71
+
72
+ context "resouce created" do
73
+ before do
74
+ stub_post("/repos/#{user}/#{repo}/git/tags").
75
+ with(:body => JSON.generate(inputs.except('unrelated'))).
76
+ to_return(:body => fixture('git_data/tag.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
77
+ end
78
+
79
+ it "should create resource successfully" do
80
+ github.git_data.create_tag user, repo, inputs
81
+ a_post("/repos/#{user}/#{repo}/git/tags").with(inputs).should have_been_made
82
+ end
83
+
84
+ it "should return the resource" do
85
+ tag = github.git_data.create_tag user, repo, inputs
86
+ tag.should be_a Hashie::Mash
87
+ end
88
+
89
+ it "should get the tag information" do
90
+ tag = github.git_data.create_tag user, repo, inputs
91
+ tag.sha.should == sha
92
+ end
93
+ end
94
+
95
+ context "failed to create resource" do
96
+ before do
97
+ stub_post("/repos/#{user}/#{repo}/git/tags").
98
+ with(inputs).
99
+ to_return(:body => fixture('git_data/tag.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
100
+
101
+ end
102
+
103
+ it "should faile to retrieve resource" do
104
+ expect {
105
+ github.git_data.create_tag user, repo, inputs
106
+ }.to raise_error(Github::ResourceNotFound)
107
+ end
108
+ end
109
+ end # create_tag
110
+
111
+ end # Github::GitData::Tags
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::GitData::Trees do
4
- include SpecHelpers::Base
3
+ describe Github::GitData::Trees, :type => :base do
5
4
 
6
5
  let(:sha) { "9fb037999f264ba9a7fc6274d15fa3ae2ab98312" }
7
6
 
@@ -1,11 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Issues::Comments do
4
- include SpecHelpers::Base
3
+ describe Github::Issues::Comments, :type => :base do
5
4
 
6
- let(:comments_api) { Github::Issues::Comments }
7
-
8
- it { comments_api::VALID_ISSUE_COMMENT_PARAM_NAME.should_not be_nil }
5
+ it { described_class::VALID_ISSUE_COMMENT_PARAM_NAME.should_not be_nil }
9
6
 
10
7
  describe 'comments' do
11
8
  let(:issue_id) { 1 }
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Issues::Events do
4
- include SpecHelpers::Base
3
+ describe Github::Issues::Events, :type => :base do
5
4
 
6
5
  describe 'events' do
7
6
  it { github.issues.should respond_to :events }
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Issues::Labels do
4
- include SpecHelpers::Base
3
+ describe Github::Issues::Labels, :type => :base do
5
4
 
6
5
  it { described_class::VALID_LABEL_INPUTS.should_not be_nil }
7
6
 
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Issues::Milestones do
4
- include SpecHelpers::Base
3
+ describe Github::Issues::Milestones, :type => :base do
5
4
 
6
5
  it { described_class::VALID_MILESTONE_OPTIONS.should_not be_nil }
7
6
  it { described_class::VALID_MILESTONE_INPUTS.should_not be_nil }
@@ -1,13 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Orgs::Teams do
3
+ describe Github::Orgs::Teams, :type => :base do
4
4
 
5
- let(:github) { Github.new }
6
5
  let(:team) { 'github' }
7
6
  let(:member) { 'github' }
8
- let(:org) { 'github' }
9
- let(:user) { 'peter-murach' }
10
- let(:repo) { 'github' }
11
7
 
12
8
  describe "teams" do
13
9
  context "resource found" do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Orgs do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:org) { 'github' }
3
+ describe Github::Orgs, :type => :base do
8
4
 
9
5
  describe "orgs" do
10
6
  context "resource found for a user" do
@@ -1,11 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Collaborators do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:repo) { 'github' }
8
- let(:collaborator) { 'octocat' }
3
+ describe Github::Repos::Collaborators, :type => :base do
9
4
 
10
5
  describe "collaborators" do
11
6
  context "resource found" do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Commits do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:repo) { 'github' }
3
+ describe Github::Repos::Commits, :type => :base do
8
4
 
9
5
  describe "commits" do
10
6
  context "resource found" do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Downloads do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:repo) { 'github' }
3
+ describe Github::Repos::Downloads, :type => :base do
8
4
 
9
5
  it { described_class::VALID_DOWNLOAD_PARAM_NAMES.should_not be_nil }
10
6
  it { described_class::REQUIRED_PARAMS.should_not be_nil }
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Forks do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:repo) { 'github' }
3
+ describe Github::Repos::Forks, :type => :base do
8
4
 
9
5
  describe "forks" do
10
6
 
@@ -1,15 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Hooks do
3
+ describe Github::Repos::Hooks, :type => :base do
4
4
 
5
- let(:hooks_api) { Github::Repos::Hooks }
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
-
10
- it { hooks_api::VALID_HOOK_PARAM_NAMES.should_not be_nil }
11
- it { hooks_api::VALID_HOOK_PARAM_VALUES.should_not be_nil }
12
- it { hooks_api::REQUIRED_PARAMS.should_not be_nil }
5
+ it { described_class::VALID_HOOK_PARAM_NAMES.should_not be_nil }
6
+ it { described_class::VALID_HOOK_PARAM_VALUES.should_not be_nil }
7
+ it { described_class::REQUIRED_PARAMS.should_not be_nil }
13
8
 
14
9
  describe "hooks" do
15
10
  context 'check aliases' do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Keys do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach'}
7
- let(:repo) { 'github' }
3
+ describe Github::Repos::Keys, :type => :base do
8
4
 
9
5
  it { described_class::VALID_KEY_PARAM_NAMES.should_not be_nil }
10
6
 
@@ -2,11 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Github::Repos::Watching do
6
-
7
- let(:github) { Github.new }
8
- let(:user) { 'peter-murach' }
9
- let(:repo) { 'github' }
5
+ describe Github::Repos::Watching, :type => :base do
10
6
 
11
7
  describe "watchers" do
12
8
  before do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
7
- let(:repo) { 'github' }
3
+ describe Github::Repos, :type => :base do
8
4
 
9
5
  describe "branches" do
10
6
  context "resource found" do
@@ -1,9 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Users do
4
-
5
- let(:github) { Github.new }
6
- let(:user) { 'peter-murach' }
3
+ describe Github::Users, :type => :base do
7
4
 
8
5
  before do
9
6
  reset_authentication_for github
@@ -6,8 +6,14 @@ module SpecHelpers
6
6
  let(:github) { Github.new }
7
7
  let(:user) { 'peter-murach' }
8
8
  let(:repo) { 'github' }
9
+ let(:org) { 'github' }
10
+ let(:collaborator) { 'octocat' }
9
11
  end
10
12
  end
11
13
 
12
14
  end
13
15
  end # SpecHelpers
16
+
17
+ RSpec.configure do |conf|
18
+ conf.include SpecHelpers::Base, :type => :base
19
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: github_api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.8
5
+ version: 0.3.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Piotr Murach
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-01 00:00:00 +00:00
13
+ date: 2012-01-03 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -235,6 +235,10 @@ files:
235
235
  - spec/fixtures/events/events.json
236
236
  - spec/fixtures/git_data/blob.json
237
237
  - spec/fixtures/git_data/blob_sha.json
238
+ - spec/fixtures/git_data/commit.json
239
+ - spec/fixtures/git_data/reference.json
240
+ - spec/fixtures/git_data/references.json
241
+ - spec/fixtures/git_data/tag.json
238
242
  - spec/fixtures/git_data/tree.json
239
243
  - spec/fixtures/issues/comment.json
240
244
  - spec/fixtures/issues/comments.json