Skip to content

Commit 06c0603

Browse files
committed
Change organizations api specs, update to use new required params error.
1 parent b43900c commit 06c0603

4 files changed

Lines changed: 36 additions & 32 deletions

File tree

lib/github_api/orgs/teams.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def create_team(org_name, params={})
6767
_normalize_params_keys(params)
6868
_filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
6969
_validate_params_values(VALID_TEAM_PARAM_VALUES, params)
70-
71-
raise ArgumentError, "Required params are: :name" unless _validate_inputs(%w[ name ], params)
70+
_validate_inputs(%w[ name ], params)
7271

7372
post("/orgs/#{org_name}/teams", params)
7473
end
@@ -92,10 +91,10 @@ def create_team(org_name, params={})
9291
def edit_team(team_name, params={})
9392
_validate_presence_of team_name
9493
_normalize_params_keys(params)
94+
9595
_filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
9696
_validate_params_values(VALID_TEAM_PARAM_VALUES, params)
97-
98-
raise ArgumentError, "Required params are: :name" unless _validate_inputs(%w[ name ], params)
97+
_validate_inputs(%w[ name ], params)
9998

10099
patch("/teams/#{team_name}", params)
101100
end

spec/github/orgs/members_spec.rb

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

33
describe Github::Orgs::Members do
4-
54
let(:github) { Github.new }
65
let(:member) { 'peter-murach' }
76
let(:org) { 'github' }
87

8+
after { github.user, github.repo = nil, nil }
9+
910
describe "members" do
1011
context "resource found" do
1112
before do
@@ -59,13 +60,9 @@
5960
end # members
6061

6162
describe "member?" do
62-
6363
context "with username ane reponame passed" do
64-
6564
context "this repo is being watched by the user"
6665
before do
67-
github.oauth_token = nil
68-
github.user = nil
6966
stub_get("/orgs/#{org}/members/#{member}").
7067
to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
7168
end
@@ -81,7 +78,6 @@
8178
membership = github.orgs.member? org, member
8279
membership.should be_true
8380
end
84-
8581
end
8682

8783
context "without org name and member name passed" do
@@ -144,13 +140,9 @@
144140
end # public_members
145141

146142
describe "public_member?" do
147-
148143
context "with username ane reponame passed" do
149-
150144
context "this repo is being watched by the user"
151145
before do
152-
github.oauth_token = nil
153-
github.user = nil
154146
stub_get("/orgs/#{org}/public_members/#{member}").
155147
to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
156148
end
@@ -166,7 +158,6 @@
166158
public_member = github.orgs.public_member? org, member
167159
public_member.should be_true
168160
end
169-
170161
end
171162

172163
context "without org name and member name passed" do

spec/github/orgs/teams_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
require 'spec_helper'
22

3-
describe Github::Orgs::Teams, :type => :base do
4-
3+
describe Github::Orgs::Teams do
4+
let(:github) { Github.new }
5+
let(:user) { 'peter-murach' }
6+
let(:org) { 'github' }
7+
let(:repo) { 'github' }
58
let(:team) { 'github' }
69
let(:member) { 'github' }
710

11+
after { github.repo, github.user = nil, nil }
12+
813
describe "teams" do
914
context "resource found" do
1015
before do
@@ -106,7 +111,6 @@
106111
before do
107112
stub_post("/orgs/#{org}/teams").with(inputs).
108113
to_return(:body => fixture('orgs/team.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
109-
110114
end
111115

112116
it "should fail to create resource if 'org_name' param is missing" do
@@ -116,7 +120,7 @@
116120
it "should failt to create resource if 'name' input is missing" do
117121
expect {
118122
github.orgs.create_team org, inputs.except(:name)
119-
}.to raise_error(ArgumentError)
123+
}.to raise_error(Github::Error::RequiredParams)
120124
end
121125

122126
it "should create resource successfully" do
@@ -139,7 +143,6 @@
139143
before do
140144
stub_post("/orgs/#{org}/teams").with(inputs).
141145
to_return(:body => fixture('orgs/team.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
142-
143146
end
144147

145148
it "should faile to retrieve resource" do
@@ -167,7 +170,7 @@
167170
it "should failt to create resource if 'name' input is missing" do
168171
expect {
169172
github.orgs.edit_team team, inputs.except(:name)
170-
}.to raise_error(ArgumentError)
173+
}.to raise_error(Github::Error::RequiredParams)
171174
end
172175

173176
it "should create resource successfully" do
@@ -190,7 +193,6 @@
190193
before do
191194
stub_patch("/teams/#{team}").with(inputs).
192195
to_return(:body => fixture('orgs/team.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
193-
194196
end
195197

196198
it "should faile to retrieve resource" do
@@ -290,8 +292,6 @@
290292

291293
context "this repo is being watched by the user"
292294
before do
293-
github.oauth_token = nil
294-
github.user = nil
295295
stub_get("/teams/#{team}/members/#{member}").
296296
to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
297297
end

spec/github/orgs_spec.rb

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

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

513
describe "orgs" do
614
context "resource found for a user" do
@@ -38,19 +46,18 @@
3846

3947
context "resource found for an au user" do
4048
before do
41-
github.user = nil
4249
github.oauth_token = OAUTH_TOKEN
43-
stub_get("/user/orgs?access_token=#{OAUTH_TOKEN}").
50+
stub_get("/user/orgs").
51+
with(:query => { :access_token => OAUTH_TOKEN }).
4452
to_return(:body => fixture('orgs/orgs.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
4553
end
4654

47-
after do
48-
github.user, github.oauth_token = nil, nil
49-
end
55+
after { github.oauth_token = nil }
5056

5157
it "should get the resources" do
5258
github.orgs.orgs
53-
a_get("/user/orgs?access_token=#{OAUTH_TOKEN}").should have_been_made
59+
a_get("/user/orgs").with(:query => { :access_token => OAUTH_TOKEN }).
60+
should have_been_made
5461
end
5562
end
5663

@@ -111,7 +118,14 @@
111118
end # org
112119

113120
describe "edit_org" do
114-
let(:inputs) { { :billing_email => '[email protected]', :blog => "https://github.com/blog", :company => "GitHub", :email => "[email protected]", :location => "San Francisco", :name => "github" } }
121+
let(:inputs) do
122+
{ :billing_email => '[email protected]',
123+
:blog => "https://github.com/blog",
124+
:company => "GitHub",
125+
:email => "[email protected]",
126+
:location => "San Francisco",
127+
:name => "github" }
128+
end
115129

116130
context "resource edited successfully" do
117131
before do

0 commit comments

Comments
 (0)