Skip to content

Commit f65aa4c

Browse files
committed
Change required parameters handling, update specs.
1 parent 3df1d5c commit f65aa4c

9 files changed

Lines changed: 51 additions & 31 deletions

File tree

lib/github_api/issues.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ def create_issue(user_name=nil, repo_name=nil, params={})
171171
_normalize_params_keys(params)
172172
# _merge_mime_type(:issue, params)
173173
_filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
174-
175-
raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
174+
_validate_inputs(%w[ title ], params)
176175

177176
post("/repos/#{user}/#{repo}/issues", params)
178177
end

lib/github_api/issues/comments.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def create_comment(user_name, repo_name, issue_id, params={})
7070
_normalize_params_keys(params)
7171
# _merge_mime_type(:issue_comment, params)
7272
_filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
73-
raise ArgumentError, "Required params are: :body" unless _validate_inputs(%w[ body ], params)
73+
_validate_inputs(%w[ body ], params)
7474

7575
post("/repos/#{user}/#{repo}/issues/#{issue_id}/comments", params)
7676
end
@@ -94,7 +94,7 @@ def edit_comment(user_name, repo_name, comment_id, params={})
9494
_normalize_params_keys(params)
9595
# _merge_mime_type(:issue_comment, params)
9696
_filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
97-
raise ArgumentError, "Required params are: :body" unless _validate_inputs(%w[ body ], params)
97+
_validate_inputs(%w[ body ], params)
9898

9999
patch("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
100100
end

lib/github_api/issues/labels.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def create_label(user_name=nil, repo_name=nil, params={})
5656

5757
_normalize_params_keys(params)
5858
_filter_params_keys(VALID_LABEL_INPUTS, params)
59-
60-
raise ArgumentError, "Required params are: :name, :color" unless _validate_inputs(VALID_LABEL_INPUTS, params)
59+
_validate_inputs(VALID_LABEL_INPUTS, params)
6160

6261
post("/repos/#{user}/#{repo}/labels", params)
6362
end
@@ -79,8 +78,7 @@ def update_label(user_name, repo_name, label_id, params={})
7978

8079
_normalize_params_keys(params)
8180
_filter_params_keys(VALID_LABEL_INPUTS, params)
82-
83-
raise ArgumentError, "Required params are: :name, :color" unless _validate_inputs(VALID_LABEL_INPUTS, params)
81+
_validate_inputs(VALID_LABEL_INPUTS, params)
8482

8583
patch("/repos/#{user}/#{repo}/labels/#{label_id}", params)
8684
end

lib/github_api/issues/milestones.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def create_milestone(user_name=nil, repo_name=nil, params={})
8585

8686
_normalize_params_keys(params)
8787
_filter_params_keys(VALID_MILESTONE_INPUTS, params)
88-
89-
raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
88+
_validate_inputs(%w[ title ], params)
9089

9190
post("/repos/#{user}/#{repo}/milestones", params)
9291
end
@@ -114,8 +113,7 @@ def update_milestone(user_name, repo_name, milestone_id, params={})
114113

115114
_normalize_params_keys(params)
116115
_filter_params_keys(VALID_MILESTONE_INPUTS, params)
117-
118-
raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
116+
_validate_inputs(%w[ title ], params)
119117

120118
patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
121119
end

spec/github/issues/comments_spec.rb

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

3-
describe Github::Issues::Comments, :type => :base do
5+
describe Github::Issues::Comments do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
49
let!(:comment_id) { 1 }
510
let!(:issue_id) { 1 }
611

12+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
13+
714
it { described_class::VALID_ISSUE_COMMENT_PARAM_NAME.should_not be_nil }
815

916
describe 'comments' do
@@ -128,7 +135,7 @@
128135
it "should fail to create resource if 'body' input is missing" do
129136
expect {
130137
github.issues.create_comment user, repo, issue_id, inputs.except('body')
131-
}.to raise_error(ArgumentError)
138+
}.to raise_error(Github::Error::RequiredParams)
132139
end
133140

134141
it "should create resource successfully" do
@@ -177,7 +184,7 @@
177184
it "should fail to create resource if 'body' input is missing" do
178185
expect {
179186
github.issues.edit_comment user, repo, comment_id, inputs.except('body')
180-
}.to raise_error(ArgumentError)
187+
}.to raise_error(Github::Error::RequiredParams)
181188
end
182189

183190
it "should create resource successfully" do

spec/github/issues/events_spec.rb

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

3-
describe Github::Issues::Events, :type => :base do
5+
describe Github::Issues::Events do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
49
let(:issue_id) { 1 }
510

11+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
12+
613
describe 'events' do
714
it { github.issues.should respond_to :events }
815
it { github.issues.should respond_to :list_events }
@@ -17,7 +24,6 @@
1724
end
1825

