gisty 0.1.2 → 0.2.0

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.
@@ -0,0 +1,346 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.0.13
3
+ Date: Wed, 21 Mar 2012 12:26:39 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 200 OK
7
+ Content-Length: 12018
8
+ X-RateLimit-Limit: 5000
9
+ X-RateLimit-Remaining: 4990
10
+ ETag: "c63e34280b5765df053e029d4ad6865a"
11
+ Link: <https://api.github.com/gists?access_token=testaccesstoken&page=1>; rel="first", <https://api.github.com/gists?access_token=testaccesstoken&page=2>; rel="prev"
12
+ X-OAuth-Scopes: gist
13
+ X-Accepted-OAuth-Scopes: gist
14
+
15
+ [
16
+ {
17
+ "description": null,
18
+ "updated_at": "2009-10-14T15:33:24Z",
19
+ "git_pull_url": "git://gist.github.com/20059.git",
20
+ "comments": 0,
21
+ "files": {
22
+ "gistfile1.txt": {
23
+ "type": "text/plain",
24
+ "filename": "gistfile1.txt",
25
+ "raw_url": "https://gist.github.com/raw/20059/eab290cab6038dc3b1e6cbbc240dd657b3aad71f/gistfile1.txt",
26
+ "size": 1512,
27
+ "language": "Text"
28
+ }
29
+ },
30
+ "public": true,
31
+ "git_push_url": "git@gist.github.com:20059.git",
32
+ "created_at": "2008-10-27T09:05:04Z",
33
+ "id": "20059",
34
+ "url": "https://api.github.com/gists/20059",
35
+ "user": {
36
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
37
+ "login": "swdyh",
38
+ "url": "https://api.github.com/users/swdyh",
39
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
40
+ "id": 9168
41
+ },
42
+ "html_url": "https://gist.github.com/20059"
43
+ },
44
+ {
45
+ "description": null,
46
+ "updated_at": "2009-10-14T15:33:24Z",
47
+ "git_pull_url": "git://gist.github.com/19595.git",
48
+ "comments": 0,
49
+ "files": {
50
+ "gistfile1": {
51
+ "type": "text/plain",
52
+ "filename": "gistfile1",
53
+ "raw_url": "https://gist.github.com/raw/19595/7ad6c99c58f315de4007fb11d778d69116cb5ef9/gistfile1",
54
+ "size": 13,
55
+ "language": null
56
+ }
57
+ },
58
+ "public": true,
59
+ "git_push_url": "git@gist.github.com:19595.git",
60
+ "created_at": "2008-10-24T21:25:30Z",
61
+ "id": "19595",
62
+ "url": "https://api.github.com/gists/19595",
63
+ "user": {
64
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
65
+ "login": "swdyh",
66
+ "url": "https://api.github.com/users/swdyh",
67
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
68
+ "id": 9168
69
+ },
70
+ "html_url": "https://gist.github.com/19595"
71
+ },
72
+ {
73
+ "description": null,
74
+ "updated_at": "2009-10-14T15:33:24Z",
75
+ "git_pull_url": "git://gist.github.com/19584.git",
76
+ "comments": 0,
77
+ "files": {
78
+ "gistfile1": {
79
+ "type": "text/plain",
80
+ "filename": "gistfile1",
81
+ "raw_url": "https://gist.github.com/raw/19584/9daeafb9864cf43055ae93beb0afd6c7d144bfa4/gistfile1",
82
+ "size": 5,
83
+ "language": null
84
+ }
85
+ },
86
+ "public": true,
87
+ "git_push_url": "git@gist.github.com:19584.git",
88
+ "created_at": "2008-10-24T21:14:40Z",
89
+ "id": "19584",
90
+ "url": "https://api.github.com/gists/19584",
91
+ "user": {
92
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
93
+ "login": "swdyh",
94
+ "url": "https://api.github.com/users/swdyh",
95
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
96
+ "id": 9168
97
+ },
98
+ "html_url": "https://gist.github.com/19584"
99
+ },
100
+ {
101
+ "description": null,
102
+ "updated_at": "2009-10-14T15:33:24Z",
103
+ "git_pull_url": "git://gist.github.com/17797.git",
104
+ "comments": 0,
105
+ "files": {
106
+ "bccks nodokeshi": {
107
+ "type": "text/plain",
108
+ "filename": "bccks nodokeshi",
109
+ "raw_url": "https://gist.github.com/raw/17797/813610f26c89313ac1a1946b794e8f7b153e0988/bccks nodokeshi",
110
+ "size": 126,
111
+ "language": null
112
+ }
113
+ },
114
+ "public": true,
115
+ "git_push_url": "git@gist.github.com:17797.git",
116
+ "created_at": "2008-10-19T08:25:21Z",
117
+ "id": "17797",
118
+ "url": "https://api.github.com/gists/17797",
119
+ "user": {
120
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
121
+ "login": "swdyh",
122
+ "url": "https://api.github.com/users/swdyh",
123
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
124
+ "id": 9168
125
+ },
126
+ "html_url": "https://gist.github.com/17797"
127
+ },
128
+ {
129
+ "description": null,
130
+ "updated_at": "2009-10-14T11:58:07Z",
131
+ "git_pull_url": "git://gist.github.com/13833.git",
132
+ "comments": 0,
133
+ "files": {
134
+ "ldr_-_twittericon.user.js": {
135
+ "type": "application/javascript",
136
+ "filename": "ldr_-_twittericon.user.js",
137
+ "raw_url": "https://gist.github.com/raw/13833/5effcc65f1447b3d765adba3e86f6456d9a5883f/ldr_-_twittericon.user.js",
138
+ "size": 1623,
139
+ "language": "JavaScript"
140
+ }
141
+ },
142
+ "public": true,
143
+ "git_push_url": "git@gist.github.com:13833.git",
144
+ "created_at": "2008-09-30T14:35:57Z",
145
+ "id": "13833",
146
+ "url": "https://api.github.com/gists/13833",
147
+ "user": {
148
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
149
+ "login": "swdyh",
150
+ "url": "https://api.github.com/users/swdyh",
151
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
152
+ "id": 9168
153
+ },
154
+ "html_url": "https://gist.github.com/13833"
155
+ },
156
+ {
157
+ "description": null,
158
+ "updated_at": "2009-10-14T11:51:22Z",
159
+ "git_pull_url": "git://gist.github.com/11863.git",
160
+ "comments": 0,
161
+ "files": {
162
+ "fashionsnap_enlarge_images.user.js": {
163
+ "type": "application/javascript",
164
+ "filename": "fashionsnap_enlarge_images.user.js",
165
+ "raw_url": "https://gist.github.com/raw/11863/1d1e6e3a4dc70c1a24b07a80265f908262854a88/fashionsnap_enlarge_images.user.js",
166
+ "size": 425,
167
+ "language": "JavaScript"
168
+ }
169
+ },
170
+ "public": true,
171
+ "git_push_url": "git@gist.github.com:11863.git",
172
+ "created_at": "2008-09-21T11:58:31Z",
173
+ "id": "11863",
174
+ "url": "https://api.github.com/gists/11863",
175
+ "user": {
176
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
177
+ "login": "swdyh",
178
+ "url": "https://api.github.com/users/swdyh",
179
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
180
+ "id": 9168
181
+ },
182
+ "html_url": "https://gist.github.com/11863"
183
+ },
184
+ {
185
+ "description": null,
186
+ "updated_at": "2009-10-14T11:49:56Z",
187
+ "git_pull_url": "git://gist.github.com/11423.git",
188
+ "comments": 0,
189
+ "files": {
190
+ "hatenakeyword.user.css": {
191
+ "type": "text/css",
192
+ "filename": "hatenakeyword.user.css",
193
+ "raw_url": "https://gist.github.com/raw/11423/993d64cbd54dd1b42cb5c4ddec5834a215643b13/hatenakeyword.user.css",
194
+ "size": 201,
195
+ "language": "CSS"
196
+ }
197
+ },
198
+ "public": true,
199
+ "git_push_url": "git@gist.github.com:11423.git",
200
+ "created_at": "2008-09-18T11:36:58Z",
201
+ "id": "11423",
202
+ "url": "https://api.github.com/gists/11423",
203
+ "user": {
204
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
205
+ "login": "swdyh",
206
+ "url": "https://api.github.com/users/swdyh",
207
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
208
+ "id": 9168
209
+ },
210
+ "html_url": "https://gist.github.com/11423"
211
+ },
212
+ {
213
+ "description": null,
214
+ "updated_at": "2009-10-14T11:49:03Z",
215
+ "git_pull_url": "git://gist.github.com/11198.git",
216
+ "comments": 0,
217
+ "files": {
218
+ "userstyle for twitter home": {
219
+ "type": "text/plain",
220
+ "filename": "userstyle for twitter home",
221
+ "raw_url": "https://gist.github.com/raw/11198/8865c4e11bb72a26db7d0e9e250dff22a0e6341c/userstyle for twitter home",
222
+ "size": 547,
223
+ "language": null
224
+ }
225
+ },
226
+ "public": true,
227
+ "git_push_url": "git@gist.github.com:11198.git",
228
+ "created_at": "2008-09-17T05:30:37Z",
229
+ "id": "11198",
230
+ "url": "https://api.github.com/gists/11198",
231
+ "user": {
232
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
233
+ "login": "swdyh",
234
+ "url": "https://api.github.com/users/swdyh",
235
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
236
+ "id": 9168
237
+ },
238
+ "html_url": "https://gist.github.com/11198"
239
+ },
240
+ {
241
+ "description": null,
242
+ "updated_at": "2009-10-14T11:35:00Z",
243
+ "git_pull_url": "git://gist.github.com/7205.git",
244
+ "comments": 0,
245
+ "files": {
246
+ "Github-shirts": {
247
+ "type": "text/plain",
248
+ "filename": "Github-shirts",
249
+ "raw_url": "https://gist.github.com/raw/7205/1f5044db67b66867bb7ec08e28adc77bb19892a4/Github-shirts",
250
+ "size": 300,
251
+ "language": null
252
+ }
253
+ },
254
+ "public": true,
255
+ "git_push_url": "git@gist.github.com:7205.git",
256
+ "created_at": "2008-08-26T04:02:27Z",
257
+ "id": "7205",
258
+ "url": "https://api.github.com/gists/7205",
259
+ "user": {
260
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
261
+ "login": "swdyh",
262
+ "url": "https://api.github.com/users/swdyh",
263
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
264
+ "id": 9168
265
+ },
266
+ "html_url": "https://gist.github.com/7205"
267
+ },
268
+ {
269
+ "description": null,
270
+ "updated_at": "2009-10-14T11:35:00Z",
271
+ "git_pull_url": "git://gist.github.com/7204.git",
272
+ "comments": 0,
273
+ "files": {
274
+
275
+ },
276
+ "public": true,
277
+ "git_push_url": "git@gist.github.com:7204.git",
278
+ "created_at": "2008-08-26T04:01:28Z",
279
+ "id": "7204",
280
+ "url": "https://api.github.com/gists/7204",
281
+ "user": {
282
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
283
+ "login": "swdyh",
284
+ "url": "https://api.github.com/users/swdyh",
285
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
286
+ "id": 9168
287
+ },
288
+ "html_url": "https://gist.github.com/7204"
289
+ },
290
+ {
291
+ "description": null,
292
+ "updated_at": "2009-10-14T11:33:59Z",
293
+ "git_pull_url": "git://gist.github.com/6938.git",
294
+ "comments": 0,
295
+ "files": {
296
+ "lightbox.js": {
297
+ "type": "application/javascript",
298
+ "filename": "lightbox.js",
299
+ "raw_url": "https://gist.github.com/raw/6938/8b14e431656c3e47f81da8426c2df42378b563da/lightbox.js",
300
+ "size": 222,
301
+ "language": "JavaScript"
302
+ }
303
+ },
304
+ "public": true,
305
+ "git_push_url": "git@gist.github.com:6938.git",
306
+ "created_at": "2008-08-23T20:21:34Z",
307
+ "id": "6938",
308
+ "url": "https://api.github.com/gists/6938",
309
+ "user": {
310
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
311
+ "login": "swdyh",
312
+ "url": "https://api.github.com/users/swdyh",
313
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
314
+ "id": 9168
315
+ },
316
+ "html_url": "https://gist.github.com/6938"
317
+ },
318
+ {
319
+ "description": null,
320
+ "updated_at": "2009-10-14T11:21:36Z",
321
+ "git_pull_url": "git://gist.github.com/3668.git",
322
+ "comments": 0,
323
+ "files": {
324
+ "hhcode.js": {
325
+ "type": "application/javascript",
326
+ "filename": "hhcode.js",
327
+ "raw_url": "https://gist.github.com/raw/3668/ff1f59509325dc3c548796b9812a8b004cb90eaf/hhcode.js",
328
+ "size": 4838,
329
+ "language": "JavaScript"
330
+ }
331
+ },
332
+ "public": true,
333
+ "git_push_url": "git@gist.github.com:3668.git",
334
+ "created_at": "2008-08-01T19:15:00Z",
335
+ "id": "3668",
336
+ "url": "https://api.github.com/gists/3668",
337
+ "user": {
338
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
339
+ "login": "swdyh",
340
+ "url": "https://api.github.com/users/swdyh",
341
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
342
+ "id": 9168
343
+ },
344
+ "html_url": "https://gist.github.com/3668"
345
+ }
346
+ ]
@@ -0,0 +1,65 @@
1
+ HTTP/1.1 201 Created
2
+ Server: nginx/1.0.13
3
+ Date: Sat, 24 Mar 2012 10:33:15 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 201 Created
7
+ X-RateLimit-Limit: 5000
8
+ ETag: "b8da3ff7db37259729d0351331372051"
9
+ Location: https://api.github.com/gists/2180935
10
+ X-OAuth-Scopes: gist
11
+ X-RateLimit-Remaining: 4999
12
+ X-Accepted-OAuth-Scopes: gist
13
+ Content-Length: 1732
14
+
15
+ {
16
+ "history": [
17
+ {
18
+ "url": "https://api.github.com/gists/2180935/cea881b482d60f5141a4ab088cb0dbdee5567461",
19
+ "user": {
20
+ "url": "https://api.github.com/users/swdyh",
21
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
22
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
23
+ "id": 9168,
24
+ "login": "swdyh"
25
+ },
26
+ "version": "cea881b482d60f5141a4ab088cb0dbdee5567461",
27
+ "change_status": {
28
+ "deletions": 0,
29
+ "additions": 1,
30
+ "total": 1
31
+ },
32
+ "committed_at": "2012-03-24T10:33:15Z"
33
+ }
34
+ ],
35
+ "git_push_url": "git@gist.github.com:2180935.git",
36
+ "comments": 0,
37
+ "updated_at": "2012-03-24T10:33:15Z",
38
+ "url": "https://api.github.com/gists/2180935",
39
+ "user": {
40
+ "url": "https://api.github.com/users/swdyh",
41
+ "avatar_url": "https://secure.gravatar.com/avatar/465e43442fc3604b4a7ad9c55bc52066?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
42
+ "gravatar_id": "465e43442fc3604b4a7ad9c55bc52066",
43
+ "id": 9168,
44
+ "login": "swdyh"
45
+ },
46
+ "public": true,
47
+ "forks": [
48
+
49
+ ],
50
+ "created_at": "2012-03-24T10:33:15Z",
51
+ "description": "the description for this gist",
52
+ "files": {
53
+ "file1.txt": {
54
+ "type": "text/plain",
55
+ "raw_url": "https://gist.github.com/raw/2180935/b087a4c57f47ffad4025004869d7366ddc82d0d1/file1.txt",
56
+ "language": "Text",
57
+ "size": 20,
58
+ "filename": "file1.txt",
59
+ "content": "String file contents"
60
+ }
61
+ },
62
+ "git_pull_url": "git://gist.github.com/2180935.git",
63
+ "id": "2180935",
64
+ "html_url": "https://gist.github.com/2180935"
65
+ }
data/test/gisty_test.rb CHANGED
@@ -1,15 +1,50 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
- require "test/unit"
2
+ require 'test/unit'
3
3
  require 'pp'
