Skip to content

Commit 8d49370

Browse files
committed
Added spec for orgs/hooks
1 parent b9e1a37 commit 8d49370

11 files changed

Lines changed: 338 additions & 5 deletions

File tree

lib/github_api/client/orgs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Github
55
class Client::Orgs < API
66

77
require_all 'github_api/client/orgs',
8-
'hooks'
8+
'hooks',
99
'members',
1010
'memberships',
1111
'teams'

lib/github_api/client/orgs/hooks.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def get(*args)
100100
# An optional string that determines whether the SSL certificate
101101
# of the host for url will be verified when delivering payloads.
102102
# Supported values include "0" (verification is performed) and
103-
# "1" (verification is not performed). The default is "0".
103+
# "1" (verification is not performed). The default is "0".or instance, if the library doesn't get updated to permit a given parameter the api call won't work, however if we skip permission all together, the endpoint should always work provided the actual resource path doesn't change. I'm in the process of completely removing the permit functionality.
104104
#
105105
# @example
106106
# github = Github.new
@@ -115,7 +115,7 @@ def get(*args)
115115
# @api public
116116
def create(*args)
117117
arguments(args, required: [:org]) do
118-
permit VALID_HOOK_PARAM_NAMES, recursive: false
118+
#permit VALID_HOOK_PARAM_NAMES, recursive: false
119119
assert_required REQUIRED_PARAMS
120120
end
121121

@@ -188,7 +188,7 @@ def ping(*args)
188188
def delete(*args)
189189
arguments(args, required: [:org, :id])
190190

191-
delete_request("/repos/#{arguments.org}/hooks/#{arguments.id}", arguments.params)
191+
delete_request("/orgs/#{arguments.org}/hooks/#{arguments.id}", arguments.params)
192192
end
193193
end # Client::Orgs::Hooks
194194
end # Github

spec/fixtures/orgs/hook.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"url": "https://api.github.com/orgs/octocat/hooks/1",
3+
"updated_at": "2011-09-06T20:39:23Z",
4+
"created_at": "2011-09-06T17:26:27Z",
5+
"name": "web",
6+
"events": [
7+
"push"
8+
],
9+
"active": true,
10+
"config": {
11+
"url": "http://example.com",
12+
"content_type": "json"
13+
},
14+
"id": 1
15+
}

