github_api 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -3
- data/lib/github_api/connection.rb +9 -3
- data/lib/github_api/issues.rb +9 -3
- data/lib/github_api/version.rb +1 -1
- data/spec/README.rdoc +22 -0
- data/spec/coverage_adapter.rb +14 -0
- data/spec/fixtures/issues/issue.json +56 -0
- data/spec/fixtures/issues/issues.json +58 -0
- data/spec/github/authorization_spec.rb +77 -0
- data/spec/github/issues_spec.rb +284 -2
- data/spec/spec_helper.rb +5 -0
- metadata +25 -59
data/README.rdoc
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
=
|
1
|
+
= GithubAPI {<img src="http://travis-ci.org/peter-murach/github.png?branch=master" />}[http://travis-ci.org/peter-murach/github] {<img src="https://gemnasium.com/peter-murach/github.png?travis" />}[https://gemnasium.com/peter-murach/github]
|
2
|
+
|
3
|
+
Wiki[https://github.com/peter-murach/github/wiki] | RDocs[http://rubydoc.info/github/peter-murach/github/master/frames]
|
2
4
|
|
3
5
|
A Ruby wrapper for the GitHub REST API v3.
|
4
6
|
|
@@ -12,7 +14,7 @@ Grab the gem by issuing
|
|
12
14
|
|
13
15
|
or in your Gemfile
|
14
16
|
|
15
|
-
gem "github_api"
|
17
|
+
gem "github_api"
|
16
18
|
|
17
19
|
== Usage
|
18
20
|
|
@@ -20,7 +22,7 @@ Create a new client instance
|
|
20
22
|
|
21
23
|
@github = Github.new
|
22
24
|
|
23
|
-
At this stage you can also supply various configuration parameters, such as :user, :repo, :org, :oauth_token, :login, :password or :basic_auth which are used
|
25
|
+
At this stage you can also supply various configuration parameters, such as :user, :repo, :org, :oauth_token, :login, :password or :basic_auth which are used throughout the API
|
24
26
|
|
25
27
|
@github = Github.new :user => 'peter-murach', :repo => 'github-api'
|
26
28
|
|
@@ -12,6 +12,14 @@ require 'github_api/request/basic_auth'
|
|
12
12
|
module Github
|
13
13
|
module Connection
|
14
14
|
|
15
|
+
ALLOWED_OPTIONS = [
|
16
|
+
:headers,
|
17
|
+
:url,
|
18
|
+
:params,
|
19
|
+
:request,
|
20
|
+
:ssl
|
21
|
+
].freeze
|
22
|
+
|
15
23
|
private
|
16
24
|
|
17
25
|
def header_options() # :nodoc:
|
@@ -42,13 +50,11 @@ module Github
|
|
42
50
|
# else
|
43
51
|
# connection_options.merge(header_options)
|
44
52
|
# end
|
45
|
-
merged_options = header_options.merge(options)
|
46
|
-
|
53
|
+
merged_options = _filter_params_keys(ALLOWED_OPTIONS, header_options.merge(options))
|
47
54
|
clear_cache unless options.empty?
|
48
55
|
|
49
56
|
@connection ||= begin
|
50
57
|
Faraday.new(merged_options) do |builder|
|
51
|
-
|
52
58
|
puts options.inspect
|
53
59
|
|
54
60
|
builder.use Faraday::Request::JSON
|
data/lib/github_api/issues.rb
CHANGED
@@ -29,7 +29,7 @@ module Github
|
|
29
29
|
body
|
30
30
|
resource
|
31
31
|
mime_type
|
32
|
-
]
|
32
|
+
].freeze
|
33
33
|
|
34
34
|
VALID_ISSUE_PARAM_VALUES = {
|
35
35
|
'filter' => %w[ assigned created mentioned subscribed ],
|
@@ -77,6 +77,7 @@ module Github
|
|
77
77
|
return response unless block_given?
|
78
78
|
response.each { |el| yield el }
|
79
79
|
end
|
80
|
+
alias :list_issues :issues
|
80
81
|
|
81
82
|
# List issues for a repository
|
82
83
|
#
|
@@ -121,6 +122,9 @@ module Github
|
|
121
122
|
return response unless block_given?
|
122
123
|
response.each { |el| yield el }
|
123
124
|
end
|
125
|
+
alias :repository_issues :repo_issues
|
126
|
+
alias :list_repo_issues :repo_issues
|
127
|
+
alias :list_repository_issues :repo_issues
|
124
128
|
|
125
129
|
# Get a single issue
|
126
130
|
#
|
@@ -128,15 +132,17 @@ module Github
|
|
128
132
|
# @github = Github.new
|
129
133
|
# @github.issues.get_issue 'user-name', 'repo-name', 'issue-id'
|
130
134
|
#
|
131
|
-
def
|
135
|
+
def issue(user_name, repo_name, issue_id, params={})
|
132
136
|
_update_user_repo_params(user_name, repo_name)
|
133
137
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
138
|
+
_validate_presence_of issue_id
|
134
139
|
|
135
140
|
_normalize_params_keys(params)
|
136
141
|
_merge_mime_type(:issue, params)
|
137
142
|
|
138
143
|
get("/repos/#{user}/#{repo}/issues/#{issue_id}")
|
139
144
|
end
|
145
|
+
alias :get_issue :issue
|
140
146
|
|
141
147
|
# Create an issue
|
142
148
|
#
|
@@ -164,7 +170,7 @@ module Github
|
|
164
170
|
|
165
171
|
_normalize_params_keys(params)
|
166
172
|
_merge_mime_type(:issue, params)
|
167
|
-
_filter_params_keys(
|
173
|
+
_filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
|
168
174
|
|
169
175
|
raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
|
170
176
|
|
data/lib/github_api/version.rb
CHANGED
data/spec/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= GithubAPI
|
2
|
+
|
3
|
+
== Running the specs and features
|
4
|
+
|
5
|
+
To run the specs first run the +bundle+ command to install the necessary gems and then +rake+ command to run the specs.
|
6
|
+
|
7
|
+
bundle
|
8
|
+
rake
|
9
|
+
|
10
|
+
The specs currently require Ruby 1.9.x.
|
11
|
+
|
12
|
+
== Coverage
|
13
|
+
|
14
|
+
GithubAPI will run coverage only on demand and to run it do
|
15
|
+
|
16
|
+
COVERAGE=true rake
|
17
|
+
|
18
|
+
== Automation
|
19
|
+
|
20
|
+
You can also run specs and features when you do file modifications by typing
|
21
|
+
|
22
|
+
COVERAGE=true guard
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.adapters.define 'github_api' do
|
4
|
+
add_filter "/spec/"
|
5
|
+
add_filter "/features/"
|
6
|
+
|
7
|
+
add_group 'Repos', 'lib/github_api/repos'
|
8
|
+
add_group 'Orgs', 'lib/github_api/orgs'
|
9
|
+
add_group 'Users', 'lib/github_api/users'
|
10
|
+
add_group 'Issues', 'lib/github_api/issues'
|
11
|
+
add_group 'Gists', 'lib/github_api/gists'
|
12
|
+
add_group 'Git Data','lib/github_api/git_data'
|
13
|
+
add_group 'Pull Requests','lib/github_api/pull_requests'
|
14
|
+
end # SimpleCov
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1",
|
3
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1",
|
4
|
+
"number": 1347,
|
5
|
+
"state": "open",
|
6
|
+
"title": "Found a bug",
|
7
|
+
"body": "I'm having a problem with this.",
|
8
|
+
"user": {
|
9
|
+
"login": "octocat",
|
10
|
+
"id": 1,
|
11
|
+
"avatar_url": "https://github.com/images/error/octocat",
|
12
|
+
"gravatar_id": "somehexcode",
|
13
|
+
"url": "https://api.github.com/users/octocat"
|
14
|
+
},
|
15
|
+
"labels": [
|
16
|
+
{
|
17
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
|
18
|
+
"name": "bug",
|
19
|
+
"color": "f29513"
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"assignee": {
|
23
|
+
"login": "octocat",
|
24
|
+
"id": 1,
|
25
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
26
|
+
"gravatar_id": "somehexcode",
|
27
|
+
"url": "https://api.github.com/users/octocat"
|
28
|
+
},
|
29
|
+
"milestone": {
|
30
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
|
31
|
+
"number": 1,
|
32
|
+
"state": "open",
|
33
|
+
"title": "v1.0",
|
34
|
+
"description": "",
|
35
|
+
"creator": {
|
36
|
+
"login": "octocat",
|
37
|
+
"id": 1,
|
38
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
39
|
+
"gravatar_id": "somehexcode",
|
40
|
+
"url": "https://api.github.com/users/octocat"
|
41
|
+
},
|
42
|
+
"open_issues": 4,
|
43
|
+
"closed_issues": 8,
|
44
|
+
"created_at": "2011-04-10T20:09:31Z",
|
45
|
+
"due_on": null
|
46
|
+
},
|
47
|
+
"comments": 0,
|
48
|
+
"pull_request": {
|
49
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1",
|
50
|
+
"diff_url": "https://github.com/octocat/Hello-World/issues/1.diff",
|
51
|
+
"patch_url": "https://github.com/octocat/Hello-World/issues/1.patch"
|
52
|
+
},
|
53
|
+
"closed_at": null,
|
54
|
+
"created_at": "2011-04-22T13:33:48Z",
|
55
|
+
"updated_at": "2011-04-22T13:33:48Z"
|
56
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1",
|
4
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1",
|
5
|
+
"number": 1347,
|
6
|
+
"state": "open",
|
7
|
+
"title": "Found a bug",
|
8
|
+
"body": "I'm having a problem with this.",
|
9
|
+
"user": {
|
10
|
+
"login": "octocat",
|
11
|
+
"id": 1,
|
12
|
+
"avatar_url": "https://github.com/images/error/octocat",
|
13
|
+
"gravatar_id": "somehexcode",
|
14
|
+
"url": "https://api.github.com/users/octocat"
|
15
|
+
},
|
16
|
+
"labels": [
|
17
|
+
{
|
18
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
|
19
|
+
"name": "bug",
|
20
|
+
"color": "f29513"
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"assignee": {
|
24
|
+
"login": "octocat",
|
25
|
+
"id": 1,
|
26
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
27
|
+
"gravatar_id": "somehexcode",
|
28
|
+
"url": "https://api.github.com/users/octocat"
|
29
|
+
},
|
30
|
+
"milestone": {
|
31
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
|
32
|
+
"number": 1,
|
33
|
+
"state": "open",
|
34
|
+
"title": "v1.0",
|
35
|
+
"description": "",
|
36
|
+
"creator": {
|
37
|
+
"login": "octocat",
|
38
|
+
"id": 1,
|
39
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
40
|
+
"gravatar_id": "somehexcode",
|
41
|
+
"url": "https://api.github.com/users/octocat"
|
42
|
+
},
|
43
|
+
"open_issues": 4,
|
44
|
+
"closed_issues": 8,
|
45
|
+
"created_at": "2011-04-10T20:09:31Z",
|
46
|
+
"due_on": null
|
47
|
+
},
|
48
|
+
"comments": 0,
|
49
|
+
"pull_request": {
|
50
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1",
|
51
|
+
"diff_url": "https://github.com/octocat/Hello-World/issues/1.diff",
|
52
|
+
"patch_url": "https://github.com/octocat/Hello-World/issues/1.patch"
|
53
|
+
},
|
54
|
+
"closed_at": null,
|
55
|
+
"created_at": "2011-04-22T13:33:48Z",
|
56
|
+
"updated_at": "2011-04-22T13:33:48Z"
|
57
|
+
}
|
58
|
+
]
|
@@ -23,6 +23,43 @@ describe Github::Authorization do
|
|
23
23
|
github.client.token_url.should == 'https://github.com/login/oauth/access_token'
|
24
24
|
end
|
25
25
|
|
26
|
+
context '.client' do
|
27
|
+
it { github.should respond_to :client }
|
28
|
+
|
29
|
+
it "should return OAuth2::Client instance" do
|
30
|
+
github.client.should be_a OAuth2::Client
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '.auth_code' do
|
35
|
+
let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
|
36
|
+
|
37
|
+
before do
|
38
|
+
github = Github.new :client_id => client_id, :client_secret => client_secret
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
github.client_id, github.client_secret = nil, nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should throw an error if no client_id" do
|
46
|
+
github.client_id = nil
|
47
|
+
expect { github.auth_code }.should raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should throw an error if no client_secret" do
|
51
|
+
github.client_secret = nil
|
52
|
+
expect { github.auth_code }.should raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return authentication token code" do
|
56
|
+
github.client_id = client_id
|
57
|
+
github.client_secret = client_secret
|
58
|
+
github.client.stub(:auth_code).and_return code
|
59
|
+
github.auth_code.should == code
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
26
63
|
context "authorize_url" do
|
27
64
|
before do
|
28
65
|
github = Github.new :client_id => client_id, :client_secret => client_secret
|
@@ -68,11 +105,51 @@ describe Github::Authorization do
|
|
68
105
|
end
|
69
106
|
end
|
70
107
|
|
108
|
+
context ".authenticated?" do
|
109
|
+
it { github.should respond_to :authenticated? }
|
110
|
+
|
111
|
+
it "should return false if falied on basic authentication" do
|
112
|
+
github.stub(:basic_authed?).and_return false
|
113
|
+
github.authenticated?.should be_false
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should return true if basic authentication performed" do
|
117
|
+
github.stub(:basic_authed?).and_return true
|
118
|
+
github.authenticated?.should be_true
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return true if basic authentication performed" do
|
122
|
+
github.stub(:oauth_token?).and_return true
|
123
|
+
github.authenticated?.should be_true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context ".basic_authed?" do
|
128
|
+
it { github.should respond_to :basic_authed? }
|
129
|
+
|
130
|
+
it "should return false if login is missing" do
|
131
|
+
github.stub(:login?).and_return false
|
132
|
+
github.basic_authed?.should be_false
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return true if login && password provided" do
|
136
|
+
github.stub(:login?).and_return true
|
137
|
+
github.stub(:password?).and_return true
|
138
|
+
github.basic_authed?.should be_true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
71
142
|
context "authentication" do
|
72
143
|
it "should respond to 'authentication'" do
|
73
144
|
github.should respond_to :authentication
|
74
145
|
end
|
75
146
|
|
147
|
+
it "should return empty hash if no basic authentication params available" do
|
148
|
+
github.stub(:login?).and_return false
|
149
|
+
github.stub(:basic_auth?).and_return false
|
150
|
+
github.authentication.should be_empty
|
151
|
+
end
|
152
|
+
|
76
153
|
context 'basic_auth' do
|
77
154
|
before do
|
78
155
|
github = Github.new :basic_auth => 'github:pass'
|
data/spec/github/issues_spec.rb
CHANGED
@@ -1,5 +1,287 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Github::Issues do
|
4
|
-
|
5
|
-
|
6
|
+
|
7
|
+
let(:issues_api) { Github::Issues }
|
8
|
+
let(:github) { Github.new }
|
9
|
+
let(:user) { 'peter-murach' }
|
10
|
+
let(:repo) { 'github' }
|
11
|
+
|
12
|
+
describe 'modules inclusion' do
|
13
|
+
it { issues_api.included_modules.should include Github::Issues::Comments }
|
14
|
+
it { issues_api.included_modules.should include Github::Issues::Events }
|
15
|
+
it { issues_api.included_modules.should include Github::Issues::Labels }
|
16
|
+
it { issues_api.included_modules.should include Github::Issues::Milestones }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'issues' do
|
20
|
+
it { github.issues.should respond_to :issues }
|
21
|
+
it { github.issues.should respond_to :list_issues }
|
22
|
+
|
23
|
+
context "resource found" do
|
24
|
+
before do
|
25
|
+
stub_get("/issues").
|
26
|
+
to_return(:body => fixture('issues/issues.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the resources" do
|
30
|
+
github.issues.issues
|
31
|
+
a_get("/issues").should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return array of resources" do
|
35
|
+
issues = github.issues.issues
|
36
|
+
issues.should be_an Array
|
37
|
+
issues.should have(1).items
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be a mash type" do
|
41
|
+
issues = github.issues.issues
|
42
|
+
issues.first.should be_a Hashie::Mash
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get issue information" do
|
46
|
+
issues = github.issues.issues
|
47
|
+
issues.first.title.should == 'Found a bug'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should yield to a block" do
|
51
|
+
github.issues.should_receive(:issues).and_yield('web')
|
52
|
+
github.issues.issues { |param| 'web' }.should == 'web'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "resource not found" do
|
57
|
+
before do
|
58
|
+
stub_get("/issues").
|
59
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return 404 with a message 'Not Found'" do
|
63
|
+
expect { github.issues.issues }.to raise_error(Github::ResourceNotFound)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end # issues
|
67
|
+
|
68
|
+
describe 'repo_issues' do
|
69
|
+
it { github.issues.should respond_to :repo_issues }
|
70
|
+
it { github.issues.should respond_to :list_repo_issues }
|
71
|
+
it { github.issues.should respond_to :list_repository_issues }
|
72
|
+
|
73
|
+
context "resource found" do
|
74
|
+
before do
|
75
|
+
github.user, github.repo = nil, nil
|
76
|
+
stub_get("/repos/#{user}/#{repo}/issues").
|
77
|
+
to_return(:body => fixture('issues/issues.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should raise error if user-name empty" do
|
81
|
+
expect {
|
82
|
+
github.issues.repo_issues nil, repo
|
83
|
+
}.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get the resources" do
|
87
|
+
github.issues.repo_issues user, repo
|
88
|
+
a_get("/repos/#{user}/#{repo}/issues").should have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return array of resources" do
|
92
|
+
repo_issues = github.issues.repo_issues user, repo
|
93
|
+
repo_issues.should be_an Array
|
94
|
+
repo_issues.should have(1).items
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be a mash type" do
|
98
|
+
repo_issues = github.issues.repo_issues user, repo
|
99
|
+
repo_issues.first.should be_a Hashie::Mash
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get repository issue information" do
|
103
|
+
repo_issues = github.issues.repo_issues user, repo
|
104
|
+
repo_issues.first.title.should == 'Found a bug'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should yield to a block" do
|
108
|
+
github.issues.should_receive(:issues).with(user, repo).and_yield('web')
|
109
|
+
github.issues.issues(user, repo) { |param| 'web' }.should == 'web'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "resource not found" do
|
114
|
+
before do
|
115
|
+
stub_get("/repos/#{user}/#{repo}/issues").
|
116
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return 404 with a message 'Not Found'" do
|
120
|
+
expect {
|
121
|
+
github.issues.repo_issues user, repo
|
122
|
+
}.to raise_error(Github::ResourceNotFound)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end # repo_issues
|
126
|
+
|
127
|
+
describe "get_issue" do
|
128
|
+
let(:issue_id) { 1347 }
|
129
|
+
|
130
|
+
it { github.issues.should respond_to :issue }
|
131
|
+
it { github.issues.should respond_to :get_issue }
|
132
|
+
|
133
|
+
context "resource found" do
|
134
|
+
before do
|
135
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
|
136
|
+
to_return(:body => fixture('issues/issue.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should fail to get resource without issue id" do
|
140
|
+
expect { github.issues.issue(user, repo, nil)}.to raise_error(ArgumentError)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should get the resource" do
|
144
|
+
github.issues.issue user, repo, issue_id
|
145
|
+
a_get("/repos/#{user}/#{repo}/issues/#{issue_id}").should have_been_made
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should get issue information" do
|
149
|
+
issue = github.issues.issue user, repo, issue_id
|
150
|
+
issue.number.should == issue_id
|
151
|
+
issue.title.should == 'Found a bug'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return mash" do
|
155
|
+
issue = github.issues.issue user, repo, issue_id
|
156
|
+
issue.should be_a Hashie::Mash
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "resource not found" do
|
161
|
+
before do
|
162
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
|
163
|
+
to_return(:body => fixture('issues/issue.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should fail to retrive resource" do
|
167
|
+
expect {
|
168
|
+
github.issues.issue user, repo, issue_id
|
169
|
+
}.to raise_error(Github::ResourceNotFound)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end # get_issue
|
173
|
+
|
174
|
+
describe "create_issue" do
|
175
|
+
let(:inputs) {
|
176
|
+
{
|
177
|
+
"title" => "Found a bug",
|
178
|
+
"body" => "I'm having a problem with this.",
|
179
|
+
"assignee" => "octocat",
|
180
|
+
"milestone" => 1,
|
181
|
+
"labels" => [
|
182
|
+
"Label1",
|
183
|
+
"Label2"
|
184
|
+
]
|
185
|
+
}
|
186
|
+
}
|
187
|
+
context "resouce created" do
|
188
|
+
before do
|
189
|
+
stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
|
190
|
+
to_return(:body => fixture('issues/issue.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should fail to create resource if 'title' input is missing" do
|
194
|
+
expect {
|
195
|
+
github.issues.create_issue user, repo, inputs.except('title')
|
196
|
+
}.to raise_error(ArgumentError)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should create resource successfully" do
|
200
|
+
github.issues.create_issue user, repo, inputs
|
201
|
+
a_post("/repos/#{user}/#{repo}/issues").with(inputs).should have_been_made
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should return the resource" do
|
205
|
+
issue = github.issues.create_issue user, repo, inputs
|
206
|
+
issue.should be_a Hashie::Mash
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should get the issue information" do
|
210
|
+
issue = github.issues.create_issue(user, repo, inputs)
|
211
|
+
issue.title.should == 'Found a bug'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "failed to create resource" do
|
216
|
+
before do
|
217
|
+
stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
|
218
|
+
to_return(:body => fixture('issues/issue.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should faile to retrieve resource" do
|
222
|
+
expect {
|
223
|
+
github.issues.create_issue user, repo, inputs
|
224
|
+
}.to raise_error(Github::ResourceNotFound)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end # create_issue
|
228
|
+
|
229
|
+
describe "edit_issue" do
|
230
|
+
let(:issue_id) { 1349 }
|
231
|
+
let(:inputs) {
|
232
|
+
{
|
233
|
+
"title" => "Found a bug",
|
234
|
+
"body" => "I'm having a problem with this.",
|
235
|
+
"assignee" => "octocat",
|
236
|
+
"milestone" => 1,
|
237
|
+
"labels" => [
|
238
|
+
"Label1",
|
239
|
+
"Label2"
|
240
|
+
]
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
context "resource edited successfully" do
|
245
|
+
before do
|
246
|
+
stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
|
247
|
+
to_return(:body => fixture("issues/issue.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should fail to edit without 'user/repo' parameters" do
|
251
|
+
github.user, github.repo = nil, nil
|
252
|
+
expect {
|
253
|
+
github.issues.edit_issue nil, repo, issue_id
|
254
|
+
}.to raise_error(ArgumentError)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should edit the resource" do
|
258
|
+
github.issues.edit_issue user, repo, issue_id, inputs
|
259
|
+
a_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).should have_been_made
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should return resource" do
|
263
|
+
issue = github.issues.edit_issue user, repo, issue_id, inputs
|
264
|
+
issue.should be_a Hashie::Mash
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should be able to retrieve information" do
|
268
|
+
issue = github.issues.edit_issue user, repo, issue_id, inputs
|
269
|
+
issue.title.should == 'Found a bug'
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context "failed to edit resource" do
|
274
|
+
before do
|
275
|
+
stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
|
276
|
+
to_return(:body => fixture("issues/issue.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should fail to find resource" do
|
280
|
+
expect {
|
281
|
+
github.issues.edit_issue user, repo, issue_id, inputs
|
282
|
+
}.to raise_error(Github::ResourceNotFound)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end # edit_issue
|
286
|
+
|
287
|
+
end # Github::Issues
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,11 @@ require 'json'
|
|
8
8
|
require 'webmock/rspec'
|
9
9
|
require 'github_api'
|
10
10
|
|
11
|
+
if RUBY_VERSION > '1.9' and ENV['COVERAGE']
|
12
|
+
require 'coverage_adapter'
|
13
|
+
SimpleCov.start 'github_api'
|
14
|
+
end
|
15
|
+
|
11
16
|
# Requires supporting files with custom matchers and macros, etc,
|
12
17
|
# in ./support/ and its subdirectories.
|
13
18
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 3
|
9
|
-
version: 0.3.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.4
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Piotr Murach
|
@@ -14,20 +10,17 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-12-
|
13
|
+
date: 2011-12-17 00:00:00 +00:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
17
|
name: hashie
|
22
18
|
prerelease: false
|
23
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
24
21
|
requirements:
|
25
22
|
- - ~>
|
26
23
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 2
|
30
|
-
- 0
|
31
24
|
version: 1.2.0
|
32
25
|
type: :runtime
|
33
26
|
version_requirements: *id001
|
@@ -35,13 +28,10 @@ dependencies:
|
|
35
28
|
name: faraday
|
36
29
|
prerelease: false
|
37
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
38
32
|
requirements:
|
39
33
|
- - ~>
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
- 7
|
44
|
-
- 4
|
45
35
|
version: 0.7.4
|
46
36
|
type: :runtime
|
47
37
|
version_requirements: *id002
|
@@ -49,13 +39,10 @@ dependencies:
|
|
49
39
|
name: multi_json
|
50
40
|
prerelease: false
|
51
41
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
52
43
|
requirements:
|
53
44
|
- - ~>
|
54
45
|
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 1
|
57
|
-
- 0
|
58
|
-
- 3
|
59
46
|
version: 1.0.3
|
60
47
|
type: :runtime
|
61
48
|
version_requirements: *id003
|
@@ -63,13 +50,10 @@ dependencies:
|
|
63
50
|
name: oauth2
|
64
51
|
prerelease: false
|
65
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
66
54
|
requirements:
|
67
55
|
- - ~>
|
68
56
|
- !ruby/object:Gem::Version
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
- 5
|
72
|
-
- 0
|
73
57
|
version: 0.5.0
|
74
58
|
type: :runtime
|
75
59
|
version_requirements: *id004
|
@@ -77,25 +61,21 @@ dependencies:
|
|
77
61
|
name: rspec
|
78
62
|
prerelease: false
|
79
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
80
65
|
requirements:
|
81
66
|
- - ~>
|
82
67
|
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
- 2
|
85
|
-
- 4
|
86
|
-
- 0
|
87
|
-
version: 2.4.0
|
68
|
+
version: 2.7.0
|
88
69
|
type: :development
|
89
70
|
version_requirements: *id005
|
90
71
|
- !ruby/object:Gem::Dependency
|
91
72
|
name: cucumber
|
92
73
|
prerelease: false
|
93
74
|
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
94
76
|
requirements:
|
95
77
|
- - ">="
|
96
78
|
- !ruby/object:Gem::Version
|
97
|
-
segments:
|
98
|
-
- 0
|
99
79
|
version: "0"
|
100
80
|
type: :development
|
101
81
|
version_requirements: *id006
|
@@ -103,27 +83,21 @@ dependencies:
|
|
103
83
|
name: yajl-ruby
|
104
84
|
prerelease: false
|
105
85
|
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
106
87
|
requirements:
|
107
88
|
- - ~>
|
108
89
|
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
- 0
|
111
|
-
- 8
|
112
|
-
- 2
|
113
|
-
version: 0.8.2
|
90
|
+
version: 1.1.0
|
114
91
|
type: :development
|
115
92
|
version_requirements: *id007
|
116
93
|
- !ruby/object:Gem::Dependency
|
117
94
|
name: bundler
|
118
95
|
prerelease: false
|
119
96
|
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
120
98
|
requirements:
|
121
99
|
- - ~>
|
122
100
|
- !ruby/object:Gem::Version
|
123
|
-
segments:
|
124
|
-
- 1
|
125
|
-
- 0
|
126
|
-
- 0
|
127
101
|
version: 1.0.0
|
128
102
|
type: :development
|
129
103
|
version_requirements: *id008
|
@@ -131,13 +105,10 @@ dependencies:
|
|
131
105
|
name: jeweler
|
132
106
|
prerelease: false
|
133
107
|
requirement: &id009 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
134
109
|
requirements:
|
135
110
|
- - ~>
|
136
111
|
- !ruby/object:Gem::Version
|
137
|
-
segments:
|
138
|
-
- 1
|
139
|
-
- 6
|
140
|
-
- 4
|
141
112
|
version: 1.6.4
|
142
113
|
type: :development
|
143
114
|
version_requirements: *id009
|
@@ -145,13 +116,10 @@ dependencies:
|
|
145
116
|
name: webmock
|
146
117
|
prerelease: false
|
147
118
|
requirement: &id010 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
148
120
|
requirements:
|
149
121
|
- - ~>
|
150
122
|
- !ruby/object:Gem::Version
|
151
|
-
segments:
|
152
|
-
- 1
|
153
|
-
- 7
|
154
|
-
- 6
|
155
123
|
version: 1.7.6
|
156
124
|
type: :development
|
157
125
|
version_requirements: *id010
|
@@ -159,12 +127,10 @@ dependencies:
|
|
159
127
|
name: simplecov
|
160
128
|
prerelease: false
|
161
129
|
requirement: &id011 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
162
131
|
requirements:
|
163
132
|
- - ~>
|
164
133
|
- !ruby/object:Gem::Version
|
165
|
-
segments:
|
166
|
-
- 0
|
167
|
-
- 4
|
168
134
|
version: "0.4"
|
169
135
|
type: :development
|
170
136
|
version_requirements: *id011
|
@@ -172,11 +138,10 @@ dependencies:
|
|
172
138
|
name: guard-rspec
|
173
139
|
prerelease: false
|
174
140
|
requirement: &id012 !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
175
142
|
requirements:
|
176
143
|
- - ">="
|
177
144
|
- !ruby/object:Gem::Version
|
178
|
-
segments:
|
179
|
-
- 0
|
180
145
|
version: "0"
|
181
146
|
type: :development
|
182
147
|
version_requirements: *id012
|
@@ -184,11 +149,10 @@ dependencies:
|
|
184
149
|
name: guard-cucumber
|
185
150
|
prerelease: false
|
186
151
|
requirement: &id013 !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
187
153
|
requirements:
|
188
154
|
- - ">="
|
189
155
|
- !ruby/object:Gem::Version
|
190
|
-
segments:
|
191
|
-
- 0
|
192
156
|
version: "0"
|
193
157
|
type: :development
|
194
158
|
version_requirements: *id013
|
@@ -262,9 +226,12 @@ files:
|
|
262
226
|
- lib/github_api/users.rb
|
263
227
|
- lib/github_api/version.rb
|
264
228
|
- lib/github_api.rb
|
229
|
+
- spec/coverage_adapter.rb
|
265
230
|
- spec/fixtures/auths/authorization.json
|
266
231
|
- spec/fixtures/auths/authorizations.json
|
267
232
|
- spec/fixtures/events/events.json
|
233
|
+
- spec/fixtures/issues/issue.json
|
234
|
+
- spec/fixtures/issues/issues.json
|
268
235
|
- spec/fixtures/orgs/members.json
|
269
236
|
- spec/fixtures/orgs/org.json
|
270
237
|
- spec/fixtures/orgs/orgs.json
|
@@ -331,6 +298,7 @@ files:
|
|
331
298
|
- spec/github/result_spec.rb
|
332
299
|
- spec/github/users_spec.rb
|
333
300
|
- spec/github_spec.rb
|
301
|
+
- spec/README.rdoc
|
334
302
|
- spec/spec_helper.rb
|
335
303
|
- README.rdoc
|
336
304
|
- LICENSE.txt
|
@@ -344,23 +312,21 @@ rdoc_options: []
|
|
344
312
|
require_paths:
|
345
313
|
- lib
|
346
314
|
required_ruby_version: !ruby/object:Gem::Requirement
|
315
|
+
none: false
|
347
316
|
requirements:
|
348
317
|
- - ">="
|
349
318
|
- !ruby/object:Gem::Version
|
350
|
-
segments:
|
351
|
-
- 0
|
352
319
|
version: "0"
|
353
320
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
321
|
+
none: false
|
354
322
|
requirements:
|
355
323
|
- - ">="
|
356
324
|
- !ruby/object:Gem::Version
|
357
|
-
segments:
|
358
|
-
- 0
|
359
325
|
version: "0"
|
360
326
|
requirements: []
|
361
327
|
|
362
328
|
rubyforge_project:
|
363
|
-
rubygems_version: 1.
|
329
|
+
rubygems_version: 1.6.2
|
364
330
|
signing_key:
|
365
331
|
specification_version: 3
|
366
332
|
summary: Ruby wrapper for the GitHub API v3
|