4
4
  require 'rr'
5
+ require 'fakeweb'
6
+
7
+ fixtures_path = Pathname.new(File.dirname(__FILE__)).join('fixtures').realpath
8
+ FakeWeb.allow_net_connect = false
9
+ stubs = [
10
+ [
11
+ :get,
12
+ 'https://api.github.com/gists?access_token=testaccesstoken',
13
+ 'gists_1'
14
+ ],
15
+ [
16
+ :get,
17
+ 'https://api.github.com/gists?access_token=testaccesstoken&page=2',
18
+ 'gists_2'
19
+ ],
20
+ [
21
+ :get,
22
+ 'https://api.github.com/gists?access_token=testaccesstoken&page=3',
23
+ 'gists_3'
24
+ ],
25
+ [
26
+ :post,
27
+ 'https://api.github.com/gists?access_token=testaccesstoken',
28
+ 'gists_post'
29
+ ]
30
+ ]
31
+ stubs.each do |stub|
32
+ head, body = IO.read(fixtures_path.join stub[2]).split("\r\n\r\n")
33
+ h = head.split("\r\n").slice(1..-1).inject({}) { |r, i|
34
+ tmp = i.split(':')
35
+ r[tmp[0]] = tmp.slice(1..-1).join(':')
36
+ r
37
+ }
38
+ h[:body] = body
39
+ FakeWeb.register_uri(stub[0], stub[1], h)
40
+ end
5
41
 