spec/fixtures/orgs/hooks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"url": "https://api.github.com/orgs/octocat/hooks/1",
4+
"updated_at": "2011-09-06T20:39:23Z",
5+
"created_at": "2011-09-06T17:26:27Z",
6+
"name": "web",
7+
"active": true,
8+
"id": 1
9+
}
10+
]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#create' do
6+
let(:org) { 'API-sampler' }
7+
let(:request_path) { "/orgs/#{org}/hooks" }
8+
let(:inputs) {
9+
{
10+
'name' => 'web',
11+
'config' => {
12+
'url' => "http://something.com/webhook",
13+
'content_type' => "json"
14+
},
15+
'active' => true
16+
}
17+
}
18+
19+
before {
20+
stub_post(request_path).with(inputs.except('unrelated')).
21+
to_return(:body => body, :status => status,
22+
:headers => {:content_type => "application/json; charset=utf-8"})
23+
}
24+
25+
after { reset_authentication_for(subject) }
26+
27+
context "resouce created" do
28+
let(:body) { fixture('orgs/hook.json') }
29+
let(:status) { 201 }
30+
31+
it "should fail to create resource if 'name' input is missing" do
32+
expect {
33+
subject.create org, inputs.except('name')
34+
}.to raise_error(Github::Error::RequiredParams)
35+
end
36+
37+
it "should failt to create resource if 'config' input is missing" do
38+
expect {
39+
subject.create org, inputs.except('config')
40+
}.to raise_error(Github::Error::RequiredParams)
41+
end
42+
43+
it "should create resource successfully" do
44+
subject.create org, inputs
45+
a_post(request_path).with(inputs).should have_been_made
46+
end
47+
48+
it "should return the resource" do
49+
hook = subject.create org, inputs
50+
hook.should be_a Github::ResponseWrapper
51+
end
52+
53+
it "should get the hook information" do
54+
hook = subject.create org, inputs
55+
hook.name.should == 'web'
56+
end
57+
end
58+
59+
it_should_behave_like 'request failure' do
60+
let(:requestable) { subject.create org, inputs }
61+
end
62+
end # create
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#delete' do
6+
let(:org) { 'API-sampler' }
7+
let(:hook_id) { 1 }
8+
let(:request_path) { "/orgs/#{org}/hooks/#{hook_id}" }
9+
10+
before {
11+
stub_delete(request_path).to_return(:body => body, :status => status,
12+
:headers => {:content_type => "application/json; charset=utf-8"})
13+
}
14+
15+
after { reset_authentication_for(subject) }
16+
17+
context "resource removed successfully" do
18+
let(:body) { '' }
19+
let(:status) { 204 }
20+
21+
it "should fail to delete without 'org' parameter" do
22+
expect { subject.delete }.to raise_error(ArgumentError)
23+
end
24+
25+
it "should fail to delete resource without 'hook_id'" do
26+
expect { subject.delete org }.to raise_error(ArgumentError)
27+
end
28+
29+
it "should delete the resource" do
30+
subject.delete org, hook_id
31+
a_delete(request_path).should have_been_made
32+
end
33+
end
34+
35+
it_should_behave_like 'request failure' do
36+
let(:requestable) { subject.delete org, hook_id }
37+
end
38+
end # delete
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#edit' do
6+
let(:org) { 'API-sampler' }
7+
let(:hook_id) { 1 }
8+
let(:request_path) {"/orgs/#{org}/hooks/#{hook_id}" }
9+
let(:inputs) {
10+
{
11+
:name => 'web',
12+
:config => {
13+
:url => "http://something.com/webhook",
14+
:content_type => "json"
15+
},
16+
:active => true
17+
}
18+
}
19+
20+
before {
21+
stub_patch(request_path).with(inputs.except(:unrelated)).
22+
to_return(:body => body, :status => status,
23+
:headers => {:content_type => "application/json; charset=utf-8"})
24+
}
25+
26+
after { reset_authentication_for(subject) }
27+
28+
context "resource edited successfully" do
29+
let(:body) { fixture("orgs/hook.json") }
30+
let(:status) { 200 }
31+
32+
it "should fail to edit without 'org' parameter" do
33+
expect { subject.edit }.to raise_error(ArgumentError)
34+
end
35+
36+
it "should fail to edit resource without 'name' parameter" do
37+
expect{
38+
subject.edit org, hook_id, inputs.except(:name)
39+
}.to raise_error(Github::Error::RequiredParams)
40+
end
41+
42+
it "should fail to edit resource without 'hook_id'" do
43+
expect { subject.edit org }.to raise_error(ArgumentError)
44+
end
45+
46+
it "should fail to edit resource without 'config' parameter" do
47+
expect {
48+
subject.edit org, hook_id, inputs.except(:config)
49+
}.to raise_error(Github::Error::RequiredParams)
50+
end
51+
52+
it "should edit the resource" do
53+
subject.edit org, hook_id, inputs
54+
a_patch(request_path).with(inputs).should have_been_made
55+
end
56+
57+
it "should return resource" do
58+
hook = subject.edit org, hook_id, inputs
59+
hook.should be_a Github::ResponseWrapper
60+
end
61+
62+
it "should be able to retrieve information" do
63+
hook = subject.edit org, hook_id, inputs
64+
hook.name.should == 'web'
65+
end
66+
end
67+
68+
it_should_behave_like 'request failure' do
69+
let(:requestable) { subject.edit org, hook_id, inputs }
70+
end
71+
end # edit
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#get' do
6+
let(:org) { 'API-sampler' }
7+
let(:hook_id) { 1 }
8+
let(:request_path) { "/orgs/#{org}/hooks/#{hook_id}" }
9+
10+
before {
11+
stub_get(request_path).to_return(:body => body, :status => status,
12+
:headers => {:content_type => "application/json; charset=utf-8"})
13+
}
14+
15+
after { reset_authentication_for(subject) }
16+
17+
context "resource found" do
18+
let(:body) { fixture('orgs/hook.json') }
19+
let(:status) { 200 }
20+
21+
it { subject.should respond_to :find }
22+
23+
it "should fail to get resource without hook id" do
24+
expect { subject.get org }.to raise_error(ArgumentError)
25+
end
26+
27+
it "should get the resource" do
28+
subject.get org, hook_id
29+
a_get(request_path).should have_been_made
30+
end
31+
32+
it "should get hook information" do
33+
hook = subject.get org, hook_id
34+
hook.id.should == hook_id
35+
hook.name.should == 'web'
36+
end
37+
38+
it "should return mash" do
39+
hook = subject.get org, hook_id
40+
hook.should be_a Github::ResponseWrapper
41+
end
42+
end
43+
44+
it_should_behave_like 'request failure' do
45+
let(:requestable) { subject.get org, hook_id }
46+
end
47+
end # get
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#list' do
6+
let(:org) { 'API-sampler' }
7+
let(:request_path) { "/orgs/#{org}/hooks" }
8+
9+
before {
10+
stub_get(request_path).to_return(:body => body, :status => status,
11+
:headers => {:content_type => "application/json; charset=utf-8"})
12+
}
13+
14+
after { reset_authentication_for(subject) }
15+
16+
context "resource found" do
17+
let(:body) { fixture('orgs/hooks.json') }
18+
let(:status) { 200 }
19+
20+
it { subject.should respond_to :all }
21+
22+
it { expect { subject.list }.to raise_error(ArgumentError) }
23+
24+
# it "should fail to get resource without required arguments" do
25+
# expect { subject.list org }.to raise_error(ArgumentError)
26+
# end
27+
28+
it "should get the resources" do
29+
subject.list org
30+
a_get(request_path).should have_been_made
31+
end
32+
33+
it_should_behave_like 'an array of resources' do
34+
let(:requestable) { subject.list org }
35+
end
36+
37+
it "should get hook information" do
38+
hooks = subject.list org
39+
hooks.first.name.should == 'web'
40+
end
41+
42+
it "should yield to a block" do
43+
yielded = []
44+
result = subject.list(org) { |obj| yielded << obj }
45+
yielded.should == result
46+
end
47+
end
48+
49+
it_should_behave_like 'request failure' do
50+
let(:requestable) { subject.list org }
51+
end
52+
end # list
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Hooks, '#ping' do
6+
let(:org) { 'API-sampler' }
7+
let(:hook_id) { 1 }
8+
let(:request_path) { "/orgs/#{org}/hooks/#{hook_id}/pings" }
9+
10+
before {
11+
stub_post(request_path).to_return(:body => body, :status => status,
12+
:headers => {:content_type => "application/json; charset=utf-8"})
13+
}
14+
15+
after { reset_authentication_for(subject) }
16+
17+
context "resource tested successfully" do
18+
let(:body) { '' }
19+
let(:status) { 204 }
20+
21+
it "should fail to test without 'org' parameter" do
22+
expect { subject.ping }.to raise_error(ArgumentError)
23+
end
24+
25+
it "should fail to test resource without 'hook_id'" do
26+
expect { subject.ping org }.to raise_error(ArgumentError)
27+
end
28+
29+
it "should trigger test for the resource" do
30+
subject.ping org, hook_id
31+
a_post(request_path).should have_been_made
32+
end
33+
end
34+
35+
it_should_behave_like 'request failure' do
36+
let(:requestable) { subject.ping org, hook_id }
37+
end
38+
end # ping

0 commit comments

Comments
 (0)