github_api 0.8.2 → 0.8.3

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.
Files changed (58) hide show
  1. data/README.md +20 -1
  2. data/features/cassettes/issues/events/get.yml +139 -0
  3. data/features/cassettes/issues/events/list_issue.yml +71 -0
  4. data/features/cassettes/issues/events/list_repo.yml +222 -0
  5. data/features/cassettes/issues/labels/list_repo.yml +65 -0
  6. data/features/cassettes/issues/milestones/create.yml +55 -0
  7. data/features/cassettes/issues/milestones/delete.yml +46 -0
  8. data/features/cassettes/issues/milestones/get.yml +175 -0
  9. data/features/cassettes/issues/milestones/list.yml +54 -0
  10. data/features/cassettes/issues/milestones/update.yml +53 -0
  11. data/features/cassettes/repos/contents/archive.yml +43 -84
  12. data/features/cassettes/say/custom.yml +60 -0
  13. data/features/cassettes/say/random.yml +60 -0
  14. data/features/issues/events.feature +38 -0
  15. data/features/issues/labels.feature +14 -0
  16. data/features/issues/milestones.feature +62 -0
  17. data/features/say.feature +68 -0
  18. data/features/step_definitions/common_steps.rb +6 -0
  19. data/features/support/helpers.rb +4 -0
  20. data/lib/github_api.rb +2 -0
  21. data/lib/github_api/client.rb +8 -0
  22. data/lib/github_api/constants.rb +4 -0
  23. data/lib/github_api/issues.rb +74 -46
  24. data/lib/github_api/issues/assignees.rb +2 -1
  25. data/lib/github_api/issues/events.rb +3 -3
  26. data/lib/github_api/issues/milestones.rb +0 -1
  27. data/lib/github_api/rate_limit.rb +2 -0
  28. data/lib/github_api/result.rb +13 -0
  29. data/lib/github_api/say.rb +24 -0
  30. data/lib/github_api/scopes.rb +19 -0
  31. data/lib/github_api/version.rb +1 -1
  32. data/spec/github/git_data/git_data_spec.rb +19 -0
  33. data/spec/github/issues/assignees/check_spec.rb +46 -0
  34. data/spec/github/issues/assignees/list_spec.rb +47 -0
  35. data/spec/github/issues/assignees_spec.rb +0 -96
  36. data/spec/github/issues/create_spec.rb +60 -0
  37. data/spec/github/issues/edit_spec.rb +61 -0
  38. data/spec/github/issues/events_spec.rb +4 -4
  39. data/spec/github/issues/get_spec.rb +49 -0
  40. data/spec/github/issues/issues_spec.rb +19 -0
  41. data/spec/github/issues/list_spec.rb +90 -0
  42. data/spec/github/issues/milestones/create_spec.rb +56 -0
  43. data/spec/github/issues/milestones/delete_spec.rb +42 -0
  44. data/spec/github/issues/milestones/get_spec.rb +49 -0
  45. data/spec/github/issues/milestones/list_spec.rb +52 -0
  46. data/spec/github/issues/milestones/update_spec.rb +57 -0
  47. data/spec/github/issues/milestones_spec.rb +1 -276
  48. data/spec/github/scopes/list_spec.rb +33 -0
  49. data/spec/github/users/followers/follow_spec.rb +33 -0
  50. data/spec/github/users/followers/following_spec.rb +65 -0
  51. data/spec/github/users/followers/is_following_spec.rb +41 -0
  52. data/spec/github/users/followers/list_spec.rb +2 -8
  53. data/spec/github/users/followers/unfollow_spec.rb +33 -0
  54. data/spec/github/users/users_spec.rb +16 -0
  55. metadata +68 -35
  56. data/spec/github/git_data_spec.rb +0 -11
  57. data/spec/github/issues_spec.rb +0 -284
  58. data/spec/github/users/followers_spec.rb +0 -172
