github_api 0.4.11 → 0.5.0.rc1

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 (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -12,32 +12,35 @@ describe Github::GitData::Blobs do
12
12
 
13
13
  it { described_class::VALID_BLOB_PARAM_NAMES.should_not be_nil }
14
14
 
15
- describe "blob" do
16
- it { github.git_data.should respond_to :blob }
17
- it { github.git_data.should respond_to :get_blob }
15
+ describe "#get" do
16
+ it { github.git_data.blobs.should respond_to :find }
18
17
 
19
18
  context "resource found" do
20
19
  before do
21
20
  stub_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").
22
- to_return(:body => fixture('git_data/blob.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
21
+ to_return(:body => fixture('git_data/blob.json'),
22
+ :status => 200,
23
+ :headers => {:content_type => "application/json; charset=utf-8"})
23
24
  end
24
25
 
25
26
  it "should fail to get resource without sha" do
26
- expect { github.git_data.blob(user, repo, nil)}.to raise_error(ArgumentError)
27
+ expect {
28
+ github.git_data.blobs.get user, repo, nil
29
+ }.to raise_error(ArgumentError)
27
30
  end
28
31
 
29
32
  it "should get the resource" do
30
- github.git_data.blob user, repo, sha
33
+ github.git_data.blobs.get user, repo, sha
31
34
  a_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").should have_been_made
32
35
  end
33
36
 
34
37
  it "should get blob information" do
35
- blob = github.git_data.blob user, repo, sha
38
+ blob = github.git_data.blobs.get user, repo, sha
36
39
  blob.content.should eql "Content of the blob"
37
40
  end
38
41
 
39
42
  it "should return mash" do
40
- blob = github.git_data.blob user, repo, sha
43
+ blob = github.git_data.blobs.get user, repo, sha
41
44
  blob.should be_a Hashie::Mash
42
45
  end
43
46
  end
@@ -45,18 +48,20 @@ describe Github::GitData::Blobs do
45
48
  context "resource not found" do
46
49
  before do
47
50
  stub_get("/repos/#{user}/#{repo}/git/blobs/#{sha}").
48
- to_return(:body => fixture('git_data/blob.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
51
+ to_return(:body => fixture('git_data/blob.json'),
52
+ :status => 404,
53
+ :headers => {:content_type => "application/json; charset=utf-8"})
49
54
  end
50
55
 
51
56
  it "should fail to retrive resource" do
52
57
  expect {
53
- github.git_data.blob user, repo, sha
58
+ github.git_data.blobs.get user, repo, sha
54
59
  }.to raise_error(Github::Error::NotFound)
55
60
  end
56
61
  end
57
- end # blob
62
+ end # get
58
63
 
59
- describe "create_blob" do
64
+ describe "#create" do
60
65
  let(:inputs) {
61
66
  {
62
67
  "content" => "Content of the blob",
@@ -69,33 +74,35 @@ describe Github::GitData::Blobs do
69
74
  before do
70
75
  stub_post("/repos/#{user}/#{repo}/git/blobs").
71
76
  with(:body => JSON.generate(inputs.except('unrelated'))).
72
- to_return(:body => fixture('git_data/blob_sha.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
77
+ to_return(:body => fixture('git_data/blob_sha.json'),
78
+ :status => 201,
79
+ :headers => {:content_type => "application/json; charset=utf-8"})
73
80
  end
74
81
 
75
82
  it "should fail to create resource if 'content' input is missing" do
76
83
  expect {
77
- github.git_data.create_blob user, repo, inputs.except('content')
84
+ github.git_data.blobs.create user, repo, inputs.except('content')
78
85
  }.to raise_error(Github::Error::RequiredParams)
79
86
  end
80
87
 
81
88
  it "should fail to create resource if 'encoding' input is missing" do
82
89
  expect {
83
- github.git_data.create_blob user, repo, inputs.except('encoding')
90
+ github.git_data.blobs.create user, repo, inputs.except('encoding')
84
91
  }.to raise_error(Github::Error::RequiredParams)
85
92
  end
86
93
 
87
94
  it "should create resource successfully" do
88
- github.git_data.create_blob user, repo, inputs
95
+ github.git_data.blobs.create user, repo, inputs
89
96
  a_post("/repos/#{user}/#{repo}/git/blobs").with(inputs).should have_been_made
90
97
  end
91
98
 
92
99
  it "should return the resource" do
93
- blob_sha = github.git_data.create_blob user, repo, inputs
100
+ blob_sha = github.git_data.blobs.create user, repo, inputs
94
101
  blob_sha.should be_a Hashie::Mash
95
102
  end
96
103
 
97
104
  it "should get the blob information" do
98
- blob_sha = github.git_data.create_blob user, repo, inputs
105
+ blob_sha = github.git_data.blobs.create user, repo, inputs
99
106
  blob_sha.sha.should == sha
100
107
  end
101
108
  end
@@ -109,10 +116,10 @@ describe Github::GitData::Blobs do
109
116
 
110
117
  it "should faile to retrieve resource" do
111
118
  expect {
112
- github.git_data.create_blob user, repo, inputs
119
+ github.git_data.blobs.create user, repo, inputs
113
120
  }.to raise_error(Github::Error::NotFound)
114
121
  end
115
122
  end
116
- end # create_blob
123
+ end # create
117
124
 
118
125
  end # Github::GitData::Blobs
@@ -12,9 +12,8 @@ describe Github::GitData::Commits, :type => :base do
12
12
 
13
13
  it { described_class::VALID_COMMIT_PARAM_NAMES.should_not be_nil }
14
14
 
15
- describe "commit" do
16
- it { github.git_data.should respond_to :commit }
17
- it { github.git_data.should respond_to :get_commit }
15
+ describe "#get" do
16
+ it { github.git_data.commits.should respond_to :find }
18
17
 
19
18
  context "resource found" do
20
19
  before do
@@ -24,22 +23,22 @@ describe Github::GitData::Commits, :type => :base do
24
23
 
25
24
  it "should fail to get resource without sha" do
26
25
  expect {
27
- github.git_data.commit(user, repo, nil)
26
+ github.git_data.commits.get user, repo, nil
28
27
  }.to raise_error(ArgumentError)
29
28
  end
30
29
 
31
30
  it "should get the resource" do
32
- github.git_data.commit user, repo, sha
31
+ github.git_data.commits.get user, repo, sha
33
32
  a_get("/repos/#{user}/#{repo}/git/commits/#{sha}").should have_been_made
34
33
  end
35
34
 
36
35
  it "should get commit information" do
37
- commit = github.git_data.commit user, repo, sha
36
+ commit = github.git_data.commits.get user, repo, sha
38
37
  commit.author.name.should eql "Scott Chacon"
39
38
  end
40
39
 
41
40
  it "should return mash" do
42
- commit = github.git_data.commit user, repo, sha
41
+ commit = github.git_data.commits.get user, repo, sha
43
42
  commit.should be_a Hashie::Mash
44
43
  end
45
44
  end
@@ -47,18 +46,20 @@ describe Github::GitData::Commits, :type => :base do
47
46
  context "resource not found" do
48
47
  before do
49
48
  stub_get("/repos/#{user}/#{repo}/git/commits/#{sha}").
50
- to_return(:body => fixture('git_data/commit.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
49
+ to_return(:body => fixture('git_data/commit.json'),
50
+ :status => 404,
51
+ :headers => {:content_type => "application/json; charset=utf-8"})
51
52
  end
52
53
 
53
54
  it "should fail to retrive resource" do
54
55
  expect {
55
- github.git_data.commit user, repo, sha
56
+ github.git_data.commits.get user, repo, sha
56
57
  }.to raise_error(Github::Error::NotFound)
57
58
  end
58
59
  end
59
- end # commit
60
+ end # get
60
61
 
61
- describe "create_commit" do
62
+ describe "#create" do
62
63
  let(:inputs) {
63
64
  {
64
65
  "message" => "my commit message",
@@ -84,34 +85,34 @@ describe Github::GitData::Commits, :type => :base do
84
85
 
85
86
  it "should fail to create resource if 'message' input is missing" do
86
87
  expect {
87
- github.git_data.create_commit user, repo, inputs.except('message')
88
+ github.git_data.commits.create user, repo, inputs.except('message')
88
89
  }.to raise_error(Github::Error::RequiredParams)
89
90
  end
90
91
 
91
92
  it "should fail to create resource if 'tree' input is missing" do
92
93
  expect {
93
- github.git_data.create_commit user, repo, inputs.except('tree')
94
+ github.git_data.commits.create user, repo, inputs.except('tree')
94
95
  }.to raise_error(Github::Error::RequiredParams)
95
96
  end
96
97
 
97
98
  it "should fail to create resource if 'parents' input is missing" do
98
99
  expect {
99
- github.git_data.create_commit user, repo, inputs.except('parents')
100
+ github.git_data.commits.create user, repo, inputs.except('parents')
100
101
  }.to raise_error(Github::Error::RequiredParams)
101
102
  end
102
103
 
103
104
  it "should create resource successfully" do
104
- github.git_data.create_commit user, repo, inputs
105
+ github.git_data.commits.create user, repo, inputs
105
106
  a_post("/repos/#{user}/#{repo}/git/commits").with(inputs).should have_been_made
106
107
  end
107
108
 
108
109
  it "should return the resource" do
109
- commit = github.git_data.create_commit user, repo, inputs
110
+ commit = github.git_data.commits.create user, repo, inputs
110
111
  commit.should be_a Hashie::Mash
111
112
  end
112
113
 
113
114
  it "should get the commit information" do
114
- commit = github.git_data.create_commit user, repo, inputs
115
+ commit = github.git_data.commits.create user, repo, inputs
115
116
  commit.author.name.should eql "Scott Chacon"
116
117
  end
117
118
  end
@@ -124,10 +125,10 @@ describe Github::GitData::Commits, :type => :base do
124
125
 
125
126
  it "should faile to retrieve resource" do
126
127
  expect {
127
- github.git_data.create_commit user, repo, inputs
128
+ github.git_data.commits.create user, repo, inputs
128
129
  }.to raise_error(Github::Error::NotFound)
129
130
  end
130
131
  end
131
- end # create_commit
132
+ end # create
132
133
 
133
134
  end # Github::GitData::Commits
@@ -14,13 +14,8 @@ describe Github::GitData::References do
14
14
  it { described_class::VALID_REF_PARAM_NAMES.should_not be_nil }
15
15
  it { described_class::VALID_REF_PARAM_VALUES.should_not be_nil }
16
16
 
17
- describe "references" do
18
-
19
- context 'check aliases' do
20
- it { github.git_data.should respond_to :references }
21
- it { github.git_data.should respond_to :list_references }
22
- it { github.git_data.should respond_to :get_all_references }
23
- end
17
+ describe "#list" do
18
+ it { github.git_data.references.should respond_to :all }
24
19
 
25
20
  context "get all the refernces based on sub-namespace" do
26
21
  before do
@@ -29,39 +24,42 @@ describe Github::GitData::References do
29
24
  end
30
25
 
31
26
  it "should fail to get resource without username" do
32
- expect { github.git_data.references }.to raise_error(ArgumentError)
27
+ expect {
28
+ github.git_data.references.list nil, repo
29
+ }.to raise_error(ArgumentError)
33
30
  end
34
31
 
35
32
  it "should fail to call with invalid reference" do
36
33
  expect {
37
- github.git_data.references user, repo, 'branch'
34
+ github.git_data.references.list user, repo, 'branch'
38
35
  }.to raise_error(ArgumentError)
39
36
  end
40
37
 
41
38
  it "should get the resources" do
42
- github.git_data.references user, repo, ref
39
+ github.git_data.references.list user, repo, ref
43
40
  a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
44
41
  end
45
42
 
46
43
  it "should return array of resources" do
47
- references = github.git_data.references user, repo, ref
44
+ references = github.git_data.references.list user, repo, ref
48
45
  references.should be_an Array
49
46
  references.should have(3).items
50
47
  end
51
48
 
52
49
  it "should be a mash type" do
53
- references = github.git_data.references user, repo, ref
50
+ references = github.git_data.references.list user, repo, ref
54
51
  references.first.should be_a Hashie::Mash
55
52
  end
56
53
 
57
54
  it "should get reference information" do
58
- references = github.git_data.references user, repo, ref
55
+ references = github.git_data.references.list user, repo, ref
59
56
  references.first.ref.should eql 'refs/heads/master'
60
57
  end
61
58
 
62
59
  it "should yield to a block" do
63
- github.git_data.should_receive(:references).with(user, repo, ref).and_yield('web')
64
- github.git_data.references(user, repo, ref) { |param| 'web' }
60
+ github.git_data.references.should_receive(:list).
61
+ with(user, repo, ref).and_yield('web')
62
+ github.git_data.references.list(user, repo, ref) { |param| 'web' }
65
63
  end
66
64
  end
67
65
 
@@ -72,7 +70,7 @@ describe Github::GitData::References do
72
70
  end
73
71
 
74
72
  it "should get the resources" do
75
- github.git_data.references user, repo
73
+ github.git_data.references.list user, repo
76
74
  a_get("/repos/#{user}/#{repo}/git/refs").should have_been_made
77
75
  end
78
76
  end
@@ -85,15 +83,14 @@ describe Github::GitData::References do
85
83
 
86
84
  it "should return 404 with a message 'Not Found'" do
87
85
  expect {
88
- github.git_data.references user, repo, ref
86
+ github.git_data.references.list user, repo, ref
89
87
  }.to raise_error(Github::Error::NotFound)
90
88
  end
91
89
  end
92
- end # references
90
+ end # list
93
91
 
94
- describe "reference" do
95
- it { github.git_data.should respond_to :reference }
96
- it { github.git_data.should respond_to :get_reference }
92
+ describe "#get" do
93
+ it { github.git_data.references.should respond_to :find }
97
94
 
98
95
  context "resource found" do
99
96
  before do
@@ -102,27 +99,29 @@ describe Github::GitData::References do
102
99
  end
103
100
 
104
101
  it "should fail to get resource without ref" do
105
- expect { github.git_data.reference(user, repo, nil)}.to raise_error(ArgumentError)
102
+ expect {
103
+ github.git_data.references.get user, repo, nil
104
+ }.to raise_error(ArgumentError)
106
105
  end
107
106
 
108
107
  it "should fail to get resource with wrong ref" do
109
108
  expect {
110
- github.git_data.reference user, repo, 'branch'
109
+ github.git_data.references.get user, repo, 'branch'
111
110
  }.to raise_error(ArgumentError)
112
111
  end
113
112
 
114
113
  it "should get the resource" do
115
- github.git_data.reference user, repo, ref
114
+ github.git_data.references.get user, repo, ref
116
115
  a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
117
116
  end
118
117
 
119
118
  it "should get reference information" do
120
- reference = github.git_data.reference user, repo, ref
119
+ reference = github.git_data.references.get user, repo, ref
121
120
  reference.first.ref.should eql "refs/heads/sc/featureA"
122
121
  end
123
122
 
124
123
  it "should return mash" do
125
- reference = github.git_data.reference user, repo, ref
124
+ reference = github.git_data.references.get user, repo, ref
126
125
  reference.first.should be_a Hashie::Mash
127
126
  end
128
127
  end
@@ -135,13 +134,13 @@ describe Github::GitData::References do
135
134
 
136
135
  it "should fail to retrive resource" do
137
136
  expect {
138
- github.git_data.reference user, repo, ref
137
+ github.git_data.references.get user, repo, ref
139
138
  }.to raise_error(Github::Error::NotFound)
140
139
  end
141
140
  end
142
- end # reference
141
+ end # get
143
142
 
144
- describe "create_reference" do
143
+ describe "#create" do
145
144
  let(:inputs) {
146
145
  {
147
146
  "ref" => "refs/heads/master",
@@ -159,34 +158,34 @@ describe Github::GitData::References do
159
158
 
160
159
  it "should fail to create resource if 'ref' input is missing" do
161
160
  expect {
162
- github.git_data.create_reference user, repo, inputs.except('ref')
161
+ github.git_data.references.create user, repo, inputs.except('ref')
163
162
  }.to raise_error(ArgumentError)
164
163
  end
165
164
 
166
165
  it "should fail to create resource if 'sha' input is missing" do
167
166
  expect {
168
- github.git_data.create_reference user, repo, inputs.except('sha')
167
+ github.git_data.references.create user, repo, inputs.except('sha')
169
168
  }.to raise_error(Github::Error::RequiredParams)
170
169
  end
171
170
 
172
171
  it "should fail to create resource if 'ref' is wrong" do
173
172
  expect {
174
- github.git_data.create_reference user, repo, 'branch'
173
+ github.git_data.references.create user, repo, 'branch'
175
174
  }.to raise_error(ArgumentError)
176
175
  end
177
176
 
178
177
  it "should create resource successfully" do
179
- github.git_data.create_reference user, repo, inputs
178
+ github.git_data.references.create user, repo, inputs
180
179
  a_post("/repos/#{user}/#{repo}/git/refs").with(inputs).should have_been_made
181
180
  end
182
181
 
183
182
  it "should return the resource" do
184
- reference = github.git_data.create_reference user, repo, inputs
183
+ reference = github.git_data.references.create user, repo, inputs
185
184
  reference.first.should be_a Hashie::Mash
186
185
  end
187
186
 
188
187
  it "should get the reference information" do
189
- reference = github.git_data.create_reference user, repo, inputs
188
+ reference = github.git_data.references.create user, repo, inputs
190
189
  reference.first.ref.should eql 'refs/heads/sc/featureA'
191
190
  end
192
191
  end
@@ -200,13 +199,13 @@ describe Github::GitData::References do
200
199
 
201
200
  it "should faile to retrieve resource" do
202
201
  expect {
203
- github.git_data.create_reference user, repo, inputs
202
+ github.git_data.references.create user, repo, inputs
204
203
  }.to raise_error(Github::Error::NotFound)
205
204
  end
206
205
  end
207
- end # create_reference
206
+ end # create
208
207
 
209
- describe "update_reference" do
208
+ describe "#update" do
210
209
  let(:inputs) {
211
210
  {
212
211
  "sha" => "827efc6d56897b048c772eb4087f854f46256132",
@@ -224,28 +223,29 @@ describe Github::GitData::References do
224
223
 
225
224
  it "should fail to update resource if 'sha' input is missing" do
226
225
  expect {
227
- github.git_data.update_reference user, repo, ref, inputs.except('sha')
226
+ github.git_data.references.update user, repo, ref, inputs.except('sha')
228
227
  }.to raise_error(Github::Error::RequiredParams)
229
228
  end
230
229
 
231
230
  it "should fail to update resource if 'ref' is wrong" do
232
231
  expect {
233
- github.git_data.update_reference user, repo, 'branch', inputs
232
+ github.git_data.references.update user, repo, 'branch', inputs
234
233
  }.to raise_error(ArgumentError)
235
234
  end
236
235
 
237
236
  it "should update resource successfully" do
238
- github.git_data.update_reference user, repo, ref, inputs
239
- a_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).should have_been_made
237
+ github.git_data.references.update user, repo, ref, inputs
238
+ a_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").
239
+ with(inputs).should have_been_made
240
240
  end
241
241
 
242
242
  it "should return the resource" do
243
- reference = github.git_data.update_reference user, repo, ref, inputs
243
+ reference = github.git_data.references.update user, repo, ref, inputs
244
244
  reference.first.should be_a Hashie::Mash
245
245
  end
246
246
 
247
247
  it "should get the reference information" do
248
- reference = github.git_data.update_reference user, repo, ref, inputs
248
+ reference = github.git_data.references.update user, repo, ref, inputs
249
249
  reference.first.ref.should eql 'refs/heads/sc/featureA'
250
250
  end
251
251
  end
@@ -259,10 +259,47 @@ describe Github::GitData::References do
259
259
 
260
260
  it "should faile to retrieve resource" do
261
261
  expect {
262
- github.git_data.update_reference user, repo, ref, inputs
262
+ github.git_data.references.update user, repo, ref, inputs
263
+ }.to raise_error(Github::Error::NotFound)
264
+ end
265
+ end
266
+ end # update
267
+
268
+ describe "#delete" do
269
+ it { github.git_data.references.should respond_to :remove }
270
+
271
+ context "resouce delete" do
272
+ before do
273
+ stub_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").
274
+ to_return(:body => '', :status => 204,
275
+ :headers => {:content_type => "application/json; charset=utf-8"})
276
+ end
277
+
278
+ it "should fail to delete resource if 'ref' input is missing" do
279
+ expect {
280
+ github.git_data.references.delete user, repo, nil
281
+ }.to raise_error(ArgumentError)
282
+ end
283
+
284
+ it "should delete resource successfully" do
285
+ github.git_data.references.delete user, repo, ref
286
+ a_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
287
+ end
288
+ end
289
+
290
+ context "failed to create resource" do
291
+ before do
292
+ stub_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").
293
+ to_return(:body => '', :status => 404,
294
+ :headers => {:content_type => "application/json; charset=utf-8"})
295
+ end
296
+
297
+ it "should faile to retrieve resource" do
298
+ expect {
299
+ github.git_data.references.delete user, repo, ref
263
300
  }.to raise_error(Github::Error::NotFound)
264
301
  end
265
302
  end
266
- end # update_reference
303
+ end # delete
267
304
 
268
305
  end # Github::GitData::References