Skip to content

Commit 4335726

Browse files
committed
Add membership list and create.
1 parent 4697db7 commit 4335726

8 files changed

Lines changed: 63 additions & 41 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"put","uri":"https://<BASIC_AUTH>@api.github.com/orgs/CodeCu/memberships/anuja-joshi?access_token=<TOKEN>","body":{"encoding":"UTF-8","base64_string":"eyJyb2xlIjoiYWRtaW4ifQ==\n"},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github API Ruby Gem 0.12.4"],"Content-Type":["application/json"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sat, 21 Nov 2015 19:00:14 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4998"],"X-Ratelimit-Reset":["1448136014"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Github-Request-Id":["52236DF4:7FBE:1B5A27F8:5650BF3E"]},"body":{"encoding":"UTF-8","base64_string":"eyJtZXNzYWdlIjoiTXVzdCBoYXZlIGFkbWluIHJpZ2h0cyB0byBSZXBvc2l0\nb3J5LiIsImRvY3VtZW50YXRpb25fdXJsIjoiaHR0cHM6Ly9kZXZlbG9wZXIu\nZ2l0aHViLmNvbS92My9vcmdzL21lbWJlcnMvI2FkZC1vci11cGRhdGUtb3Jn\nYW5pemF0aW9uLW1lbWJlcnNoaXAifQ==\n"},"http_version":null},"recorded_at":"Sat, 21 Nov 2015 19:00:15 GMT"}],"recorded_with":"VCR 2.6.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"put","uri":"https://<BASIC_AUTH>@api.github.com/orgs/CodeCu/memberships/anujaware?access_token=<TOKEN>","body":{"encoding":"UTF-8","base64_string":"eyJyb2xlIjoibWVtYmVyIn0=\n"},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github API Ruby Gem 0.12.4"],"Content-Type":["application/json"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sat, 21 Nov 2015 19:00:14 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4999"],"X-Ratelimit-Reset":["1448136014"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Github-Request-Id":["52236DF4:7FBF:2382B2D5:5650BF3D"]},"body":{"encoding":"UTF-8","base64_string":"eyJtZXNzYWdlIjoiTXVzdCBoYXZlIGFkbWluIHJpZ2h0cyB0byBSZXBvc2l0\nb3J5LiIsImRvY3VtZW50YXRpb25fdXJsIjoiaHR0cHM6Ly9kZXZlbG9wZXIu\nZ2l0aHViLmNvbS92My9vcmdzL21lbWJlcnMvI2FkZC1vci11cGRhdGUtb3Jn\nYW5pemF0aW9uLW1lbWJlcnNoaXAifQ==\n"},"http_version":null},"recorded_at":"Sat, 21 Nov 2015 19:00:14 GMT"}],"recorded_with":"VCR 2.6.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"get","uri":"https://<BASIC_AUTH>@api.github.com/user/memberships/orgs?access_token=<TOKEN>","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github API Ruby Gem 0.12.4"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sat, 21 Nov 2015 19:15:06 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4997"],"X-Ratelimit-Reset":["1448136014"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Etag":["\"be2b47a6aa91c255a63bbfbd08983b13\""],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Served-By":["8a5c38021a5cd7cef7b8f49a296fee40"],"X-Github-Request-Id":["52236DF4:94AB:1150803F:5650C2B9"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Sat, 21 Nov 2015 19:15:06 GMT"}],"recorded_with":"VCR 2.6.0"}

features/orgs/members.feature

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,3 @@ Feature: Members API
5555
| true |
5656
When I make request within a cassette named "orgs/members/member_public_true"
5757
Then the response should be true
58-
59-
Scenario: Add/Update Organization Membership (unaffiliated user)
60-
61-
Given I want to grant_organization_membership resource with the following params:
62-
| org | username |
63-
| CodeCu | anujaware |
64-
And I pass the following request options:
65-
| role |
66-
| member |
67-
When I make request within a cassette named "orgs/members/grant_organization_membership_unaffiliated_user"
68-
Then the response status should be 200
69-
And the response type should be JSON
70-
And the response should not be empty
71-
72-
73-
Scenario: Add/Update Organization Membership (already member)
74-
75-
Given I want to grant_organization_membership resource with the following params:
76-
| org | username |
77-
| CodeCu | anuja-joshi |
78-
And I pass the following request options:
79-
| role |
80-
| admin |
81-
When I make request within a cassette named "orgs/members/grant_organization_membership_already_member"
82-
Then the response status should be 200
83-
And the response type should be JSON
84-
And the response should not be empty