@@ -1,101 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Issues::Assignees do
4
- let(:github) { Github::Issues::Assignees.new }
5
- let(:user) { 'peter-murach' }
6
- let(:repo) { 'github' }
7
- let(:assignee) { 'octocat' }
8
-
9
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
10
-
11
- describe '#list' do
12
- context 'resources found' do
13
- before do
14
- stub_get("/repos/#{user}/#{repo}/assignees").
15
- to_return(:body => fixture('repos/assignees.json'),
16
- :status => 200,
17
- :headers => {:content_type => "application/json; charset=utf-8"})
18
- end
19
-
20
- it 'should get the resources' do
21
- github.list user, repo
22
- a_get("/repos/#{user}/#{repo}/assignees").should have_been_made
23
- end
24
-
25
- it "should return array of resources" do
26
- assignees = github.list user, repo
27
- assignees.should be_an Array
28
- assignees.should have(1).items
29
- end
30
-
31
- it "should be a mash type" do
32
- assignees = github.list user, repo
33
- assignees.first.should be_a Hashie::Mash
34
- end
35
-
36
- it "should get collaborator information" do
37
- assignees = github.list user, repo
38
- assignees.first.login.should == 'octocat'
39
- end
40
-
41
- it "should yield to a block" do
42
- github.should_receive(:list).with(user, repo).and_yield('web')
43
- github.list(user, repo) { |param| 'web' }
44
- end
45
- end
46
-
47
- context "resource not found" do
48
- before do
49
- stub_get("/repos/#{user}/#{repo}/assignees").
50
- to_return(:body => "", :status => [404, "Not Found"],
51
- :headers => {:content_type => "application/json; charset=utf-8"})
52
- end
53
-
54
- it "should return 404 with a message 'Not Found'" do
55
- expect {
56
- github.list user, repo
57
- }.to raise_error(Github::Error::NotFound)
58
- end
59
- end
60
- end # list
61
-
62
- describe '#check' do
63
- context "resource found " do
64
- before do
65
- stub_get("/repos/#{user}/#{repo}/assignees/#{assignee}").
66
- to_return(:body => '', :status => 204,
67
- :headers => {:content_type => "application/json; charset=utf-8"})
68
- end
69
-
70
- it "should fail to get resource without collaborator name" do
71
- expect {
72
- github.check user, repo, nil
73
- }.to raise_error(ArgumentError)
74
- end
75
-
76
- it "should get the resource" do
77
- github.check user, repo, assignee
78
- a_get("/repos/#{user}/#{repo}/assignees/#{assignee}").should have_been_made
79
- end
80
-
81
- it "should find assignee" do
82
- github.should_receive(:check).with(user, repo, assignee) { true }
83
- github.check user, repo, assignee
84
- end
85
- end
86
-
87
- context "resource not found" do
88
- before do
89
- stub_get("/repos/#{user}/#{repo}/assignees/#{assignee}").
90
- to_return(:body => '', :status => 404,
91
- :headers => {:content_type => "application/json; charset=utf-8"})
92
- end
93
-
94
- it "should fail to retrieve resource" do
95
- github.should_receive(:check).with(user, repo, assignee) { false }
96
- github.check user, repo, assignee
97
- end
98
- end
99
- end # check
100
4
 