6
42
  class GistyTest < Test::Unit::TestCase
7
43
  include RR::Adapters::TestUnit
8
44
 
9
45
  def setup
10
- @gisty_dir = Pathname.new('tmp').realpath.join('gists')
11
- @gisty = Gisty.new @gisty_dir, 'foo', 'bar'
12
- stub_open_uri!
46
+ @gisty_dir = Pathname.new(File.dirname(__FILE__)).join('tmp')
47
+ @gisty = Gisty.new @gisty_dir, :access_token => 'testaccesstoken'
13
48
  stub_kernel_system!
14
49
  end
15
50
 
@@ -17,19 +52,6 @@ class GistyTest < Test::Unit::TestCase
17
52
  FileUtils.rm_rf @gisty_dir
18
53
  end
19
54
 
20
- def stub_open_uri!
21
- stub(OpenURI).open_uri do |uri|
22
- path = url2fixture uri
23
- # puts "stub open_uri: #{uri} -> #{path}"
24
- open url2fixture(uri)
25
- end
26
- end
27
-
28
- def url2fixture url
29
- filename = url.to_s.split('/').last.gsub(/[&?=]/, '_')
30
- File.join File.dirname(__FILE__), 'fixtures', filename
31
- end
32
-
33
55
  def stub_kernel_system!
