Skip to content

Commit 2b61b87

Browse files
committed
Change git data api to use new required params error and update specs.
1 parent 06c0603 commit 2b61b87

9 files changed

Lines changed: 50 additions & 33 deletions

File tree

lib/github_api/git_data/blobs.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def create_blob(user_name, repo_name, params={})
4242

4343
_normalize_params_keys(params)
4444
_filter_params_keys(VALID_BLOB_PARAM_NAMES, params)
45-
46-
raise ArgumentError, "Required params are: #{VALID_BLOB_PARAM_NAMES.join(', ')}" unless _validate_inputs(VALID_BLOB_PARAM_NAMES, params)
45+
_validate_inputs(VALID_BLOB_PARAM_NAMES, params)
4746

4847
post("/repos/#{user}/#{repo}/git/blobs", params)
4948
end

lib/github_api/git_data/commits.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def create_commit(user_name, repo_name, params={})
7474
_validate_user_repo_params(user, repo) unless user? && repo?
7575
_normalize_params_keys(params)
7676
_filter_params_keys(VALID_COMMIT_PARAM_NAMES, params)
77-
78-
raise ArgumentError, "Required params are: message, tree, parents" unless _validate_inputs(REQUIRED_COMMIT_PARAMS, params)
77+
_validate_inputs(REQUIRED_COMMIT_PARAMS, params)
7978

8079
post("/repos/#{user}/#{repo}/git/commits", params)
8180
end

lib/github_api/git_data/references.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def create_reference(user_name, repo_name, params={})
8383
_normalize_params_keys params
8484
_filter_params_keys VALID_REF_PARAM_NAMES, params
8585
_validate_reference params['ref']
86-
87-
raise ArgumentError, "Required params are: ref, sha" unless _validate_inputs(%w[ ref sha ], params)
86+
_validate_inputs(%w[ ref sha ], params)
8887

8988
post("/repos/#{user}/#{repo}/git/refs", params)
9089
end
@@ -109,8 +108,7 @@ def update_reference(user_name, repo_name, ref, params={})
109108
_validate_reference ref
110109
_normalize_params_keys(params)
111110
_filter_params_keys(VALID_REF_PARAM_NAMES, params)
112-
113-
raise ArgumentError, "Required params are: sha" unless _validate_inputs(%w[ sha ], params)
111+
_validate_inputs(%w[ sha ], params)
114112

115113
patch("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
116114
end

lib/github_api/git_data/trees.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def create_tree(user_name, repo_name, params={})
8686
_validate_user_repo_params(user, repo) unless user? && repo?
8787
_normalize_params_keys(params)
8888

89-
raise ArgumentError, "Required param: 'tree'" unless _validate_inputs(%w[ tree ], params)
89+
_validate_inputs(%w[ tree ], params)
9090

9191
_filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
9292
_validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])

spec/github/git_data/blobs_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
require 'spec_helper'
1+
# encoding: utf-8
22

3-
describe Github::GitData::Blobs, :type => :base do
3+
require 'spec_helper'
44

5+
describe Github::GitData::Blobs do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
59
let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
610

711
it { described_class::VALID_BLOB_PARAM_NAMES.should_not be_nil }
@@ -69,13 +73,13 @@
6973
it "should fail to create resource if 'content' input is missing" do
7074
expect {
7175
github.git_data.create_blob user, repo, inputs.except('content')
72-
}.to raise_error(ArgumentError)
76+
}.to raise_error(Github::Error::RequiredParams)
7377
end
7478

7579
it "should fail to create resource if 'encoding' input is missing" do
7680
expect {
7781
github.git_data.create_blob user, repo, inputs.except('encoding')
78-
}.to raise_error(ArgumentError)
82+
}.to raise_error(Github::Error::RequiredParams)
7983
end
8084

8185
it "should create resource successfully" do

spec/github/git_data/commits_spec.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# encoding: utf-8
2+
13
require 'spec_helper'
24

35
describe Github::GitData::Commits, :type => :base do
4-
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
59
let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
610

711
it { described_class::VALID_COMMIT_PARAM_NAMES.should_not be_nil }
@@ -17,7 +21,9 @@
1721
end
1822

1923
it "should fail to get resource without sha" do
20-
expect { github.git_data.commit(user, repo, nil)}.to raise_error(ArgumentError)
24+
expect {
25+
github.git_data.commit(user, repo, nil)
26+
}.to raise_error(ArgumentError)
2127
end
2228

2329
it "should get the resource" do
@@ -77,19 +83,19 @@
7783
it "should fail to create resource if 'message' input is missing" do
7884
expect {
7985
github.git_data.create_commit user, repo, inputs.except('message')
80-
}.to raise_error(ArgumentError)
86+
}.to raise_error(Github::Error::RequiredParams)
8187
end
8288