1926
it "should fail to get resource without username" do
20-
github.user, github.repo = nil, nil
2127
expect { github.issues.events }.to raise_error(ArgumentError)
2228
end
2329

@@ -60,7 +66,6 @@
6066
}.to raise_error(Github::Error::NotFound)
6167
end
6268
end
63-
6469
end # without issue_id
6570

6671
context 'with issue_id' do

spec/github/issues/labels_spec.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'spec_helper'
22

3-
describe Github::Issues::Labels, :type => :base do
3+
describe Github::Issues::Labels do
4+
let(:github) { Github.new }
5+
let(:user) { 'peter-murach' }
6+
let(:repo) { 'github' }
7+
8+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
49

510
it { described_class::VALID_LABEL_INPUTS.should_not be_nil }
611

@@ -123,13 +128,13 @@
123128
it "should fail to create resource if 'name' input is missing" do
124129
expect {
125130
github.issues.create_label user, repo, inputs.except('name')
126-
}.to raise_error(ArgumentError)
131+
}.to raise_error(Github::Error::RequiredParams)
127132
end
128133

129134
it "should fail to create resource if 'color' input is missing" do
130135
expect {
131136
github.issues.create_label user, repo, inputs.except('color')
132-
}.to raise_error(ArgumentError)
137+
}.to raise_error(Github::Error::RequiredParams)
133138
end
134139

135140
it "should create resource successfully" do
@@ -181,13 +186,13 @@
181186
it "should fail to create resource if 'name' input is missing" do
182187
expect {
183188
github.issues.update_label user, repo, label_id, inputs.except('name')
184-
}.to raise_error(ArgumentError)
189+
}.to raise_error(Github::Error::RequiredParams)
185190
end
186191

187192
it "should fail to create resource if 'color' input is missing" do
188193
expect {
189194
github.issues.update_label user, repo, label_id, inputs.except('color')
190-
}.to raise_error(ArgumentError)
195+
}.to raise_error(Github::Error::RequiredParams)
191196
end
192197

193198
it "should update resource successfully" do
@@ -274,13 +279,14 @@
274279

275280
it "should fail to get resource without issue_id" do
276281
expect {
277-
github.issues.labels_for user, repo, nil
282+
github.issues.labels_for user, repo, nil
278283
}.to raise_error(ArgumentError)
279284
end
280285

281286
it "should get the resources" do
282287
github.issues.labels_for user, repo, issue_id
283-
a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
288+
a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
289+
should have_been_made
284290
end
285291

286292
it "should return array of resources" do

spec/github/issues/milestones_spec.rb

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

3-
describe Github::Issues::Milestones, :type => :base do
5+
describe Github::Issues::Milestones do
6+
let(:github) { Github.new }
7+
let(:user) { 'peter-murach' }
8+
let(:repo) { 'github' }
9+
10+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
411

512
it { described_class::VALID_MILESTONE_OPTIONS.should_not be_nil }
613
it { described_class::VALID_MILESTONE_INPUTS.should_not be_nil }
@@ -127,7 +134,7 @@
127134
it "should fail to create resource if 'title' input is missing" do
128135
expect {
129136
github.issues.create_milestone user, repo, inputs.except('title')
130-
}.to raise_error(ArgumentError)
137+
}.to raise_error(Github::Error::RequiredParams)
131138
end
132139

133140
it "should create resource successfully" do
@@ -181,7 +188,7 @@
181188
it "should fail to create resource if 'title' input is missing" do
182189
expect {
183190
github.issues.update_milestone user, repo, milestone_id, inputs.except('title')
184-
}.to raise_error(ArgumentError)
191+
}.to raise_error(Github::Error::RequiredParams)
185192
end
186193

187194
it "should update resource successfully" do

spec/github/issues_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
require 'spec_helper'
44

55
describe Github::Issues do
6-
76
let(:issues_api) { Github::Issues }
87
let(:github) { Github.new }
98
let(:user) { 'peter-murach' }
109
let(:repo) { 'github' }
1110

11+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
12+
1213
describe 'modules inclusion' do
1314
it { issues_api.included_modules.should include Github::Issues::Comments }
1415
it { issues_api.included_modules.should include Github::Issues::Events }
@@ -193,7 +194,7 @@
193194
it "should fail to create resource if 'title' input is missing" do
194195
expect {
195196
github.issues.create_issue user, repo, inputs.except('title')
196-
}.to raise_error(ArgumentError)
197+
}.to raise_error(Github::Error::RequiredParams)
197198
end
198199

199200
it "should create resource successfully" do
@@ -248,7 +249,6 @@
248249
end
249250

250251
it "should fail to edit without 'user/repo' parameters" do
251-
github.user, github.repo = nil, nil
252252
expect {
253253
github.issues.edit_issue nil, repo, issue_id
254254
}.to raise_error(ArgumentError)

0 commit comments

Comments
 (0)