34
56
  stub(Kernel).system do |cmd|
35
57
  # puts "* '#{cmd}' *"
@@ -43,73 +65,46 @@ class GistyTest < Test::Unit::TestCase
43
65
  end
44
66
  end
45
67
 
46
- # def stub_post_form! dummy = 'http://gist.github.com/111111'
47
- # stub(Net::HTTP).post_form do |uri, opt|
48
- # { 'Location' => dummy }
49
- # end
50
- # end
51
-
52
- def test_extract_ids
53
- path = File.join 'test', 'fixtures', 'swdyh_page_4'
54
- ids = Gisty.extract_ids IO.read(path)
55
- assert ids.include?("6938")
56
- assert ids.include?("3668")
68
+ def test_unset_access_token
69
+ assert_raise(Gisty::UnsetAuthInfoException) { Gisty.new @gisty_dir }
70
+ assert_raise(Gisty::UnsetAuthInfoException) { Gisty.new @gisty_dir, :access_token => '' }
57
71
  end
58
72
 
59
- def test_extract
60
- meta = @gisty.extract 'http://gist.github.com/30119'
61
- assert_equal 'brianleroux', meta[:author]
62
- assert_equal 4, meta[:files].size
63
- end
73
+ def test_mygists
74
+ myg = @gisty.mygists
75
+ assert_equal 30, myg[:content].size
76
+ assert_not_nil myg[:link][:next]
77
+ assert_not_nil myg[:link][:last]
64
78
 