8389
it "should fail to create resource if 'tree' input is missing" do
8490
expect {
8591
github.git_data.create_commit user, repo, inputs.except('tree')
86-
}.to raise_error(ArgumentError)
92+
}.to raise_error(Github::Error::RequiredParams)
8793
end
8894

8995
it "should fail to create resource if 'parents' input is missing" do
9096
expect {
9197
github.git_data.create_commit user, repo, inputs.except('parents')
92-
}.to raise_error(ArgumentError)
98+
}.to raise_error(Github::Error::RequiredParams)
9399
end
94100

95101
it "should create resource successfully" do
@@ -112,7 +118,6 @@
112118
before do
113119
stub_post("/repos/#{user}/#{repo}/git/commits").with(inputs).
114120
to_return(:body => fixture('git_data/commit.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
115-
116121
end
117122

118123
it "should faile to retrieve resource" do

spec/github/git_data/references_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
require 'spec_helper'
1+
# encoding: utf-8
22

3-
describe Github::GitData::References, :type => :base do
3+
require 'spec_helper'
44

5+
describe Github::GitData::References do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
59
let(:ref) { "heads/master" }
610
let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
711

12+
after { github.user, github.repo = nil, nil }
13+
814
it { described_class::VALID_REF_PARAM_NAMES.should_not be_nil }
915
it { described_class::VALID_REF_PARAM_VALUES.should_not be_nil }
1016

@@ -23,7 +29,6 @@
2329
end
2430

2531
it "should fail to get resource without username" do
26-
github.user, github.repo = nil, nil
2732
expect { github.git_data.references }.to raise_error(ArgumentError)
2833
end
2934

@@ -161,7 +166,7 @@
161166
it "should fail to create resource if 'sha' input is missing" do
162167
expect {
163168
github.git_data.create_reference user, repo, inputs.except('sha')
164-
}.to raise_error(ArgumentError)
169+
}.to raise_error(Github::Error::RequiredParams)
165170
end
166171

167172
it "should fail to create resource if 'ref' is wrong" do
@@ -217,13 +222,13 @@
217222
to_return(:body => fixture('git_data/reference.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
218223
end
219224

220-
it "should fail to create resource if 'sha' input is missing" do
225+
it "should fail to update resource if 'sha' input is missing" do
221226
expect {
222227
github.git_data.update_reference user, repo, ref, inputs.except('sha')
223-
}.to raise_error(ArgumentError)
228+
}.to raise_error(Github::Error::RequiredParams)
224229
end
225230

226-
it "should fail to create resource if 'ref' is wrong" do
231+
it "should fail to update resource if 'ref' is wrong" do
227232
expect {
228233
github.git_data.update_reference user, repo, 'branch', inputs
229234
}.to raise_error(ArgumentError)
@@ -245,7 +250,7 @@
245250
end
246251
end
247252

248-
context "failed to create resource" do
253+
context "failed to update resource" do
249254
before do
250255
stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).
251256
to_return(:body => fixture('git_data/reference.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})

spec/github/git_data/tags_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
require 'spec_helper'
1+
# encoding: utf-8
22

3-
describe Github::GitData::Tags, :type => :base do
3+
require 'spec_helper'
44

5+
describe Github::GitData::Tags do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
59
let(:sha) { "940bd336248efae0f9ee5bc7b2d5c985887b16ac" }
610

711
it { described_class::VALID_TAG_PARAM_NAMES.should_not be_nil }
@@ -97,7 +101,6 @@
97101
stub_post("/repos/#{user}/#{repo}/git/tags").
98102
with(inputs).
99103
to_return(:body => fixture('git_data/tag.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
100-
101104
end
102105

103106
it "should faile to retrieve resource" do

spec/github/git_data/trees_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
require 'spec_helper'
1+
# encoding: utf-8
22

3-
describe Github::GitData::Trees, :type => :base do
3+
require 'spec_helper'
44

5+
describe Github::GitData::Trees do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
59
let(:sha) { "9fb037999f264ba9a7fc6274d15fa3ae2ab98312" }
610

711
it { described_class::VALID_TREE_PARAM_NAMES.should_not be_nil }
@@ -96,7 +100,7 @@
96100
it "should fail to create resource if 'content' input is missing" do
97101
expect {
98102
github.git_data.create_tree user, repo, inputs.except('tree')
99-
}.to raise_error(ArgumentError)
103+
}.to raise_error(Github::Error::RequiredParams)
100104
end
101105

102106
it "should create resource successfully" do

0 commit comments

Comments
 (0)