acts_as_unvlogable 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,392 +0,0 @@
1
- require 'test/unit'
2
-
3
- $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
4
- # Main class
5
- require 'acts_as_unvlogable'
6
- # Gems & other herbs
7
- require 'shoulda'
8
-
9
- class ActsAsUnvlogableTest < Test::Unit::TestCase
10
-
11
- context "Instancing UnvlogIt" do
12
-
13
- context "without any url" do
14
- should "raise an ArgumentError exception" do
15
- assert_raise(ArgumentError, "We need a video url") { UnvlogIt.new }
16
- end
17
- end
18
-
19
- context "with an unsupported url" do
20
- should "raise an ArgumentError exception" do
21
- assert_raise(ArgumentError, "Unsuported url or service") { UnvlogIt.new("http://iwannagothere.net/") }
22
- end
23
- end
24
-
25
- # ----------------------------------------------------------
26
- # Testing youtube
27
- # ----------------------------------------------------------
28
- context "with an existent youtube url" do
29
- setup do
30
- @videotron = UnvlogIt.new("http://www.youtube.com/watch?v=WZYzvcqgim0") # => The Super Fast Cat Attacks - Ninja Cat
31
- end
32
- should "initialize a VgYoutube instance" do
33
- assert_equal VgYoutube, @videotron.instance_values['object'].class
34
- assert_equal "http://www.youtube.com/watch?v=WZYzvcqgim0", @videotron.instance_values['object'].instance_values['url']
35
- assert_equal "WZYzvcqgim0", @videotron.instance_values['object'].instance_values['video_id']
36
- assert_not_nil @videotron.instance_values['object'].instance_values['details']
37
- end
38
-
39
- should "return the video properties" do
40
- check_video_attributes({:title => "The Super Fast Cat Attacks - Ninja Cat", :service => "Youtube"})
41
- end
42
- end
43
-
44
- context "with an existent youtube url that can not be embedded" do
45
- should "raise an ArgumentError" do
46
- assert_raise(ArgumentError, "Embedding disabled by request") { UnvlogIt.new("http://www.youtube.com/watch?v=3Oec8RuwVVs") }# => The Killers - Read My Mind
47
- end
48
- end
49
-
50
- context "with an inexistent youtube url" do
51
- should "raise an ArgumentError" do
52
- assert_raise(ArgumentError, "Unsuported url or service") { UnvlogIt.new("http://www.youtube.com/watch?v=inexistente") }
53
- end
54
- end
55
-
56
- # ----------------------------------------------------------
57
- # Testing metacafe
58
- # ----------------------------------------------------------
59
- context "with an existent metacafe url" do
60
- setup do
61
- @videotron = UnvlogIt.new("http://www.metacafe.com/watch/1135061/close_call_a320_caught_in_crosswinds/") # => Close Call! A320 Caught in Crosswinds
62
- end
63
- should "initialize a VgMetacafe instance" do
64
- assert_equal VgMetacafe, @videotron.instance_values['object'].class
65
- assert_equal "http://www.metacafe.com/watch/1135061/close_call_a320_caught_in_crosswinds/", @videotron.instance_values['object'].instance_values['url']
66
- assert_equal 3, @videotron.instance_values['object'].instance_values['args'].size
67
- assert !@videotron.instance_values['object'].instance_values['youtubed']
68
- assert_nil @videotron.instance_values['object'].instance_values['yt']
69
- end
70
-
71
- should "return the video properties" do
72
- check_video_attributes({:title => "Close call a320 caught in crosswinds", :service => "Metacafe"})
73
- end
74
- end
75
-
76
- context "with an existent 'youtubed' metacafe url" do
77
- setup do
78
- @videotron = UnvlogIt.new("http://www.metacafe.com/watch/yt-r07zdVLOWBA/pop_rocks_and_coke_myth/") # => Close Call! A320 Caught in Crosswinds
79
- end
80
- should "initialize a VgMetacafe instance" do
81
- assert_equal VgMetacafe, @videotron.instance_values['object'].class
82
- assert_equal "http://www.metacafe.com/watch/yt-r07zdVLOWBA/pop_rocks_and_coke_myth/", @videotron.instance_values['object'].instance_values['url']
83
- assert_equal 3, @videotron.instance_values['object'].instance_values['args'].size
84
- assert @videotron.instance_values['object'].instance_values['youtubed']
85
- assert VgYoutube, @videotron.instance_values['object'].instance_values['yt'].class
86
- end
87
-
88
- should "return the video properties" do
89
- check_video_attributes({:title => "Pop Rocks and Coke Myth", :service => "Metacafe"})
90
- end
91
- end
92
-
93
-
94
- end
95
-
96
-
97
- # ----------------------------------------------------------
98
- # Testing dailymotion
99
- # ----------------------------------------------------------
100
- context "with a dailymotion video url" do
101
- setup do
102
- @videotron = UnvlogIt.new("http://www.dailymotion.com/video/x7u5kn_parkour-dayyy_sport") # => parkour dayyy
103
- end
104
- should "initialize a VgDailymotion instance" do
105
- assert_equal VgDailymotion, @videotron.instance_values['object'].class
106
- assert_equal "http://www.dailymotion.com/video/x7u5kn_parkour-dayyy_sport", @videotron.instance_values['object'].instance_values['url']
107
- assert_equal "x7u5kn_parkour-dayyy_sport", @videotron.instance_values['object'].instance_values['video_id']
108
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
109
- end
110
-
111
- should "return the video properties" do
112
- check_video_attributes({:title => "parkour dayyy", :service => "Dailymotion"})
113
- end
114
- end
115
-
116
-
117
-
118
- # ----------------------------------------------------------
119
- # Testing collegehumor
120
- # ----------------------------------------------------------
121
- context "with a collegehumor video url" do
122
- setup do
123
- @videotron = UnvlogIt.new("http://www.collegehumor.com/video:1781938") # => Brohemian Rhapsody
124
- end
125
- should "initialize a VgCollegehumor instance" do
126
- assert_equal VgCollegehumor, @videotron.instance_values['object'].class
127
- assert_equal "http://www.collegehumor.com/video:1781938", @videotron.instance_values['object'].instance_values['url']
128
- assert_equal "1781938", @videotron.instance_values['object'].instance_values['video_id']
129
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
130
- end
131
-
132
- should "return the video properties" do
133
- check_video_attributes({:title => "Brohemian Rhapsody", :service => "CollegeHumor"})
134
- end
135
- end
136
-
137
-
138
- # ----------------------------------------------------------
139
- # Testing blip.tv
140
- # ----------------------------------------------------------
141
- context "with a blip.tv video url" do
142
- setup do
143
- @videotron = UnvlogIt.new("http://blip.tv/file/678407/") # => Toy Break 26 : Adult Toys
144
- end
145
- should "initialize a VgBlip instance" do
146
- assert_equal VgBlip, @videotron.instance_values['object'].class
147
- assert_equal "http://blip.tv/file/678407/", @videotron.instance_values['object'].instance_values['url']
148
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
149
- end
150
-
151
- should "return the video properties" do
152
- check_video_attributes({:title => "Toy Break 26 : Adult Toys", :service => "Blip.tv"})
153
- end
154
- end
155
-
156
-
157
- # ----------------------------------------------------------
158
- # Testing mtvmusic.com
159
- # ----------------------------------------------------------
160
- context "with a mtvmusic.com video url" do
161
- setup do
162
- @videotron = UnvlogIt.new("http://www.mtvhive.com/artist/twin_shadow/videos/640381/slow_live") # => Twin Shadow » Slow (Live)
163
- end
164
- should "initialize a VgMtvmusic instance" do
165
- assert_equal VgMtvmusic, @videotron.instance_values['object'].class
166
- assert_equal "http://www.mtvhive.com/artist/twin_shadow/videos/640381/slow_live", @videotron.instance_values['object'].instance_values['url']
167
- assert_equal "640381", @videotron.instance_values['object'].instance_values['video_id']
168
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
169
- end
170
-
171
- should "return the video properties" do
172
- check_video_attributes({:title => "Twin Shadow » Slow (Live)", :service => "MTV Music"})
173
- end
174
- end
175
-
176
-
177
-
178
- # ----------------------------------------------------------
179
- # Testing vids.myspace.com
180
- # ----------------------------------------------------------
181
- context "with a vids.myspace.com video url" do
182
- setup do
183
- @videotron = UnvlogIt.new("http://vids.myspace.com/index.cfm?fuseaction=vids.individual&VideoID=27111431") # => rocabilis
184
- end
185
- should "initialize a VgMyspace instance" do
186
- assert_equal VgMyspace, @videotron.instance_values['object'].class
187
- assert_equal "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&VideoID=27111431", @videotron.instance_values['object'].instance_values['url']
188
- assert_equal "27111431", @videotron.instance_values['object'].instance_values['video_id']
189
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
190
- end
191
-
192
- should "return the video properties" do
193
- check_video_attributes({:title => "rocabilis", :service => "Myspace"})
194
- end
195
- end
196
-
197
-
198
- # ----------------------------------------------------------
199
- # Testing 11870.com
200
- # ----------------------------------------------------------
201
- context "with an 11870.com video url" do
202
- setup do
203
- @videotron = UnvlogIt.new("http://11870.com/pro/chic-basic-born/media/b606abfe") # => Chic & Basic Born
204
- end
205
- should "initialize a Vg11870 instance" do
206
- assert_equal Vg11870, @videotron.instance_values['object'].class
207
- assert_equal "http://11870.com/pro/chic-basic-born/media/b606abfe", @videotron.instance_values['object'].instance_values['url']
208
- assert_not_nil @videotron.instance_values['object'].instance_values['page']
209
- assert_not_nil @videotron.instance_values['object'].instance_values['flashvars']
210
- end
211
-
212
- should "return the video properties" do
213
- check_video_attributes({:title => "Chic & Basic Born", :service => "11870.com"})
214
- end
215
- end
216
-
217
-
218
- # ----------------------------------------------------------
219
- # Testing dalealplay.com
220
- # ----------------------------------------------------------
221
- context "with a dalealplay.com video url" do
222
- setup do
223
- @videotron = UnvlogIt.new("http://www.dalealplay.com/informaciondecontenido.php?con=80280") # => Camelos Semos Jonathan Tú si que vales
224
- end
225
- should "initialize a VgDalealplay instance" do
226
- assert_equal VgDalealplay, @videotron.instance_values['object'].class
227
- assert_equal "http://www.dalealplay.com/informaciondecontenido.php?con=80280", @videotron.instance_values['object'].instance_values['url']
228
- assert_equal "80280", @videotron.instance_values['object'].instance_values['video_id']
229
- assert_not_nil @videotron.instance_values['object'].instance_values['page']
230
- end
231
-
232
- should "return the video properties" do
233
- check_video_attributes({:title => "Camelos.Semos. Jonathan. Tú si que vales.", :service => "dalealplay"})
234
- end
235
- end
236
-
237
-
238
-
239
- # ----------------------------------------------------------
240
- # Testing flickr.com
241
- # ----------------------------------------------------------
242
- context "with a flickr.com video url" do
243
- setup do
244
- @videotron = UnvlogIt.new("http://www.flickr.com/photos/jerovital/4152225414/", {:key => "065b2eff5e604e2a408c01af1f27a982" }) # => la primera vela
245
- end
246
- should "initialize a VgFlickr instance" do
247
- assert_equal VgFlickr, @videotron.instance_values['object'].class
248
- assert_equal "http://www.flickr.com/photos/jerovital/4152225414/", @videotron.instance_values['object'].instance_values['url']
249
- assert_equal "4152225414", @videotron.instance_values['object'].instance_values['video_id']
250
- assert_not_nil @videotron.instance_values['object'].instance_values['details']
251
- end
252
-
253
- should "return the video properties" do
254
- check_video_attributes({:title => "flipando en los columpios", :service => "Flickr"})
255
- end
256
- end
257
-
258
-
259
- # ----------------------------------------------------------
260
- # Testing qik.com
261
- # ----------------------------------------------------------
262
- context "with a qik.com video url" do
263
- setup do
264
- @videotron = UnvlogIt.new("http://qik.com/video/340982") # => Honolulu Day 8: USS Arizona at Pearl Harbor
265
- end
266
- should "initialize a VgQik instance" do
267
- assert_equal VgQik, @videotron.instance_values['object'].class
268
- assert_equal "http://qik.com/video/340982", @videotron.instance_values['object'].instance_values['url']
269
- assert_equal "340982", @videotron.instance_values['object'].instance_values['video_id']
270
- assert_not_nil @videotron.instance_values['object'].instance_values['page']
271
- assert_not_nil @videotron.instance_values['object'].instance_values['feed_url']
272
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
273
- end
274
-
275
- should "return the video properties" do
276
- check_video_attributes({:title => "Honolulu Day 8: USS Arizona at Pearl Harbor", :service => "Qik"})
277
- end
278
- end
279
-
280
-
281
-
282
- # ----------------------------------------------------------
283
- # Testing www.marca.tv
284
- # ----------------------------------------------------------
285
- context "with a www.marca.tv video url" do
286
- setup do
287
- @videotron = UnvlogIt.new("http://www.marca.com/tv/?v=DN23wG8c1Rj") # => Pau entra por la puerta grande en el club de los 10.000
288
- end
289
- should "initialize a VgMarca instance" do
290
- assert_equal VgMarca, @videotron.instance_values['object'].class
291
- assert_equal "http://www.marca.com/tv/?v=DN23wG8c1Rj", @videotron.instance_values['object'].instance_values['url']
292
- assert_equal "DN23wG8c1Rj", @videotron.instance_values['object'].instance_values['video_id']
293
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
294
- end
295
-
296
- should "return the video properties" do
297
- check_video_attributes({:title => "Pau entra por la puerta grande en el club de los 10.000", :service => "Marca.tv"})
298
- end
299
- end
300
-
301
-
302
-
303
- # ----------------------------------------------------------
304
- # Testing ted talks
305
- # ----------------------------------------------------------
306
- context "with a ted talks video url" do
307
- setup do
308
- @videotron = UnvlogIt.new("http://www.ted.com/index.php/talks/benjamin_wallace_on_the_price_of_happiness.html") # => Benjamin Wallace: Does happiness have a price tag?
309
- end
310
- should "initialize a VgTed instance" do
311
- assert_equal VgTed, @videotron.instance_values['object'].class
312
- assert_equal "http://www.ted.com/index.php/talks/benjamin_wallace_on_the_price_of_happiness.html", @videotron.instance_values['object'].instance_values['url']
313
- assert_not_nil @videotron.instance_values['object'].instance_values['page']
314
- assert_not_nil @videotron.instance_values['object'].instance_values['flashvars']
315
- assert_not_nil @videotron.instance_values['object'].instance_values['args']
316
- end
317
-
318
- should "return the video properties" do
319
- check_video_attributes({:title => "Benjamin Wallace on the price of happiness", :service => "Ted Talks"})
320
- end
321
- end
322
-
323
- context "with an invalid ted talks video url" do
324
- should "raise an ArgumentError exception" do
325
- assert_raise(ArgumentError, "Unsuported url or service") { UnvlogIt.new("http://www.ted.com/index.php/wadus.html") }
326
- end
327
- end
328
-
329
-
330
- # ----------------------------------------------------------
331
- # Testing vimeo
332
- # ----------------------------------------------------------
333
- context "with a vimeo video url" do
334
- setup do
335
- @videotron = UnvlogIt.new("http://vimeo.com/2354261") # => People are strange
336
- end
337
- should "initialize a VgVimeo instance" do
338
- assert_equal VgVimeo, @videotron.instance_values['object'].class
339
- assert_equal "http://vimeo.com/2354261", @videotron.instance_values['object'].instance_values['url']
340
- assert_equal "2354261", @videotron.instance_values['object'].instance_values['video_id']
341
- assert_not_nil @videotron.instance_values['object'].instance_values['feed']
342
- end
343
-
344
- should "return the video properties" do
345
- check_video_attributes({:title => "People are strange", :service => "Vimeo"})
346
- end
347
- end
348
-
349
- # ----------------------------------------------------------
350
- # Testing RuTube
351
- # ----------------------------------------------------------
352
- context "with a rutube video url" do
353
- setup do
354
- @videotron = UnvlogIt.new("http://rutube.ru/tracks/1958807.html?v=56cd2f1b50a4d2b69ff455e72f2fae29") # => chipmunks!!
355
- end
356
- should "initialize a VgRutube instance" do
357
- assert_equal VgRutube, @videotron.instance_values['object'].class
358
- assert_equal "http://rutube.ru/tracks/1958807.html?v=56cd2f1b50a4d2b69ff455e72f2fae29", @videotron.instance_values['object'].instance_values['url']
359
- assert_equal "1958807", @videotron.instance_values['object'].instance_values['movie_id']
360
- assert_equal "56cd2f1b50a4d2b69ff455e72f2fae29", @videotron.instance_values['object'].send(:movie_hash)
361
- end
362
-
363
- should "return the video properties" do
364
- check_video_attributes({:title => "Запасливые бурундуки"})
365
- end
366
- end
367
-
368
- context "with an invalid rutube video url" do
369
- should "raise an ArgumentError exception" do
370
- assert_raise(ArgumentError, "Unsuported url or service") { UnvlogIt.new("http://rutube.ru/tracks/abdcd.html?v=523423") }
371
- end
372
- end
373
-
374
- protected
375
-
376
- def check_video_attributes(options={})
377
- assert_equal "#{options[:title]}", @videotron.title unless (options.blank? || options[:title].blank?)
378
- assert_equal "#{options[:service]}", @videotron.service unless (options.blank? || options[:service].blank?)
379
- assert_not_nil @videotron.thumbnail
380
- if options.blank? || options[:noembed].blank?
381
- assert_not_nil @videotron.embed_url
382
- assert_not_nil @videotron.embed_html
383
- elsif options[:noembed]
384
- assert_nil @videotron.embed_url
385
- assert_nil @videotron.embed_html
386
- assert_nil @videotron.video_details[:embed_url]
387
- assert_nil @videotron.video_details[:embed_html]
388
- end
389
- assert_not_nil @videotron.flv
390
- assert_equal Hash, @videotron.video_details.class
391
- end
392
- end