101
5
  end # Github::Repos::Assignees
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/issues" }
9
+ let(:inputs) {
10
+ {
11
+ "title" => "Found a bug",
12
+ "body" => "I'm having a problem with this.",
13
+ "assignee" => "octocat",
14
+ "milestone" => 1,
15
+ "labels" => [
16
+ "Label1",
17
+ "Label2"
18
+ ]
19
+ }
20
+ }
21
+
22
+ before {
23
+ stub_post(request_path).with(inputs).
24
+ to_return(:body => body, :status => status,
25
+ :headers => {:content_type => "application/json; charset=utf-8"})
26
+ }
27
+
28
+ after { reset_authentication_for(subject) }
29
+
30
+ context "resouce created" do
31
+ let(:body) { fixture('issues/issue.json') }
32
+ let(:status) { 201 }
33
+
34
+ it "should fail to create resource if 'title' input is missing" do
35
+ expect {
36
+ subject.create user, repo, inputs.except('title')
37
+ }.to raise_error(Github::Error::RequiredParams)
38
+ end
39
+
40
+ it "should create resource successfully" do
41
+ subject.create user, repo, inputs
42
+ a_post(request_path).with(inputs).should have_been_made
43
+ end
44
+
45
+ it "should return the resource" do
46
+ issue = subject.create user, repo, inputs
47
+ issue.should be_a Hashie::Mash
48
+ end
49
+
50
+ it "should get the issue information" do
51
+ issue = subject.create(user, repo, inputs)
52
+ issue.title.should == 'Found a bug'
53
+ end
54
+ end
55
+
56
+ it_should_behave_like 'request failure' do
57
+ let(:requestable) { subject.create user, repo, inputs }
58
+ end
59
+
60
+ end # create
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:issue_id) { 1347 }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}" }
10
+ let(:inputs) {
11
+ {
12
+ "title" => "Found a bug",
13
+ "body" => "I'm having a problem with this.",
14
+ "assignee" => "octocat",
15
+ "milestone" => 1,
16
+ "labels" => [
17
+ "Label1",
18
+ "Label2"
19
+ ]
20
+ }
21
+ }
22
+
23
+ before {
24
+ stub_patch(request_path).with(inputs).
25
+ to_return(:body => body, :status => status,
26
+ :headers => {:content_type => "application/json; charset=utf-8"})
27
+ }
28
+
29
+ after { reset_authentication_for(subject) }
30
+
31
+ context "resource edited successfully" do
32
+ let(:body) { fixture("issues/issue.json") }
33
+ let(:status) { 200 }
34
+
35
+ it "should fail to edit without 'user/repo' parameters" do
36
+ expect {
37
+ subject.edit nil, repo, issue_id
38
+ }.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it "should edit the resource" do
42
+ subject.edit user, repo, issue_id, inputs
43
+ a_patch(request_path).with(inputs).should have_been_made
44
+ end
45
+
46
+ it "should return resource" do
47
+ issue = subject.edit user, repo, issue_id, inputs
48
+ issue.should be_a Hashie::Mash
49
+ end
50
+
51
+ it "should be able to retrieve information" do
52
+ issue = subject.edit user, repo, issue_id, inputs
53
+ issue.title.should == 'Found a bug'
54
+ end
55
+ end
56
+
57
+ it_should_behave_like 'request failure' do
58
+ let(:requestable) { subject.edit user, repo, issue_id, inputs }
59
+ end
60
+
61
+ end # edit
@@ -76,23 +76,23 @@ describe Github::Issues::Events do
76
76
  end
77
77
 
78
78
  it "should get the resources" do
79
- github.issues.events.list user, repo, issue_id
79
+ github.issues.events.list user, repo, :issue_id => issue_id
80
80
  a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/events").should have_been_made
81
81
  end
82
82
 
83
83
  it "should return array of resources" do
84
- events = github.issues.events.list user, repo, issue_id
84
+ events = github.issues.events.list user, repo, :issue_id => issue_id
85
85
  events.should be_an Array
86
86
  events.should have(1).items
87
87
  end
88
88
 
89
89
  it "should be a mash type" do
90
- events = github.issues.events.list user, repo, issue_id
90
+ events = github.issues.events.list user, repo, :issue_id => issue_id
91
91
  events.first.should be_a Hashie::Mash
92
92
  end
93
93
 
94
94
  it "should get issue information" do
95
- events = github.issues.events.list user, repo, issue_id
95
+ events = github.issues.events.list user, repo, :issue_id => issue_id
96
96
  events.first.actor.login.should == 'octocat'
97
97
  end
