github_api 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/README.md +2 -1
  2. data/features/README.rdoc +4 -4
  3. data/features/cassettes/gitignore/get.yml +60 -0
  4. data/features/cassettes/gitignore/get_raw.yml +224 -0
  5. data/features/cassettes/gitignore/list.yml +67 -0
  6. data/features/cassettes/issues/comments/get.yml +71 -0
  7. data/features/cassettes/issues/comments/list_issue.yml +82 -0
  8. data/features/cassettes/issues/comments/list_repo.yml +266 -0
  9. data/features/cassettes/pull_requests/comments/get.yml +159 -0
  10. data/features/cassettes/pull_requests/comments/list_pull.yml +54 -0
  11. data/features/cassettes/pull_requests/comments/list_repo.yml +54 -0
  12. data/features/cassettes/repos/list_repos.yml +129 -0
  13. data/features/cassettes/users/all.yml +256 -0
  14. data/features/gitignore.feature +37 -0
  15. data/features/issues/comments.feature +37 -0
  16. data/features/pull_requests/comments.feature +27 -0
  17. data/features/repos.feature +8 -0
  18. data/features/step_definitions/common_steps.rb +2 -0
  19. data/features/users.feature +8 -0
  20. data/lib/github_api.rb +1 -0
  21. data/lib/github_api/client.rb +5 -0
  22. data/lib/github_api/git_data/tags.rb +4 -4
  23. data/lib/github_api/gitignore.rb +56 -0
  24. data/lib/github_api/issues/comments.rb +23 -9
  25. data/lib/github_api/pull_requests/comments.rb +24 -6
  26. data/lib/github_api/repos.rb +14 -1
  27. data/lib/github_api/repos/keys.rb +4 -4
  28. data/lib/github_api/users.rb +21 -0
  29. data/lib/github_api/users/keys.rb +6 -6
  30. data/lib/github_api/version.rb +1 -1
  31. data/spec/fixtures/gitignore/template.json +4 -0
  32. data/spec/fixtures/gitignore/template_raw +1 -0
  33. data/spec/fixtures/gitignore/templates.json +9 -0
  34. data/spec/fixtures/users/users.json +9 -0
  35. data/spec/github/activity/notifications/mark_spec.rb +1 -1
  36. data/spec/github/activity/starring/starring_spec.rb +2 -2
  37. data/spec/github/activity/watching/watching_spec.rb +2 -2
  38. data/spec/github/git_data/commits/create_spec.rb +75 -0
  39. data/spec/github/git_data/commits/get_spec.rb +50 -0
  40. data/spec/github/git_data/commits_spec.rb +1 -126
  41. data/spec/github/git_data/references/create_spec.rb +67 -0
  42. data/spec/github/git_data/references/delete_spec.rb +38 -0
  43. data/spec/github/git_data/references/get_spec.rb +54 -0
  44. data/spec/github/git_data/references/list_spec.rb +77 -0
  45. data/spec/github/git_data/references/update_spec.rb +62 -0
  46. data/spec/github/git_data/references_spec.rb +1 -298
  47. data/spec/github/git_data/tags/create_spec.rb +61 -0
  48. data/spec/github/git_data/tags/get_spec.rb +48 -0
  49. data/spec/github/git_data/tags_spec.rb +0 -108
  50. data/spec/github/git_data/trees/create_spec.rb +62 -0
  51. data/spec/github/git_data/trees/get_spec.rb +69 -0
  52. data/spec/github/git_data/trees_spec.rb +0 -133
  53. data/spec/github/gitignore/get_spec.rb +54 -0
  54. data/spec/github/gitignore/list_spec.rb +42 -0
  55. data/spec/github/issues/comments_spec.rb +46 -11
  56. data/spec/github/pull_requests/comments_spec.rb +46 -11
  57. data/spec/github/pull_requests_spec.rb +3 -3
  58. data/spec/github/repos/contents/archive_spec.rb +26 -0
  59. data/spec/github/repos/contents/get_spec.rb +30 -0
  60. data/spec/github/repos/contents/readme_spec.rb +30 -0
  61. data/spec/github/repos/hooks/create_spec.rb +68 -0
  62. data/spec/github/repos/hooks/delete_spec.rb +40 -0
  63. data/spec/github/repos/hooks/edit_spec.rb +77 -0
  64. data/spec/github/repos/hooks/get_spec.rb +49 -0
  65. data/spec/github/repos/hooks/list_spec.rb +54 -0
  66. data/spec/github/repos/hooks/test_spec.rb +40 -0
  67. data/spec/github/repos/hooks_spec.rb +2 -337
  68. data/spec/github/repos/keys/create_spec.rb +50 -0
  69. data/spec/github/repos/keys/delete_spec.rb +40 -0
  70. data/spec/github/repos/keys/edit_spec.rb +40 -0
  71. data/spec/github/repos/keys/get_spec.rb +43 -0
  72. data/spec/github/repos/keys/list_spec.rb +52 -0
  73. data/spec/github/repos/keys_spec.rb +2 -213
  74. data/spec/github/repos/list_spec.rb +19 -3
  75. data/spec/github/repos/merging/merge_spec.rb +58 -0
  76. data/spec/github/repos/pub_sub_hubbub_spec.rb +16 -14
  77. data/spec/github/repos/statuses/create_spec.rb +54 -0
  78. data/spec/github/repos/statuses/list_spec.rb +53 -0
  79. data/spec/github/repos/statuses_spec.rb +1 -114
  80. data/spec/github/users/emails/add_spec.rb +33 -0
  81. data/spec/github/users/emails/delete_spec.rb +33 -0
  82. data/spec/github/users/emails/list_spec.rb +52 -0
  83. data/spec/github/users/followers/list_spec.rb +68 -0
  84. data/spec/github/users/followers_spec.rb +0 -70
  85. data/spec/github/users/get_spec.rb +66 -0
  86. data/spec/github/users/keys/create_spec.rb +51 -0
  87. data/spec/github/users/keys/delete_spec.rb +37 -0
  88. data/spec/github/users/keys/get_spec.rb +50 -0
  89. data/spec/github/users/keys/list_spec.rb +50 -0
  90. data/spec/github/users/keys/update_spec.rb +56 -0
  91. data/spec/github/users/list_spec.rb +45 -0
  92. data/spec/github/users/update_spec.rb +56 -0
  93. metadata +96 -43
  94. data/spec/github/repos/contents_spec.rb +0 -65
  95. data/spec/github/repos/merging_spec.rb +0 -71
  96. data/spec/github/repos/starring_spec.rb +0 -4
  97. data/spec/github/users/emails_spec.rb +0 -110
  98. data/spec/github/users/keys_spec.rb +0 -256
  99. data/spec/github/users_spec.rb +0 -128
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Gitignore, '#get' do
6
+ let(:template) { 'Ruby' }
7
+ let(:request_path) { "/gitignore/templates/#{template}" }
8
+
9
+
10
+ before {
11
+ stub_get(request_path).to_return(:body => body, :status => status,
12
+ :headers => {:accept => accept })
13
+ }
14
+
15
+ after { reset_authentication_for(subject) }
16
+
17
+ context "resource found" do
18
+ let(:body) { fixture("gitignore/template.json") }
19
+ let(:status) { 200 }
20
+ let(:accept) { "application/json; charset=utf-8" }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it "should fail to get resource without key" do
25
+ expect { subject.get nil }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should get the resource" do
29
+ subject.get template
30
+ a_get(request_path).should have_been_made
31
+ end
32
+
33
+ it "should get key information" do
34
+ temp = subject.get template
35
+ temp.name.should == "C"
36
+ end
37
+ end
38
+
39
+ context 'raw content' do
40
+ let(:body) { fixture("gitignore/template_raw") }
41
+ let(:status) { 200 }
42
+ let(:accept) { 'application/vnd.github.raw' }
43
+
44
+ it "should get the resource" do
45
+ subject.get template, 'mime' => 'application/vnd.github.raw'
46
+ a_get(request_path).should have_been_made
47
+ end
48
+ end
49
+
50
+ it_should_behave_like 'request failure' do
51
+ let(:accept) { 'application/json' }
52
+ let(:requestable) { subject.get template }
53
+ end
54
+ end # get
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Gitignore, '#list' do
6
+ let(:request_path) { "/gitignore/templates" }
7
+
8
+ before {
9
+ stub_get(request_path).to_return(:body => body, :status => status,
10
+ :headers => {:content_type => "application/json; charset=utf-8"})
11
+ }
12
+
13
+ after { reset_authentication_for(subject) }
14
+
15
+ context "resource found" do
16
+ let(:body) { fixture("gitignore/templates.json") }
17
+ let(:status) { 200 }
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 get template information" do
27
+ templates = subject.list
28
+ templates.first.should == 'Actionscript'
29
+ end
30
+
31
+ it "should yield to a block" do
32
+ yielded = []
33
+ result = subject.list { |obj| yielded << obj }
34
+ yielded.should == result
35
+ end
36
+ end
37
+
38
+ it_should_behave_like 'request failure' do
39
+ let(:requestable) { subject.list }
40
+ end
41
+
42
+ end # list
@@ -16,7 +16,7 @@ describe Github::Issues::Comments do
16
16
  describe '#list' do
