github_api 0.4.3 → 0.4.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.md +10 -4
- data/features/cassettes/gists/comments/all.yml +121 -0
- data/features/cassettes/gists/comments/first.yml +46 -0
- data/features/gists/comments.feature +25 -0
- data/features/step_definitions/common_steps.rb +4 -0
- data/lib/github_api.rb +4 -1
- data/lib/github_api/api.rb +4 -82
- data/lib/github_api/api/actions.rb +14 -2
- data/lib/github_api/api_factory.rb +24 -0
- data/lib/github_api/client.rb +9 -9
- data/lib/github_api/filter.rb +56 -0
- data/lib/github_api/gists.rb +6 -2
- data/lib/github_api/gists/comments.rb +37 -16
- data/lib/github_api/ratelimit_status.rb +17 -0
- data/lib/github_api/repos/hooks.rb +8 -4
- data/lib/github_api/result.rb +4 -0
- data/lib/github_api/validation.rb +49 -0
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/gists/comment.json +13 -0
- data/spec/fixtures/gists/comments.json +15 -0
- data/spec/github/api_factory_spec.rb +14 -0
- data/spec/github/filter_spec.rb +82 -0
- data/spec/github/gists/comments_spec.rb +253 -1
- data/spec/github/repos/hooks_spec.rb +22 -6
- data/spec/github/result_spec.rb +6 -0
- data/spec/github/validation_spec.rb +61 -0
- metadata +14 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
module Github
|
2
|
+
module Filter
|
3
|
+
|
4
|
+
def process_params(*args)
|
5
|
+
yield self if block_given?
|
6
|
+
end
|
7
|
+
|
8
|
+
def normalize(params)
|
9
|
+
_normalize_params_keys params
|
10
|
+
end
|
11
|
+
|
12
|
+
def filter(keys, params)
|
13
|
+
_filter_params_keys(keys, params)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Turns any keys from nested hashes including nested arrays into strings
|
17
|
+
def _normalize_params_keys(params) # :nodoc:
|
18
|
+
case params
|
19
|
+
when Hash
|
20
|
+
params.keys.each do |k|
|
21
|
+
params[k.to_s] = params.delete(k)
|
22
|
+
_normalize_params_keys(params[k.to_s])
|
23
|
+
end
|
24
|
+
when Array
|
25
|
+
params.map! do |el|
|
26
|
+
_normalize_params_keys(el)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
params.to_s
|
30
|
+
end
|
31
|
+
return params
|
32
|
+
end
|
33
|
+
|
34
|
+
# Removes any keys from nested hashes that don't match predefiend keys
|
35
|
+
def _filter_params_keys(keys, params, options={:recursive => true}) # :nodoc:
|
36
|
+
case params
|
37
|
+
when Hash
|
38
|
+
params.keys.each do |k, v|
|
39
|
+
unless (keys.include?(k) or Github::Validation::VALID_API_KEYS.include?(k))
|
40
|
+
params.delete(k)
|
41
|
+
else
|
42
|
+
_filter_params_keys(keys, params[k]) if options[:recursive]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
when Array
|
46
|
+
params.map! do |el|
|
47
|
+
_filter_params_keys(keys, el) if options[:recursive]
|
48
|
+
end
|
49
|
+
else
|
50
|
+
params
|
51
|
+
end
|
52
|
+
return params
|
53
|
+
end
|
54
|
+
|
55
|
+
end # Filter
|
56
|
+
end # Github
|
data/lib/github_api/gists.rb
CHANGED
@@ -36,7 +36,9 @@ module Github
|
|
36
36
|
#
|
37
37
|
def gists(user_name=nil, params={})
|
38
38
|
_update_user_repo_params(user_name)
|
39
|
-
|
39
|
+
process_params do
|
40
|
+
normalize params
|
41
|
+
end
|
40
42
|
|
41
43
|
response = if user
|
42
44
|
get("/users/#{user}/gists", params)
|
@@ -57,7 +59,9 @@ module Github
|
|
57
59
|
# @github.gists.starred
|
58
60
|
#
|
59
61
|
def starred(params={})
|
60
|
-
|
62
|
+
process_params do
|
63
|
+
normalize params
|
64
|
+
end
|
61
65
|
|
62
66
|
response = get("/gists/starred", params)
|
63
67
|
return response unless block_given?
|
@@ -4,7 +4,11 @@ module Github
|
|
4
4
|
class Gists
|
5
5
|
module Comments
|
6
6
|
|
7
|
-
REQUIRED_GIST_COMMENT_INPUTS = %w[
|
7
|
+
REQUIRED_GIST_COMMENT_INPUTS = %w[
|
8
|
+
body
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
ALLOWED_GIST_COMMENT_INPUTS = %w[
|
8
12
|
body
|
9
13
|
mime_type
|
10
14
|
resource
|
@@ -14,72 +18,89 @@ module Github
|
|
14
18
|
#
|
15
19
|
# = Examples
|
16
20
|
# @github = Github.new
|
17
|
-
# @github.gists.
|
21
|
+
# @github.gists.comments 'gist-id'
|
18
22
|
#
|
19
|
-
def
|
23
|
+
def comments(gist_id, params={})
|
20
24
|
_normalize_params_keys(params)
|
25
|
+
_validate_presence_of(gist_id)
|
21
26
|
_merge_mime_type(:gist_comment, params)
|
22
27
|
|
23
|
-
get("/gists/#{gist_id}/comments", params)
|
28
|
+
response = get("/gists/#{gist_id}/comments", params)
|
29
|
+
return response unless block_given?
|
30
|
+
response.each { |el| yield el }
|
24
31
|
end
|
32
|
+
alias :list_comments :comments
|
33
|
+
alias :gist_comments :comments
|
25
34
|
|
26
35
|
# Get a single comment
|
27
36
|
#
|
28
37
|
# = Examples
|
29
38
|
# @github = Github.new
|
30
|
-
# @github.gists.
|
39
|
+
# @github.gists.comment 'comment-id'
|
31
40
|
#
|
32
|
-
def
|
41
|
+
def comment(comment_id, params={})
|
33
42
|
_normalize_params_keys(params)
|
43
|
+
_validate_presence_of(comment_id)
|
34
44
|
_merge_mime_type(:gist_comment, params)
|
35
45
|
|
36
46
|
get("/gists/comments/#{comment_id}", params)
|
37
47
|
end
|
48
|
+
alias :gist_comment :comment
|
49
|
+
alias :get_comment :comment
|
38
50
|
|
39
51
|
# Create a comment
|
40
52
|
#
|
41
53
|
# = Examples
|
42
54
|
# @github = Github.new
|
43
|
-
# @github.gists.
|
55
|
+
# @github.gists.create_comment 'gist-id'
|
44
56
|
#
|
45
|
-
def
|
57
|
+
def create_comment(gist_id, params={})
|
46
58
|
_normalize_params_keys(params)
|
47
59
|
_merge_mime_type(:gist_comment, params)
|
48
|
-
_filter_params_keys(
|
60
|
+
_filter_params_keys(ALLOWED_GIST_COMMENT_INPUTS, params)
|
49
61
|
|
50
|
-
|
62
|
+
unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
|
63
|
+
raise ArgumentError, "Required inputs are: :body"
|
64
|
+
end
|
51
65
|
|
52
66
|
post("/gists/#{gist_id}/comments", params)
|
53
67
|
end
|
68
|
+
alias :create_gist_comment :create_comment
|
54
69
|
|
55
70
|
# Edit a comment
|
56
71
|
#
|
57
72
|
# = Examples
|
58
73
|
# @github = Github.new
|
59
|
-
# @github.gists.
|
74
|
+
# @github.gists.edit_comment 'comment-id'
|
60
75
|
#
|
61
|
-
def
|
76
|
+
def edit_comment(comment_id, params={})
|
62
77
|
_normalize_params_keys(params)
|
78
|
+
_validate_presence_of(comment_id)
|
63
79
|
_merge_mime_type(:gist_comment, params)
|
64
|
-
_filter_params_keys(
|
80
|
+
_filter_params_keys(ALLOWED_GIST_COMMENT_INPUTS, params)
|
65
81
|
|
66
|
-
|
82
|
+
unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
|
83
|
+
raise ArgumentError, "Required inputs are: :body"
|
84
|
+
end
|
67
85
|
|
68
86
|
patch("/gists/comments/#{comment_id}", params)
|
69
87
|
end
|
88
|
+
alias :edit_gist_comment :edit_comment
|
70
89
|
|
71
90
|
# Delete a comment
|
72
91
|
#
|
73
92
|
# = Examples
|
74
93
|
# @github = Github.new
|
75
|
-
# @github.gists.
|
94
|
+
# @github.gists.delete_comment 'comment-id'
|
76
95
|
#
|
77
|
-
def
|
96
|
+
def delete_comment(comment_id, params={})
|
78
97
|
_normalize_params_keys(params)
|
98
|
+
_validate_presence_of(comment_id)
|
79
99
|
_merge_mime_type(:gist_comment, params)
|
80
100
|
|
81
101
|
delete("/gists/comments/#{comment_id}", params)
|
82
102
|
end
|
103
|
+
alias :delete_gist_comment :delete_comment
|
83
104
|
|
84
105
|
end # Comments
|
85
106
|
end # Gists
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Github
|
2
|
+
class RatelimitStatus
|
3
|
+
include Github::Constants
|
4
|
+
|
5
|
+
attr_reader :ratelimit_limit, :ratelimit_remaining
|
6
|
+
|
7
|
+
def initialize(env)
|
8
|
+
@env = env
|
9
|
+
@ratelimit_limit = env[:response_headers][RATELIMIT_LIMIT]
|
10
|
+
@ratelimit_remaining = env[:response_headers][RATELIMIT_REMAINING]
|
11
|
+
end
|
12
|
+
|
13
|
+
def ratelimit_reset_time
|
14
|
+
@ratelimit_reset_time ||= Time.parse(@env[:reponse_headers]['date'])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -96,9 +96,11 @@ module Github
|
|
96
96
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
97
97
|
|
98
98
|
_normalize_params_keys(params)
|
99
|
-
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
99
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params, :recursive => false)
|
100
100
|
|
101
|
-
|
101
|
+
unless _validate_inputs(REQUIRED_PARAMS, params)
|
102
|
+
raise ArgumentError, "Required parameters are: name, config"
|
103
|
+
end
|
102
104
|
|
103
105
|
post("/repos/#{user}/#{repo}/hooks", params)
|
104
106
|
end
|
@@ -130,9 +132,11 @@ module Github
|
|
130
132
|
_validate_presence_of hook_id
|
131
133
|
|
132
134
|
_normalize_params_keys(params)
|
133
|
-
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
135
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params, :recursive => false)
|
134
136
|
|
135
|
-
|
137
|
+
unless _validate_inputs(REQUIRED_PARAMS, params)
|
138
|
+
raise ArgumentError, "Required parameters are: name, config"
|
139
|
+
end
|
136
140
|
|
137
141
|
patch("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
138
142
|
end
|
data/lib/github_api/result.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Github
|
4
|
+
module Validation
|
5
|
+
|
6
|
+
VALID_API_KEYS = [
|
7
|
+
'page',
|
8
|
+
'per_page',
|
9
|
+
'jsonp_callback'
|
10
|
+
]
|
11
|
+
|
12
|
+
# Ensures that esential input parameters are present before request is made
|
13
|
+
#
|
14
|
+
def _validate_inputs(required, provided)
|
15
|
+
required.all? do |key|
|
16
|
+
provided.has_deep_key? key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Ensures that esential arguments are present before request is made
|
21
|
+
#
|
22
|
+
def _validate_presence_of(*params)
|
23
|
+
params.each do |param|
|
24
|
+
raise ArgumentError, "parameter cannot be nil" if param.nil?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Check if user or repository parameters are passed
|
29
|
+
#
|
30
|
+
def _validate_user_repo_params(user_name, repo_name)
|
31
|
+
raise ArgumentError, "[user] parameter cannot be nil" if user_name.nil?
|
32
|
+
raise ArgumentError, "[repo] parameter cannot be nil" if repo_name.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Ensures that hash values contain predefined values
|
36
|
+
#
|
37
|
+
def _validate_params_values(permitted, params)
|
38
|
+
params.each do |k, v|
|
39
|
+
next unless permitted.keys.include?(k)
|
40
|
+
if permitted[k].is_a?(Array) && !permitted[k].include?(params[k])
|
41
|
+
raise ArgumentError, "Wrong value for #{k}, allowed: #{permitted[k].join(', ')}"
|
42
|
+
elsif permitted[k].is_a?(Regexp) && !(permitted[k] =~ params[k])
|
43
|
+
raise ArgumentError, "String does not match the parameter value."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end # Validation
|
49
|
+
end # Github
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"id": 1,
|
3
|
+
"url": "https://api.github.com/gists/comments/1",
|
4
|
+
"body": "Just commenting for the sake of commenting",
|
5
|
+
"user": {
|
6
|
+
"login": "octocat",
|
7
|
+
"id": 1,
|
8
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
9
|
+
"gravatar_id": "somehexcode",
|
10
|
+
"url": "https://api.github.com/users/octocat"
|
11
|
+
},
|
12
|
+
"created_at": "2011-04-18T23:23:56Z"
|
13
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": 1,
|
4
|
+
"url": "https://api.github.com/gists/comments/1",
|
5
|
+
"body": "Just commenting for the sake of commenting",
|
6
|
+
"user": {
|
7
|
+
"login": "octocat",
|
8
|
+
"id": 1,
|
9
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
10
|
+
"gravatar_id": "somehexcode",
|
11
|
+
"url": "https://api.github.com/users/octocat"
|
12
|
+
},
|
13
|
+
"created_at": "2011-04-18T23:23:56Z"
|
14
|
+
}
|
15
|
+
]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::ApiFactory, :type => :base do
|
4
|
+
|
5
|
+
context '#new' do
|
6
|
+
it 'throws error if klass type is ommitted' do
|
7
|
+
expect { described_class.new nil }.to raise_error(ArgumentError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'instantiates a new object' do
|
11
|
+
described_class.new('Repos').should be_a Github::Repos
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end # Github::ApiFactory
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'github_api/core_ext/hash'
|
3
|
+
|
4
|
+
describe Github::Filter, :type => :base do
|
5
|
+
|
6
|
+
let(:repos_instance) { Github::Repos.new }
|
7
|
+
let(:block) {
|
8
|
+
Proc.new do |repo|
|
9
|
+
repo = repos_instance
|
10
|
+
end
|
11
|
+
}
|
12
|
+
let(:hash) { { :a => { :b => { :c => 1 } } } }
|
13
|
+
|
14
|
+
context '#process_params' do
|
15
|
+
|
16
|
+
it 'correctly yields current api instance' do
|
17
|
+
github.repos.should_receive(:process_params).and_yield repos_instance
|
18
|
+
github.repos.process_params(&block).should eq repos_instance
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#normalize' do
|
23
|
+
it 'should call normalize on passed block' do
|
24
|
+
github.repos.process_params(&block).should respond_to :normalize
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should normalize params inside block' do
|
28
|
+
github.repos.stub(:process_params).and_yield repos_instance
|
29
|
+
github.repos.process_params do |repo|
|
30
|
+
repo.normalize hash
|
31
|
+
end
|
32
|
+
hash.all_keys.should include 'a'
|
33
|
+
hash.all_keys.should_not include :a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#filter' do
|
38
|
+
it 'should call filter on passed block' do
|
39
|
+
github.repos.process_params(&block).should respond_to :filter
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should filter params inside block' do
|
43
|
+
github.repos.stub(:process_params).and_yield repos_instance
|
44
|
+
github.repos.process_params do |repo|
|
45
|
+
repo.filter [:a], hash
|
46
|
+
end
|
47
|
+
hash.all_keys.should include :a
|
48
|
+
hash.all_keys.should_not include :b
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '#_normalize_params_keys' do
|
53
|
+
it 'converts hash keys to string' do
|
54
|
+
['a', 'b', 'c'].each do |key|
|
55
|
+
github.repos._normalize_params_keys(hash).all_keys.should include key
|
56
|
+
end
|
57
|
+
[:a, :b, :c].each do |key|
|
58
|
+
github.repos._normalize_params_keys(hash).all_keys.should_not include key
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context '#_filter_params_keys' do
|
64
|
+
it 'removes unwanted keys from hash' do
|
65
|
+
github.repos._filter_params_keys([:a], hash)
|
66
|
+
hash.all_keys.should include :a
|
67
|
+
hash.all_keys.should_not include :b
|
68
|
+
hash.all_keys.should_not include :c
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'recursively filters inputs tree' do
|
72
|
+
github.repos._filter_params_keys([:a, :b], hash)
|
73
|
+
hash.all_keys.should_not include :c
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'filters inputs tree only on top level' do
|
77
|
+
github.repos._filter_params_keys([:a, :b], hash, :recursive => false)
|
78
|
+
hash.all_keys.should include :c
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end # Github::Filter
|
@@ -1,5 +1,257 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Gists::Comments, :type => :base do
|
4
|
-
|
4
|
+
|
5
|
+
let(:gist_id) { '1' }
|
6
|
+
let(:comment_id) { 1 }
|
7
|
+
|
8
|
+
describe "#comments" do
|
9
|
+
context 'check aliases' do
|
10
|
+
it { github.gists.should respond_to :comments }
|
11
|
+
it { github.gists.should respond_to :list_comments }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'resource found' do
|
15
|
+
before do
|
16
|
+
stub_get("/gists/#{gist_id}/comments").
|
17
|
+
to_return(:body => fixture('gists/comments.json'),
|
18
|
+
:status => 200,
|
19
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "throws error if gist id not provided" do
|
23
|
+
expect { github.gists.comments nil}.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get the resources" do
|
27
|
+
github.gists.comments gist_id
|
28
|
+
a_get("/gists/#{gist_id}/comments").should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return array of resources" do
|
32
|
+
comments = github.gists.comments gist_id
|
33
|
+
comments.should be_an Array
|
34
|
+
comments.should have(1).items
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be a mash type" do
|
38
|
+
comments = github.gists.comments gist_id
|
39
|
+
comments.first.should be_a Hashie::Mash
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get gist information" do
|
43
|
+
comments = github.gists.comments gist_id
|
44
|
+
comments.first.user.login.should == 'octocat'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should yield to a block" do
|
48
|
+
github.gists.should_receive(:comments).with(gist_id).and_yield('web')
|
49
|
+
github.gists.comments(gist_id) { |param| 'web' }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'resource not found' do
|
54
|
+
before do
|
55
|
+
stub_get("/gists/#{gist_id}/comments").
|
56
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return 404 with a message 'Not Found'" do
|
60
|
+
expect {
|
61
|
+
github.gists.comments gist_id
|
62
|
+
}.to raise_error(Github::ResourceNotFound)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end # comments
|
66
|
+
|
67
|
+
describe "#comment" do
|
68
|
+
context 'check aliases' do
|
69
|
+
it { github.gists.should respond_to :comment }
|
70
|
+
it { github.gists.should respond_to :get_comment }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'resource found' do
|
74
|
+
before do
|
75
|
+
stub_get("/gists/comments/#{comment_id}").
|
76
|
+
to_return(:body => fixture('gists/comment.json'),
|
77
|
+
:status => 200,
|
78
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should fail to get resource without comment id" do
|
82
|
+
expect { github.gists.comment nil }.to raise_error(ArgumentError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should get the resource" do
|
86
|
+
github.gists.comment comment_id
|
87
|
+
a_get("/gists/comments/#{comment_id}").should have_been_made
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get comment information" do
|
91
|
+
comment = github.gists.comment comment_id
|
92
|
+
comment.id.should eq comment_id
|
93
|
+
comment.user.login.should == 'octocat'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return mash" do
|
97
|
+
comment = github.gists.comment comment_id
|
98
|
+
comment.should be_a Hashie::Mash
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'resource not found' do
|
103
|
+
before do
|
104
|
+
stub_get("/gists/comments/#{comment_id}").
|
105
|
+
to_return(:body => fixture('gists/comment.json'),
|
106
|
+
:status => 404,
|
107
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should fail to retrive resource" do
|
111
|
+
expect {
|
112
|
+
github.gists.comment comment_id
|
113
|
+
}.to raise_error(Github::ResourceNotFound)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end # comment
|
117
|
+
|
118
|
+
describe "#create_comment" do
|
119
|
+
let(:inputs) {
|
120
|
+
{ "body" =>"Just commenting for the sake of commenting", "unrelated" => true }
|
121
|
+
}
|
122
|
+
|
123
|
+
context "resouce created" do
|
124
|
+
before do
|
125
|
+
stub_post("/gists/#{gist_id}/comments").
|
126
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
127
|
+
to_return(:body => fixture('gists/comment.json'),
|
128
|
+
:status => 201,
|
129
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should fail to create resource if 'content' input is missing" do
|
133
|
+
expect {
|
134
|
+
github.gists.create_comment gist_id, inputs.except('body')
|
135
|
+
}.to raise_error(ArgumentError)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should create resource successfully" do
|
139
|
+
github.gists.create_comment gist_id, inputs
|
140
|
+
a_post("/gists/#{gist_id}/comments").with(inputs).should have_been_made
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return the resource" do
|
144
|
+
comment = github.gists.create_comment gist_id, inputs
|
145
|
+
comment.should be_a Hashie::Mash
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should get the comment information" do
|
149
|
+
comment = github.gists.create_comment gist_id, inputs
|
150
|
+
comment.user.login.should == 'octocat'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "failed to create resource" do
|
155
|
+
before do
|
156
|
+
stub_post("/gists/#{gist_id}/comments").with(inputs).
|
157
|
+
to_return(:body => fixture('gists/comment.json'),
|
158
|
+
:status => 404,
|
159
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should faile to retrieve resource" do
|
163
|
+
expect {
|
164
|
+
github.gists.create_comment gist_id, inputs
|
165
|
+
}.to raise_error(Github::ResourceNotFound)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end # create_comment
|
169
|
+
|
170
|
+
describe "#edit_comment" do
|
171
|
+
let(:inputs) {
|
172
|
+
{ "body" =>"Just commenting for the sake of commenting", "unrelated" => true }
|
173
|
+
}
|
174
|
+
|
175
|
+
context "resouce edited" do
|
176
|
+
before do
|
177
|
+
stub_patch("/gists/comments/#{comment_id}").
|
178
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
179
|
+
to_return(:body => fixture('gists/comment.json'),
|
180
|
+
:status => 201,
|
181
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should fail to create resource if 'content' input is missing" do
|
185
|
+
expect {
|
186
|
+
github.gists.edit_comment comment_id, inputs.except('body')
|
187
|
+
}.to raise_error(ArgumentError)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should create resource successfully" do
|
191
|
+
github.gists.edit_comment comment_id, inputs
|
192
|
+
a_patch("/gists/comments/#{comment_id}").with(inputs).should have_been_made
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should return the resource" do
|
196
|
+
comment = github.gists.edit_comment comment_id, inputs
|
197
|
+
comment.should be_a Hashie::Mash
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should get the comment information" do
|
201
|
+
comment = github.gists.edit_comment comment_id, inputs
|
202
|
+
comment.user.login.should == 'octocat'
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "failed to create resource" do
|
207
|
+
before do
|
208
|
+
stub_patch("/gists/comments/#{comment_id}").with(inputs).
|
209
|
+
to_return(:body => fixture('gists/comment.json'),
|
210
|
+
:status => 404,
|
211
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should faile to retrieve resource" do
|
215
|
+
expect {
|
216
|
+
github.gists.edit_comment comment_id, inputs
|
217
|
+
}.to raise_error(Github::ResourceNotFound)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end # edit_comment
|
221
|
+
|
222
|
+
describe "#delete_comment" do
|
223
|
+
context "resouce deleted" do
|
224
|
+
before do
|
225
|
+
stub_delete("/gists/comments/#{comment_id}").
|
226
|
+
to_return(:body => '',
|
227
|
+
:status => 204,
|
228
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should fail to create resource if 'content' input is missing" do
|
232
|
+
expect { github.gists.delete_comment nil }.to raise_error(ArgumentError)
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should create resource successfully" do
|
236
|
+
github.gists.delete_comment comment_id
|
237
|
+
a_delete("/gists/comments/#{comment_id}").should have_been_made
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "failed to create resource" do
|
242
|
+
before do
|
243
|
+
stub_delete("/gists/comments/#{comment_id}").
|
244
|
+
to_return(:body => fixture('gists/comment.json'),
|
245
|
+
:status => 404,
|
246
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should faile to retrieve resource" do
|
250
|
+
expect {
|
251
|
+
github.gists.delete_comment comment_id
|
252
|
+
}.to raise_error(Github::ResourceNotFound)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end # delete_comment
|
256
|
+
|
5
257
|
end # Github::Gists::Comments
|