65
- def test_new
66
- assert_instance_of Gisty, @gisty
79
+ myg2 = @gisty.mygists :url => myg[:link][:next]
80
+ assert_equal 30, myg2[:content].size
81
+ assert_not_nil myg2[:link][:prev]
82
+ assert_not_nil myg2[:link][:next]
83
+ assert_not_nil myg2[:link][:last]
67
84
  end
68
85
 
69
- def test_next_link
70
- path1 = url2fixture('http://gist.github.com/mine?page=1&login=foo&token=bar')
71
- path2 = url2fixture('http://gist.github.com/mine?page=2&login=foo&token=bar')
72
- path3 = url2fixture('http://gist.github.com/mine?page=3&login=foo&token=bar')
73
- assert_equal '/mine?page=2', @gisty.next_link(IO.read(path1))
74
- assert_equal '/mine?page=3', @gisty.next_link(IO.read(path2))
75
- assert_nil @gisty.next_link(IO.read(path3))
76
- end
77
86
 
78
- def test_map_page_urls
79
- mapped = @gisty.map_pages do |url, page|
80
- assert url.match(/page=\d/)
81
- end
82
- assert_equal 3, mapped.size
87
+ def test_all_mygists
88
+ assert_equal 72, @gisty.all_mygists.size
83
89
  end