17
17
  it { github.issues.should respond_to :all }
18
18
 
19
- context "resource found" do
19
+ context "on an issue" do
20
20
  before do
21
21
  stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/comments").
22
22
  to_return(:body => fixture('issues/comments.json'),
@@ -26,36 +26,71 @@ describe Github::Issues::Comments do
26
26
 
27
27
  it "should fail to get resource without username" do
28
28
  expect {
29
- github.issues.comments.list user, repo, nil
29
+ github.issues.comments.list user, nil
30
30
  }.to raise_error(ArgumentError)
31
31
  end
32
32
 
33
33
  it "should get the resources" do
34
- github.issues.comments.list user, repo, issue_id
34
+ github.issues.comments.list user, repo, :issue_id => issue_id
35
35
  a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/comments").should have_been_made
36
36
  end
37
37
 
38
38
  it "should return array of resources" do
39
- comments = github.issues.comments.list user, repo, issue_id
39
+ comments = github.issues.comments.list user, repo, :issue_id => issue_id
40
+ comments.should be_an Array
41
+ comments.should have(1).items
42
+ end
43
+
44
+ it "should be a mash type" do
45
+ comments = github.issues.comments.list user, repo, :issue_id => issue_id
46
+ comments.first.should be_a Hashie::Mash
47
+ end
48
+
49
+ it "should get issue comment information" do
50
+ comments = github.issues.comments.list user, repo, :issue_id => issue_id
51
+ comments.first.user.login.should == 'octocat'
52
+ end
53
+
54
+ it "should yield to a block" do
55
+ yielded = []
56
+ result = github.issues.comments.list(user, repo, :issue_id => issue_id) { |obj| yielded << obj }
57
+ yielded.should == result
58
+ end
59
+ end
60
+
61
+ context "in a repository" do
62
+ before do
63
+ stub_get("/repos/#{user}/#{repo}/issues/comments").
64
+ to_return(:body => fixture('issues/comments.json'),
65
+ :status => 200,
66
+ :headers => {:content_type => "application/json; charset=utf-8"})
67
+ end
68
+
69
+ it "should get the resources" do
70
+ github.issues.comments.list user, repo
71
+ a_get("/repos/#{user}/#{repo}/issues/comments").should have_been_made
72
+ end
73
+
74
+ it "should return array of resources" do
75
+ comments = github.issues.comments.list user, repo
40
76
  comments.should be_an Array
41
77
  comments.should have(1).items
42
78
  end
43
79
 
44
80
  it "should be a mash type" do
45
- comments = github.issues.comments.list user, repo, issue_id
81
+ comments = github.issues.comments.list user, repo
46
82
  comments.first.should be_a Hashie::Mash
47
83
  end
48
84
 
49
85
  it "should get issue comment information" do
50
- comments = github.issues.comments.list user, repo, issue_id
86
+ comments = github.issues.comments.list user, repo
51
87
  comments.first.user.login.should == 'octocat'
52
88
  end
53
89
 
54
90
  it "should yield to a block" do
55
- github.issues.comments.should_receive(:list).
56
- with(user, repo, issue_id).and_yield('web')
57
- github.issues.comments.list(user, repo, issue_id) { |param| 'web' }.
58
- should == 'web'
91
+ yielded = []
92
+ result = github.issues.comments.list(user, repo) { |obj| yielded << obj }
93
+ yielded.should == result
59
94
  end
60
95
  end
61
96
 
@@ -67,7 +102,7 @@ describe Github::Issues::Comments do
67
102
 
68
103
  it "should return 404 with a message 'Not Found'" do
69
104
  expect {
70
- github.issues.comments.list user, repo, issue_id
105
+ github.issues.comments.list user, repo, :issue_id => issue_id
71
106
  }.to raise_error(Github::Error::NotFound)
72
107
  end
73
108
  end
@@ -14,8 +14,7 @@ describe Github::PullRequests::Comments do
14
14
  describe "#list" do
15
15
  it { github.pull_requests.comments.should respond_to :all }
16
16
 
17
- context 'resource found' do
18
-
17
+ context 'on a pull request' do
19
18
  before do
20
19
  stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
21
20
  to_return(:body => fixture('pull_requests/comments.json'),
@@ -25,36 +24,72 @@ describe Github::PullRequests::Comments do
25
24
 
26
25
  it "throws error if comment id not provided" do
27
26
  expect {
28
- github.pull_requests.comments.list user, repo, nil
27
+ github.pull_requests.comments.list user, nil
29
28
  }.to raise_error(ArgumentError)
30
29
  end
31
30
 
32
31
  it "should get the resources" do
33
- github.pull_requests.comments.list user, repo, pull_request_id
32
+ github.pull_requests.comments.list user, repo, :request_id => pull_request_id
34
33
  a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
35
34
  should have_been_made
36
35
  end
37
36
 
38
37
  it "should return array of resources" do
39
- comments = github.pull_requests.comments.list user, repo, pull_request_id
38
+ comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
39
+ comments.should be_an Array
40
+ comments.should have(1).items
41
+ end
42
+
43
+ it "should be a mash type" do
44
+ comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
45
+ comments.first.should be_a Hashie::Mash
46
+ end
47
+
48
+ it "should get pull request comment information" do
49
+ comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
50
+ comments.first.id.should == pull_request_id
51
+ end
52
+
53
+ it "should yield to a block" do
54
+ yielded = []
55
+ result = github.pull_requests.comments.list(user, repo, :request_id => pull_request_id) { |obj| yielded << obj }
56
+ yielded.should == result
57
+ end
58
+ end
59
+
60
+ context 'in a repository' do
61
+ before do
62
+ stub_get("/repos/#{user}/#{repo}/pulls/comments").
63
+ to_return(:body => fixture('pull_requests/comments.json'),
64
+ :status => 200,
65
+ :headers => {:content_type => "application/json; charset=utf-8"})
66
+ end
67
+
68
+ it "should get the resources" do
69
+ github.pull_requests.comments.list user, repo
70
+ a_get("/repos/#{user}/#{repo}/pulls/comments").should have_been_made
71
+ end
72
+
73
+ it "should return array of resources" do
74
+ comments = github.pull_requests.comments.list user, repo
40
75
  comments.should be_an Array
41
76
  comments.should have(1).items
42
77
  end
43
78
 
44
79
  it "should be a mash type" do
45
- comments = github.pull_requests.comments.list user, repo, pull_request_id
80
+ comments = github.pull_requests.comments.list user, repo
46
81
  comments.first.should be_a Hashie::Mash
47
82
  end
48
83
 
49
84
  it "should get pull request comment information" do
50
- comments = github.pull_requests.comments.list user, repo, pull_request_id
85
+ comments = github.pull_requests.comments.list user, repo
51
86
  comments.first.id.should == pull_request_id
52
87
  end
53
88
 
54
89
  it "should yield to a block" do
55
- github.pull_requests.comments.should_receive(:list).
56
- with(user, repo, pull_request_id).and_yield('web')
57
- github.pull_requests.comments.list(user, repo, pull_request_id) {|param| 'web' }
90
+ yielded = []
91
+ result = github.pull_requests.comments.list(user, repo) { |obj| yielded << obj }
92
+ yielded.should == result
58
93
  end
59
94
  end
60
95
 
@@ -66,7 +101,7 @@ describe Github::PullRequests::Comments do
66
101
 
67
102
  it "should return 404 with a message 'Not Found'" do
68
103
  expect {
69
- github.pull_requests.comments.list user, repo, pull_request_id
104
+ github.pull_requests.comments.list user, repo, :request_id => pull_request_id
70
105
  }.to raise_error(Github::Error::NotFound)
71
106
  end
72
107
  end
@@ -57,7 +57,7 @@ describe Github::PullRequests do
57
57
  context 'resource not found' do
58
58
  before do
59
59
  stub_get("/repos/#{user}/#{repo}/pulls").
60
- to_return(:body => "", :status => [404, "Not Found"])
60
+ to_return(:body => "[]", :status => [404, "Not Found"])
61
61
  end
62
62
 
63
63
  it "should return 404 with a message 'Not Found'" do
@@ -338,7 +338,7 @@ describe Github::PullRequests do
338
338
  github.oauth_token = nil
339
339
  github.user = nil
340
340
  stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
341
- to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
341
+ to_return(:body => "[]", :status => 404, :headers => {:user_agent => github.user_agent})
342
342
  end
343
343
 
344
344
  it "should fail validation " do
@@ -354,7 +354,7 @@ describe Github::PullRequests do
354
354
 
355
355
  it "should return true if resoure found" do
356
356
  stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
357
- to_return(:body => "", :status => 200,
357
+ to_return(:body => "[]", :status => 200,
358
358
  :headers => {:user_agent => github.user_agent})
359
359
  merged = github.pull_requests.merged? user, repo, pull_request_id
360
360
  merged.should be_true
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Contents, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/#{archive_format}/#{ref}" }
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
+ let(:archive_format) { 'tarball' }
18
+ let(:ref) { 'master' }
19
+ let(:body) { '[]' }
20
+ let(:status) { 302 }
21
+
22
+ it "should get the resources" do
23
+ subject.archive user, repo, :archive_format => archive_format, :ref => ref
24
+ a_get(request_path).should have_been_made
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Contents, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/contents/#{path}" }
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
+ let(:path) { 'README.md' }
18
+ let(:body) { fixture('repos/content.json') }
19
+ let(:status) { 200 }
20
+
21
+ it "should get the resources" do
22
+ subject.get user, repo, path
23
+ a_get(request_path).should have_been_made
24
+ end
25
+
26
+ it "should get repository information" do
27
+ content = subject.get user, repo, path
28
+ content.name.should == 'README.md'
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Contents, '#readme' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/readme" }
9
+
10
+ before {
11
+ stub_get(request_path).
12
+ 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
+ let(:body) { fixture('repos/readme.json') }
19
+ let(:status) { 200 }
20
+
21
+ it "should get the resources" do
22
+ subject.readme user, repo
23
+ a_get(request_path).should have_been_made
24
+ end
25
+
26
+ it "should get readme information" do
27
+ readme = subject.readme user, repo
28
+ readme.name.should == 'README.md'
29
+ end
30
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Hooks, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/hooks" }
9
+ let(:inputs) {
10
+ {
11
+ 'name' => 'web',
12
+ 'config' => {
13
+ 'url' => "http://something.com/webhook",
14
+ 'address' => "test@example.com",
15
+ 'subdomain' => "github",
16
+ 'room' => "Commits",
17
+ 'token' => "abc123"
18
+ },
19
+ 'active' => true,
20
+ 'unrelated' => true
21
+ }
22
+ }
23
+
24
+ before {
25
+ stub_post(request_path).with(inputs.except('unrelated')).
26
+ to_return(:body => body, :status => status,
27
+ :headers => {:content_type => "application/json; charset=utf-8"})
28
+ }
29
+
30
+ after { reset_authentication_for(subject) }
31
+
32
+ context "resouce created" do
33
+ let(:body) { fixture('repos/hook.json') }
34
+ let(:status) { 201 }
35
+
36
+ it "should fail to create resource if 'name' input is missing" do
37
+ expect {
38
+ subject.create user, repo, inputs.except('name')
39
+ }.to raise_error(Github::Error::RequiredParams)
40
+ end
41
+
42
+ it "should failt to create resource if 'config' input is missing" do
43
+ expect {
44
+ subject.create user, repo, inputs.except('config')
45
+ }.to raise_error(Github::Error::RequiredParams)
46
+ end
47
+
48
+ it "should create resource successfully" do
49
+ subject.create user, repo, inputs
50
+ a_post(request_path).with(inputs).should have_been_made
51
+ end
52
+
53
+ it "should return the resource" do
54
+ hook = subject.create user, repo, inputs
55
+ hook.should be_a Hashie::Mash
56
+ end
57
+
58
+ it "should get the hook information" do
59
+ hook = subject.create user, repo, inputs
60
+ hook.name.should == 'web'
61
+ end
62
+ end
63
+
64
+ it_should_behave_like 'request failure' do
65
+ let(:requestable) { subject.create user, repo, inputs }
66
+ end
67
+
68
+ end # create