features/orgs/memberships.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Memberships API
2+
3+
Background:
4+
Given I have "Github::Client::Orgs::Memberships" instance
5+
6+
Scenario: List
7+
8+
Given I want to list resources
9+
When I make request within a cassette named "orgs/memberships/list"
10+
Then the response status should be 200
11+
And the response type should be JSON
12+
13+
Scenario: Add/Update Organization Membership (unaffiliated user)
14+
15+
Given I want to create resource with the following params:
16+
| org | username |
17+
| CodeCu | anujaware |
18+
And I pass the following request options:
19+
| role |
20+
| member |
21+
When I make request within a cassette named "orgs/memberships/add_unaffiliated_user"
22+
Then the response status should be 200
23+
And the response type should be JSON
24+
And the response should not be empty
25+
26+
Scenario: Add/Update Organization Membership (already member)
27+
28+
Given I want to create resource with the following params:
29+
| org | username |
30+
| CodeCu | anuja-joshi |
31+
And I pass the following request options:
32+
| role |
33+
| admin |
34+
When I make request within a cassette named "orgs/memberships/add_already_member"
35+
Then the response status should be 200
36+
And the response type should be JSON
37+
And the response should not be empty

lib/github_api/client/orgs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Client::Orgs < API
66

77
require_all 'github_api/client/orgs',
88
'members',
9+
'memberships',
910
'teams'
1011

1112
# Access to Client::Orgs::Members API

spec/github/client/orgs/members/grant_organization_membership_spec.rb renamed to spec/github/client/orgs/memberships/create_spec.rb

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,54 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Orgs::Members, '#grant_organization_membership' do
5+
RSpec.describe Github::Client::Orgs::Memberships, '#create' do
66
let(:org) { 'CodeCu' }
77
let(:status) { 200 }
88

99
before {
10-
stub_put(request_path).with(inputs).to_return(:body => body, :status => status,
11-
:headers => {:content_type => "application/json; charset=utf-8"})
10+
stub_put(request_path).with(inputs).
11+
to_return(body: body, status: status,
12+
headers: {content_type: 'application/json; charset=utf-8'})
1213
}
1314

1415
context 'Add/update organization membership - unaffiliated user' do
15-
1616
let(:username) { 'anujaware' }
1717
let(:request_path) { "/orgs/#{org}/memberships/#{username}" }
1818
let(:body) { fixture('orgs/membership_to_unaffiliated_user.json') }
1919
let(:inputs) {{role: 'member'}}
2020

2121
it 'should create organization membership with pending state' do
22-
response = subject.grant_organization_membership org, username, inputs
23-
expect(response.state).to eq 'pending'
22+
response = subject.create(org, username, inputs)
23+
expect(response.state).to eq('pending')
2424
end
2525

2626
it 'should create organization membership with role member' do
27-
response = subject.grant_organization_membership org, username, inputs
28-
expect(response.role).to eq 'member'
27+
response = subject.create org, username, inputs
28+
expect(response.role).to eq('member')
29+
end
30+
31+
it "failse without role option" do
32+
expect {
33+
subject.create(org, username)
34+
}.to raise_error(Github::Error::RequiredParams,
35+
/Required parameters are: role/)
2936
end
3037
end
3138

3239
context 'Add/update organization membership - affiliated user' do
33-
3440
let(:username) { 'anuja-joshi' }
3541
let(:request_path) { "/orgs/#{org}/memberships/#{username}" }
3642
let(:body) { fixture('orgs/membership_to_affilliated_user.json') }
3743
let(:inputs) {{role: 'admin'}}
3844

3945
it 'should create organization membership with active state' do
40-
response = subject.grant_organization_membership org, username, inputs
41-
expect(response.state).to eq 'active'
46+
response = subject.create(org, username, inputs)
47+
expect(response.state).to eq('active')
4248
end
4349

4450
it 'should update organization membership with role admin' do
45-
response = subject.grant_organization_membership org, username, inputs
46-
expect(response.role).to eq 'admin'
51+
response = subject.create(org, username, inputs)
52+
expect(response.role).to eq('admin')
4753
end
4854
end
49-
end # grant_organization_membership
55+
end # create

spec/integration/orgs_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
its(:teams) { should be_a Github::Client::Orgs::Teams }
1414

15+
its(:memberships) { should be_a(Github::Client::Orgs::Memberships) }
16+
1517
end # Github::Client::Orgs

0 commit comments

Comments
 (0)