98
98
 
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:issue_id) { 1347 }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}" }
10
+
11
+ before {
12
+ stub_get(request_path).to_return(:body => body, :status => status,
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture('issues/issue.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it "should fail to get resource without issue id" do
25
+ expect { subject.get user, repo, nil }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should get the resource" do
29
+ subject.get user, repo, issue_id
30
+ a_get(request_path).should have_been_made
31
+ end
32
+
33
+ it "should get issue information" do
34
+ issue = subject.get user, repo, issue_id
35
+ issue.number.should == issue_id
36
+ issue.title.should == 'Found a bug'
37
+ end
38
+
39
+ it "should return mash" do
40
+ issue = subject.get user, repo, issue_id
41
+ issue.should be_a Hashie::Mash
42
+ end
43
+ end
44
+
45
+ it_should_behave_like 'request failure' do
46
+ let(:requestable) { subject.get user, repo, issue_id }
47
+ end
48
+
49
+ end # get
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues do
6
+
7
+ after { reset_authentication_for subject }
8
+
9
+ its(:assignees) { should be_a Github::Issues::Assignees }
10
+
11
+ its(:comments) { should be_a Github::Issues::Comments }
12
+
13
+ its(:events) { should be_a Github::Issues::Events }
14
+
15
+ its(:labels) { should be_a Github::Issues::Labels }
16
+
17
+ its(:milestones) { should be_a Github::Issues::Milestones }
18
+
19
+ end # Github::Issues
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues, '#list' do
6
+ let(:request_path) { "/issues" }
7
+ let(:body) { fixture('issues/issues.json') }
8
+ let(:status) { 200 }
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
+
19
+ it { should respond_to(:all) }
20
+
21
+ it "should get the resources" do
22
+ subject.list
23
+ a_get(request_path).should have_been_made
24
+ end
25
+
26
+ it_should_behave_like 'an array of resources' do
27
+ let(:requestable) { subject.list }
28
+ end
29
+
30
+ it "should get issue information" do
31
+ issues = subject.list
32
+ issues.first.title.should == 'Found a bug'
33
+ end
34
+
35
+ it "should yield to a block" do
36
+ yielded = []
37
+ result = subject.list { |obj| yielded << obj }
38
+ yielded.should == result
39
+ end
40
+ end
41
+
42
+ context 'for a given organization' do
43
+ let(:org) { 'github' }
44
+ let(:request_path) { "/orgs/#{org}/issues" }
45
+
46
+ it 'should get the resources' do
47
+ subject.list :org => org
48
+ a_get(request_path).should have_been_made
49
+ end
50
+ end
51
+
52
+ context 'for an user' do
53
+ let(:request_path) { "/user/issues" }
54
+
55
+ it 'should get the resources' do
56
+ subject.list :user
57
+ a_get(request_path).should have_been_made
58
+ end
59
+ end
60
+
61
+ context "for a repository" do
62
+ let(:user) { 'peter-murach' }
63
+ let(:repo) { 'github' }
64
+ let(:request_path) { "/repos/#{user}/#{repo}/issues" }
65
+
66
+ it "should get the resources" do
67
+ subject.list :user => user, :repo => repo
68
+ a_get(request_path).should have_been_made
69
+ end
70
+
71
+ it_should_behave_like 'an array of resources' do
72
+ let(:requestable) { subject.list :user => user, :repo => repo }
73
+ end
74
+
75
+ it "should get repository issue information" do
76
+ repo_issues = subject.list :user => user, :repo => repo
77
+ repo_issues.first.title.should == 'Found a bug'
78
+ end
79
+
80
+ it "should yield to a block" do
81
+ yielded = []
82
+ result = subject.list(:user => user, :repo => repo) { |obj| yielded << obj }
83
+ yielded.should == result
84
+ end
85
+ end
86
+
87
+ it_should_behave_like 'request failure' do
88
+ let(:requestable) { subject.list }
89
+ end
90
+ end # list
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Milestones, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/milestones" }
9
+ let(:inputs) {
10
+ {
11
+ "title" => "String",
12
+ "state" => "open or closed",
13
+ "description" => "String",
14
+ "due_on" => "Time"
15
+ }
16
+ }
17
+
18
+ before {
19
+ stub_post(request_path).with(inputs).
20
+ to_return(:body => body, :status => status,
21
+ :headers => {:content_type => "application/json; charset=utf-8"})
22
+ }
23
+
24
+ after { reset_authentication_for(subject) }
25
+
26
+ context "resouce created" do
27
+ let(:body) { fixture('issues/milestone.json') }
28
+ let(:status) { 201 }
29
+
30
+ it "should fail to create resource if 'title' input is missing" do
31
+ expect {
32
+ subject.create user, repo, inputs.except('title')
33
+ }.to raise_error(Github::Error::RequiredParams)
34
+ end
35
+
36
+ it "should create resource successfully" do
37
+ subject.create user, repo, inputs
38
+ a_post(request_path).with(inputs).should have_been_made
39
+ end
40
+
41
+ it "should return the resource" do
42
+ milestone = subject.create user, repo, inputs
43
+ milestone.should be_a Hashie::Mash
44
+ end
45
+
46
+ it "should get the milestone information" do
47
+ milestone = subject.create user, repo, inputs
48
+ milestone.title.should == 'v1.0'
49
+ end
50
+ end
51
+
52
+ it_should_behave_like 'request failure' do
53
+ let(:requestable) { subject.create user, repo, inputs }
54
+ end
55
+
56
+ end # create