github_api 0.8.0 → 0.8.1

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 (53) hide show
  1. data/features/gists/comments.feature +8 -8
  2. data/lib/github_api/gists/comments.rb +15 -15
  3. data/lib/github_api/repos.rb +3 -1
  4. data/lib/github_api/repos/comments.rb +6 -5
  5. data/lib/github_api/requestable.rb +67 -0
  6. data/lib/github_api/version.rb +1 -1
  7. data/spec/github/activity/activity_spec.rb +2 -0
  8. data/spec/github/activity/events/issue_spec.rb +8 -20
  9. data/spec/github/activity/events/network_spec.rb +8 -20
  10. data/spec/github/activity/events/org_spec.rb +8 -18
  11. data/spec/github/activity/events/performed_spec.rb +13 -31
  12. data/spec/github/activity/events/public_spec.rb +7 -18
  13. data/spec/github/activity/events/received_spec.rb +12 -31
  14. data/spec/github/activity/events/repository_spec.rb +8 -20
  15. data/spec/github/activity/events/user_org_spec.rb +8 -20
  16. data/spec/github/activity/notifications/list_spec.rb +4 -11
  17. data/spec/github/activity/starring/list_spec.rb +8 -21
  18. data/spec/github/activity/watching/list_spec.rb +4 -18
  19. data/spec/github/gists/comments_spec.rb +24 -23
  20. data/spec/github/git_data/blobs/create_spec.rb +62 -0
  21. data/spec/github/git_data/blobs/get_spec.rb +49 -0
  22. data/spec/github/git_data/blobs_spec.rb +0 -116
  23. data/spec/github/repos/branch_spec.rb +3 -9
  24. data/spec/github/repos/branches_spec.rb +5 -13
  25. data/spec/github/repos/collaborators/add_spec.rb +37 -0
  26. data/spec/github/repos/collaborators/get_spec.rb +51 -0
  27. data/spec/github/repos/collaborators/list_spec.rb +51 -0
  28. data/spec/github/repos/collaborators/remove_spec.rb +37 -0
  29. data/spec/github/repos/collaborators_spec.rb +1 -176
  30. data/spec/github/repos/comments/create_spec.rb +2 -33
  31. data/spec/github/repos/comments/delete_spec.rb +3 -9
  32. data/spec/github/repos/comments/get_spec.rb +3 -9
  33. data/spec/github/repos/comments/list_spec.rb +16 -40
  34. data/spec/github/repos/comments/update_spec.rb +5 -11
  35. data/spec/github/repos/commits/get_spec.rb +3 -9
  36. data/spec/github/repos/commits/list_spec.rb +9 -20
  37. data/spec/github/repos/contributors_spec.rb +5 -13
  38. data/spec/github/repos/delete_spec.rb +3 -8
  39. data/spec/github/repos/downloads/create_spec.rb +3 -9
  40. data/spec/github/repos/downloads/delete_spec.rb +3 -9
  41. data/spec/github/repos/downloads/get_spec.rb +5 -12
  42. data/spec/github/repos/downloads/list_spec.rb +8 -18
  43. data/spec/github/repos/edit_spec.rb +3 -9
  44. data/spec/github/repos/forks/create_spec.rb +3 -9
  45. data/spec/github/repos/forks/list_spec.rb +8 -21
  46. data/spec/github/repos/get_spec.rb +3 -9
  47. data/spec/github/repos/list_spec.rb +8 -7
  48. data/spec/github/repos_spec.rb +2 -0
  49. data/spec/shared/api_interface_behaviour.rb +15 -0
  50. data/spec/shared/array_of_resources_behaviour.rb +15 -0
  51. data/spec/shared/request_failure_behaviour.rb +16 -0
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +43 -33
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::GitData::Blobs, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/git/blobs/#{sha}" }
10
+
11
+ before {
12
+ stub_get(request_path).
13
+ to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resource found" do
20
+ let(:body) { fixture('git_data/blob.json') }
21
+ let(:status) { 200 }
22
+
23
+ it { should respond_to :find }
24
+
25
+ it "should fail to get resource without sha" do
26
+ expect { subject.get user, repo, nil }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should get the resource" do
30
+ subject.get user, repo, sha
31
+ a_get(request_path).should have_been_made
32
+ end
33
+
34
+ it "should get blob information" do
35
+ blob = subject.get user, repo, sha
36
+ blob.content.should eql "Content of the blob"
37
+ end
38
+
39
+ it "should return mash" do
40
+ blob = subject.get user, repo, sha
41
+ blob.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, sha }
47
+ end
48
+
49
+ end # get
@@ -3,123 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Github::GitData::Blobs do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
- let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
10
-
11
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
12
6
 