84
90
 
85
- def test_remote_ids
86
- ids = @gisty.remote_ids
87
- # assert_equal 20, ids.size
88
- # assert ids.include?('7205')
89
- # assert ids.include?('bc82698ab357bd8bb433')
90
- end
91
-
92
- def test_clone
93
- id = @gisty.remote_ids.first
94
- pn = @gisty_dir.join id
95
- @gisty.clone id
91
+ def test_all_mygists_with_block
92
+ @gisty.all_mygists { |gist| assert_not_nil gist['id'] }
96
93
  end
97
94
 
98
95
  def test_list
99
- ids = @gisty.remote_ids
100
- @gisty.clone ids[0]
101
- @gisty.clone ids[1]
102
- list = @gisty.list[:public].map { |i| i.first }
103
- assert list.include?(ids[0])
104
- assert list.include?(ids[1])
105
- end
96
+ FileUtils.mkdir_p @gisty_dir.join('111')
97
+ open(@gisty_dir.join('111').join('test.txt'), 'w') { |f| f.puts 'test' }
98
+ FileUtils.mkdir_p @gisty_dir.join('aaa')
99
+ open(@gisty_dir.join('aaa').join('test.txt'), 'w') { |f| f.puts 'test' }
100
+ FileUtils.mkdir_p @gisty_dir.join('commands')
101
+ open(@gisty_dir.join('commands').join('test.rb'), 'w') { |f| f.puts '#test' }
106
102
 
107
- def test_delete
108
- id = '11111'
109
- pn = @gisty_dir.join id
110
- FileUtils.mkdir(pn)
111
- @gisty.delete id
112
- assert !pn.exist?
103
+ list = @gisty.list
104
+ assert_equal 1, list[:public].size
105
+ assert_equal 1, list[:private].size
106
+ assert_equal 2, @gisty.local_gist_directories.size
107
+ assert_equal 2, @gisty.local_ids.size
113
108
  end
114
109
 
115
110
  def test_sync
@@ -119,22 +114,29 @@ class GistyTest < Test::Unit::TestCase
119
114
  assert ids.all? { |i| @gisty_dir.join(i).exist? }
120
115
  end
121
116
 
122
- # def test_sync_delete
123
- # id = '12345'
124
- # assert !@gisty.remote_ids.include?(id)
125
- # @gisty.clone id
126
- # assert @gisty_dir.join(id).exist?
127
- # @gisty.sync true
128
- # assert !@gisty_dir.join(id).exist?
129
- # end
117
+ # require stdin input y/n
118
+ # def test_sync_delete
119
+ # id = '12345'
120
+ # assert !@gisty.remote_ids.include?(id)
121
+ # @gisty.clone id
122
+ # assert @gisty_dir.join(id).exist?
123
+ # @gisty.sync true
124
+ # assert !@gisty_dir.join(id).exist?
125
+ # end
126
+
127
+ def test_delete
128
+ id = '11111'
129
+ pn = @gisty_dir.join id
130
+ @gisty.clone id
131
+ @gisty.delete id
132
+ assert !pn.exist?
133
+ end
130
134
 
131
135
  def test_build_params
132
136
  path = File.join('test', 'fixtures', 'foo.user.js')
133
137
  params = @gisty.build_params path
134
-
135
- assert_equal '.js', params['file_ext[gistfile1]']
136
- assert_equal 'foo.user.js', params['file_name[gistfile1]']
137
- assert_equal "// foo.user.js\n", params['file_contents[gistfile1]']
138
+ assert_equal 'foo.user.js', params['files'].keys[0]
139
+ assert_equal "// foo.user.js\n", params['files']['foo.user.js']['content']
138
140
  end
139
141
 
140
142
  def test_build_params_multi
@@ -142,44 +144,50 @@ class GistyTest < Test::Unit::TestCase
142
144
  path2 = File.join('test', 'fixtures', 'bar.user.js')