13
7
  it { described_class::VALID_BLOB_PARAM_NAMES.should_not be_nil }
14
8
 
15
- describe "#get" do
16
- it { github.git_data.blobs.should respond_to :find }
17
-
18
- context "resource found" do
19
- before do
20
- stub_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").
21
- to_return(:body => fixture('git_data/blob.json'),
22
- :status => 200,
23
- :headers => {:content_type => "application/json; charset=utf-8"})
24
- end
25
-
26
- it "should fail to get resource without sha" do
27
- expect {
28
- github.git_data.blobs.get user, repo, nil
29
- }.to raise_error(ArgumentError)
30
- end
31
-
32
- it "should get the resource" do
33
- github.git_data.blobs.get user, repo, sha
34
- a_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").should have_been_made
35
- end
36
-
37
- it "should get blob information" do
38
- blob = github.git_data.blobs.get user, repo, sha
39
- blob.content.should eql "Content of the blob"
40
- end
41
-
42
- it "should return mash" do
43
- blob = github.git_data.blobs.get user, repo, sha
44
- blob.should be_a Hashie::Mash
45
- end
46
- end
47
-
48
- context "resource not found" do
49
- before do
50
- stub_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").
51
- to_return(:body => fixture('git_data/blob.json'),
52
- :status => 404,
53
- :headers => {:content_type => "application/json; charset=utf-8"})
54
- end
55
-
56
- it "should fail to retrive resource" do
57
- expect {
58
- github.git_data.blobs.get user, repo, sha
59
- }.to raise_error(Github::Error::NotFound)
60
- end
61
- end
62
- end # get
63
-
64
- describe "#create" do
65
- let(:inputs) {
66
- {
67
- "content" => "Content of the blob",
68
- "encoding" => "utf-8",
69
- "unrelated" => 'giberrish'
70
- }
71
- }
72
-
73
- context "resouce created" do
74
- before do
75
- stub_post("/repos/#{user}/#{repo}/git/blobs").
76
- with(inputs.except('unrelated')).
77
- to_return(:body => fixture('git_data/blob_sha.json'),
78
- :status => 201,
79
- :headers => {:content_type => "application/json; charset=utf-8"})
80
- end
81
-
82
- it "should fail to create resource if 'content' input is missing" do
83
- expect {
84
- github.git_data.blobs.create user, repo, inputs.except('content')
85
- }.to raise_error(Github::Error::RequiredParams)
86
- end
87
-
88
- it "should fail to create resource if 'encoding' input is missing" do
89
- expect {
90
- github.git_data.blobs.create user, repo, inputs.except('encoding')
91
- }.to raise_error(Github::Error::RequiredParams)
92
- end
93
-
94
- it "should create resource successfully" do
95
- github.git_data.blobs.create user, repo, inputs
96
- a_post("/repos/#{user}/#{repo}/git/blobs").with(inputs).should have_been_made
97
- end
98
-
99
- it "should return the resource" do
100
- blob_sha = github.git_data.blobs.create user, repo, inputs
101
- blob_sha.should be_a Hashie::Mash
102
- end
103
-
104
- it "should get the blob information" do
105
- blob_sha = github.git_data.blobs.create user, repo, inputs
106
- blob_sha.sha.should == sha
107
- end
108
- end
109
-
110
- context "failed to create resource" do
111
- before do
112
- stub_post("/repos/#{user}/#{repo}/git/blobs").with(inputs).
113
- to_return(:body => fixture('git_data/blob_sha.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
114
-
115
- end
116
-
117
- it "should faile to retrieve resource" do
118
- expect {
119
- github.git_data.blobs.create user, repo, inputs
120
- }.to raise_error(Github::Error::NotFound)
121
- end
122
- end
123
- end # create
124
-
125
9
  end # Github::GitData::Blobs
@@ -35,14 +35,8 @@ describe Github::Repos, '#branch' do
35
35
  end
36
36
  end
37
37
 
38
- context "resource not found" do
39
- let(:body) { '' }
40
- let(:status) { 404 }
41
-
42
- it "should fail to get resource" do
43
- expect {
44
- subject.branch user, repo, branch
45
- }.to raise_error(Github::Error::NotFound)
46
- end
38
+ it_should_behave_like 'request failure' do
39
+ let(:requestable) { subject.branch user, repo, branch }
47
40
  end
41
+
48
42
  end # branch
@@ -31,10 +31,8 @@ describe Github::Repos, '#branches' do
31
31
  a_get(request_path).should have_been_made
32
32
  end
33
33
 
34
- it "should return array of resources" do
35
- branches = subject.branches user, repo
36
- branches.should be_an Array
37
- branches.should have(1).items
34
+ it_should_behave_like 'an array of resources' do
35
+ let(:requestable) { subject.branches user, repo }
38
36
  end
39
37
 
40
38
  it "should get branch information" do
@@ -49,14 +47,8 @@ describe Github::Repos, '#branches' do
49
47
  end
50
48
  end
51
49
 
52
- context "resource not found" do
53
- let(:body) { '' }
54
- let(:status) { 404 }
55
-
56
- it "should fail to get resource" do
57
- expect {
58
- subject.branches user, repo
59
- }.to raise_error(Github::Error::NotFound)
60
- end
50
+ it_should_behave_like 'request failure' do
51
+ let(:requestable) { subject.branches user, repo }
61
52
  end
53
+
62
54
  end # branches
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Collaborators, '#add' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:collaborator) { 'octocat' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/collaborators/#{collaborator}" }
10
+
11
+ before {
12
+ stub_put(request_path).
13
+ to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resouce added" do
20
+ let(:body) { '' }
21
+ let(:status) { 204 }
22
+
23
+ it "should fail to add resource if 'collaborator' input is missing" do
24
+ expect { subject.add user, repo, nil }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it "should add resource successfully" do
28
+ subject.add user, repo, collaborator
29
+ a_put(request_path).should have_been_made
30
+ end
31
+ end
32
+
33
+ it_should_behave_like 'request failure' do
34
+ let(:requestable) { subject.add user, repo, collaborator }
35
+ end
36
+
37
+ end # add
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Collaborators, '#collaborator?' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:collaborator) { 'octocat' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/collaborators/#{collaborator}" }
10
+
11
+ before {
12
+ stub_get(request_path).
13
+ to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resource found " do
20
+ let(:body) { '' }
21
+ let(:status) { 204 }
22
+
23
+ it "should fail to get resource without collaborator name" do
24
+ expect {
25
+ subject.collaborator? user, repo, nil
26
+ }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should get the resource" do
30
+ subject.collaborator? user, repo, collaborator
31
+ a_get(request_path).should have_been_made
32
+ end
33
+
34
+ it "should find collaborator" do
35
+ subject.should_receive(:collaborator?).
36
+ with(user, repo, collaborator) { true }
37
+ subject.collaborator? user, repo, collaborator
38
+ end
39
+ end
40
+
41
+ context "resource not found" do
42
+ let(:body) { '' }
43
+ let(:status) { 404 }
44
+
45
+ it "should fail to retrieve resource" do
46
+ subject.should_receive(:collaborator?).
47
+ with(user, repo, collaborator) { false }
48
+ subject.collaborator? user, repo, collaborator
49
+ end
50
+ end
51
+ end # collaborator?
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Collaborators, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/collaborators" }
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
+ context "resource found" do
19
+ let(:body) { fixture('repos/collaborators.json') }
20
+ let(:status) { 200 }
21
+
22
+ it "should fail to get resource without username" do
23
+ expect { subject.list }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should get the resources" do
27
+ subject.list user, repo
28
+ a_get(request_path).should have_been_made
29
+ end
30
+
31
+ it_should_behave_like 'an array of resources' do
32
+ let(:requestable) { subject.list user, repo }
33
+ end
34
+
35
+ it "should get collaborator information" do
36
+ collaborators = subject.list user, repo
37
+ collaborators.first.login.should == 'octocat'
38
+ end
39
+
40
+ it "should yield to a block" do
41
+ yielded = []
42
+ result = subject.list(user, repo) { |obj| yielded << obj }
43
+ yielded.should == result
44
+ end
45
+ end
46
+
47
+ it_should_behave_like 'request failure' do
48
+ let(:requestable) { subject.list user, repo }
49
+ end
50
+
51
+ end # list
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Collaborators, '#remove' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:collaborator) { 'octocat' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/collaborators/#{collaborator}" }
10
+
11
+ before {
12
+ stub_delete(request_path).
13
+ to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resouce removed" do
20
+ let(:body) { '' }
21
+ let(:status) { 204 }
22
+
23
+ it "should fail to add resource if 'collaborator' input is missing" do
24
+ expect { subject.remove user, repo, nil }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it "should add resource successfully" do
28
+ subject.remove user, repo, collaborator
29
+ a_delete(request_path).should have_been_made
30
+ end
31
+ end
32
+
33
+ it_should_behave_like 'request failure' do
34
+ let(:requestable) { subject.remove user, repo, collaborator }
35
+ end
36
+
37
+ end # remove
@@ -1,182 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Repos::Collaborators do
4
- let(:github) { Github.new }
5
- let(:user) { 'peter-murach' }
6
- let(:repo) { 'github' }
7
- let(:collaborator) { 'octocat' }
8
4
 
9
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
10
-
11
- describe "#list" do
12
- context "resource found" do
13
- before do
14
- stub_get("/repos/#{user}/#{repo}/collaborators").
15
- to_return(:body => fixture('repos/collaborators.json'),
16
- :status => 200,
17
- :headers => {:content_type => "application/json; charset=utf-8"})
18
- end
19
-
20
- it "should fail to get resource without username" do
21
- expect {
22
- github.repos.collaborators.list
23
- }.to raise_error(ArgumentError)
24
- end
25
-
26
- it "should get the resources" do
27
- github.repos.collaborators.list user, repo
28
- a_get("/repos/#{user}/#{repo}/collaborators").should have_been_made
29
- end
30
-
31
- it "should return array of resources" do
32
- collaborators = github.repos.collaborators.list user, repo
33
- collaborators.should be_an Array
34
- collaborators.should have(1).items
35
- end
36
-
37
- it "should be a mash type" do
38
- collaborators = github.repos.collaborators.list user, repo
39
- collaborators.first.should be_a Hashie::Mash
40
- end
41
-
42
- it "should get collaborator information" do
43
- collaborators = github.repos.collaborators.list user, repo
44
- collaborators.first.login.should == 'octocat'
45
- end
46
-
47
- it "should yield to a block" do
48
- github.repos.collaborators.should_receive(:list).
49
- with(user, repo).and_yield('web')
50
- github.repos.collaborators.list(user, repo) { |param| 'web' }
51
- end
52
- end
53
-
54
- context "resource not found" do
55
- before do
56
- stub_get("/repos/#{user}/#{repo}/collaborators").
57
- to_return(:body => "", :status => [404, "Not Found"],
58
- :headers => {:content_type => "application/json; charset=utf-8"})
59
- end
60
-
61
- it "should return 404 with a message 'Not Found'" do
62
- expect {
63
- github.repos.collaborators.list user, repo
64
- }.to raise_error(Github::Error::NotFound)
65
- end
66
- end
67
- end # collaborators
68
-
69
- describe "collaborator?" do
70
- context "resource found " do
71
- before do
72
- stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
73
- to_return(:body => '', :status => 204,
74
- :headers => {:content_type => "application/json; charset=utf-8"})
75
- end
76
-
77
- it "should fail to get resource without collaborator name" do
78
- expect {
79
- github.repos.collaborators.collaborator? user, repo, nil
80
- }.to raise_error(ArgumentError)
81
- end
82
-
83
- it "should get the resource" do
84
- github.repos.collaborators.collaborator? user, repo, collaborator
85
- a_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
86
- should have_been_made
87
- end
88
-
89
- it "should find collaborator" do
90
- github.repos.should_receive(:collaborator?).
91
- with(user, repo, collaborator) { true }
92
- github.repos.collaborator? user, repo, collaborator
93
- end
94
- end
95
-
96
- context "resource not found" do
97
- before do
98
- stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
99
- to_return(:body => '', :status => 404,
100
- :headers => {:content_type => "application/json; charset=utf-8"})
101
- end
102
-
103
- it "should fail to retrieve resource" do
104
- github.repos.should_receive(:collaborator?).
105
- with(user, repo, collaborator) { false }
106
- github.repos.collaborator? user, repo, collaborator
107
- end
108
- end
109
- end # collaborator?
110
-
111
- describe "#add" do
112
- context "resouce added" do
113
- before do
114
- stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
115
- to_return(:body => '', :status => 204,
116
- :headers => {:content_type => "application/json; charset=utf-8"})
117
- end
118
-
119
- it "should fail to add resource if 'collaborator' input is missing" do
120
- expect {
121
- github.repos.collaborators.add user, repo, nil
122
- }.to raise_error(ArgumentError)
123
- end
124
-
125
- it "should add resource successfully" do
126
- github.repos.collaborators.add user, repo, collaborator
127
- a_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
128
- end
129
- end
130
-
131
- context "failed to add resource" do
132
- before do
133
- stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
134
- to_return(:body => '', :status => 404,
135
- :headers => {:content_type => "application/json; charset=utf-8"})
136
- end
137
-
138
- it "should fail to add resource" do
139
- expect {
140
- github.repos.collaborators.add user, repo, collaborator
141
- }.to raise_error(Github::Error::NotFound)
142
- end
143
- end
144
- end # add
145
-
146
- describe "#remove" do
147
- context "resouce removed" do
148
- before do
149
- stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
150
- to_return(:body => '', :status => 204,
151
- :headers => {:content_type => "application/json; charset=utf-8"})
152
- end
153
-
154
- it "should fail to add resource if 'collaborator' input is missing" do
155
- expect {
156
- github.repos.collaborators.remove user, repo, nil
157
- }.to raise_error(ArgumentError)
158
- end
159
-
160
- it "should add resource successfully" do
161
- github.repos.collaborators.remove user, repo, collaborator
162
- a_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
163
- should have_been_made
164
- end
165
- end
166
-
167
- context "failed to remove resource" do
168
- before do
169
- stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
170
- to_return(:body => '', :status => 404,
171
- :headers => {:content_type => "application/json; charset=utf-8"})
172
- end
173
-
174
- it "should fail to remove resource" do
175
- expect {
176
- github.repos.collaborators.remove user, repo, collaborator
177
- }.to raise_error(Github::Error::NotFound)
178
- end
179
- end
180
- end # remove
5
+ it_should_behave_like 'api interface'
181
6
 
182
7
  end # Github::Repos::Collaborators