143
145
  params = @gisty.build_params [path1, path2]
144
146
 
145
- assert_equal '.js', params['file_ext[gistfile1]']
146
- assert_equal 'foo.user.js', params['file_name[gistfile1]']
147
- assert_equal "// foo.user.js\n", params['file_contents[gistfile1]']
148
- assert_equal '.js', params['file_ext[gistfile2]']
149
- assert_equal 'bar.user.js', params['file_name[gistfile2]']
150
- assert_equal "// bar.user.js\n", params['file_contents[gistfile2]']
147
+ assert_not_nil params['files']['foo.user.js']
148
+ assert_not_nil params['files']['bar.user.js']
149
+
150
+ assert_equal "// foo.user.js\n", params['files']['foo.user.js']['content']
151
+ assert_equal "// bar.user.js\n", params['files']['bar.user.js']['content']
151
152
  end
152
153
 
153
- def test_ssl_ca_option
154
+ def test_ssl_ca_option_default
154
155
  ca = '/ssl_ca_path/cert.pem'
155
- @gisty = Gisty.new @gisty_dir, 'foo', 'bar'
156
- assert_nil @gisty.instance_eval { @ssl_ca }
156
+ g = Gisty.new @gisty_dir, :access_token => 'testaccess_token'
157
+ assert_nil g.instance_eval { @ssl_ca }
158
+ end
157
159
 
160
+ def test_set_ssl_ca_option
158
161
  ca = '/ssl_ca_path/cert.pem'
159
- @gisty = Gisty.new @gisty_dir, 'foo', 'bar', :ssl_ca => ca
160
- assert_equal ca, @gisty.instance_eval { @ssl_ca }
162
+ g = Gisty.new @gisty_dir, :access_token => 'testaccess_token', :ssl_ca => ca
163
+ assert_equal ca, g.instance_eval { @ssl_ca }
161
164
  end
162
165
 
163
- # def test_create
164
- # stub_post_form!
165
- # path = File.join('test', 'fixtures', 'foo.user.js')
166
- # @gisty.create path
167
- # end
166
+ def test_ssl_verify_default
167
+ g = Gisty.new @gisty_dir, :access_token => 'testaccess_token'
168
+ assert_equal OpenSSL::SSL::VERIFY_PEER, g.instance_eval { @ssl_verify }
169
+ end
168
170
 
169
- # def test_create_multi
170
- # path1 = File.join('test', 'fixtures', 'foo.user.js')
171
- # path2 = File.join('test', 'fixtures', 'bar.user.js')
172
- # @gisty.create [path1, path2]
173
- # end
171
+ def test_set_ssl_verify_option
172
+ opt = { :access_token => 'testaccess_token' }
174
173
 
175
- # def test_post_failure
176
- # stub(Net::HTTP).post_form do |uri, opt|
177
- # Net::HTTPClientError.new 'foo', 'bar', 'baz'
178
- # end
179
- # path = File.join('test', 'fixtures', 'foo.user.js')
180
- # assert_raise Gisty::PostFailureException do
181
- # @gisty.create path
182
- # end
183
- # end
184
- end
174
+ g = Gisty.new @gisty_dir, opt.merge(:ssl_verify => :none)
175
+ assert_equal OpenSSL::SSL::VERIFY_NONE, g.instance_eval { @ssl_verify }
176
+
177
+ g = Gisty.new @gisty_dir, opt.merge(:ssl_verify => 'NONE')
178
+ assert_equal OpenSSL::SSL::VERIFY_NONE, g.instance_eval { @ssl_verify }
179
+
180
+ g = Gisty.new @gisty_dir, opt.merge(:ssl_verify => 'None')
181
+ assert_equal OpenSSL::SSL::VERIFY_NONE, g.instance_eval { @ssl_verify }
185
182
 
183
+ g = Gisty.new @gisty_dir, opt.merge(:ssl_verify => OpenSSL::SSL::VERIFY_NONE)
184
+ assert_equal OpenSSL::SSL::VERIFY_NONE, g.instance_eval { @ssl_verify }
185
+ end
186
+
187
+ def test_create
188
+ # stub
189
+ path = File.join('test', 'fixtures', 'foo.user.js')
190
+ r = @gisty.create path
191
+ assert_not_nil r
192
+ end
193
+ end