enigmamachine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/.document +5 -0
  2. data/.gitignore +26 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +32 -0
  5. data/Rakefile +57 -0
  6. data/VERSION +1 -0
  7. data/bin/enigmamachine +15 -0
  8. data/lib/enigmamachine/config.ru +9 -0
  9. data/lib/enigmamachine/encoding_queue.rb +29 -0
  10. data/lib/enigmamachine/models/encoder.rb +54 -0
  11. data/lib/enigmamachine/models/encoding_task.rb +19 -0
  12. data/lib/enigmamachine/models/video.rb +37 -0
  13. data/lib/enigmamachine/public/default.css +233 -0
  14. data/lib/enigmamachine/public/images/Enigma-logo.jpg +0 -0
  15. data/lib/enigmamachine/public/images/bg01.jpg +0 -0
  16. data/lib/enigmamachine/public/images/bg02.jpg +0 -0
  17. data/lib/enigmamachine/public/images/bg03.jpg +0 -0
  18. data/lib/enigmamachine/public/images/bg04.jpg +0 -0
  19. data/lib/enigmamachine/public/images/img02.gif +0 -0
  20. data/lib/enigmamachine/public/images/img03.gif +0 -0
  21. data/lib/enigmamachine/public/images/img04.gif +0 -0
  22. data/lib/enigmamachine/public/images/img05.gif +0 -0
  23. data/lib/enigmamachine/public/images/img06.jpg +0 -0
  24. data/lib/enigmamachine/public/images/spacer.gif +0 -0
  25. data/lib/enigmamachine/views/encoders/edit.erb +20 -0
  26. data/lib/enigmamachine/views/encoders/encoder.erb +10 -0
  27. data/lib/enigmamachine/views/encoders/encoding_task.erb +10 -0
  28. data/lib/enigmamachine/views/encoders/form.erb +5 -0
  29. data/lib/enigmamachine/views/encoders/index.erb +12 -0
  30. data/lib/enigmamachine/views/encoders/new.erb +19 -0
  31. data/lib/enigmamachine/views/encoders/show.erb +19 -0
  32. data/lib/enigmamachine/views/encoding_tasks/edit.erb +23 -0
  33. data/lib/enigmamachine/views/encoding_tasks/form.erb +12 -0
  34. data/lib/enigmamachine/views/encoding_tasks/new.erb +23 -0
  35. data/lib/enigmamachine/views/index.erb +13 -0
  36. data/lib/enigmamachine/views/layout.erb +67 -0
  37. data/lib/enigmamachine/views/videos/form.erb +11 -0
  38. data/lib/enigmamachine/views/videos/index.erb +36 -0
  39. data/lib/enigmamachine/views/videos/new.erb +19 -0
  40. data/lib/enigmamachine/views/videos/video.erb +6 -0
  41. data/lib/enigmamachine.rb +179 -0
  42. data/lib/enigmamachine.sqlite3 +0 -0
  43. data/lib/ext/array_ext.rb +8 -0
  44. data/lib/ext/partials.rb +28 -0
  45. data/lib/init.rb +75 -0
  46. data/test/helper.rb +49 -0
  47. data/test/support/afile.mpg +0 -0
  48. data/test/support/blueprints.rb +29 -0
  49. data/test/test_encoder.rb +80 -0
  50. data/test/test_encoder_queue.rb +34 -0
  51. data/test/test_enigmamachine.rb +536 -0
  52. data/test/test_video.rb +84 -0
  53. metadata +141 -0
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestEncoderQueue < Test::Unit::TestCase
4
+
5
+ context "the encode_next_video method" do
6
+ setup do
7
+ destroy_all_videos
8
+ @video = Video.make
9
+ @task = EncodingTask.make(:with_encoder)
10
+ @video.encoder = @task.encoder
11
+ @video.save
12
+ @queue = EncodingQueue.new
13
+ @queue.encode_next_video
14
+ sleep 1
15
+ end
16
+
17
+ should "exist" do
18
+ assert @queue.respond_to? "encode_next_video"
19
+ end
20
+
21
+ should "start encoding the video" do
22
+ v = Video.get(@video.id)
23
+ assert_equal "encoding", v.state
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def destroy_all_videos
30
+ Video.all.each { |v| v.destroy! }
31
+ end
32
+
33
+ end
34
+
@@ -0,0 +1,536 @@
1
+ require 'helper'
2
+
3
+ class TestEnigmamachine < Test::Unit::TestCase
4
+
5
+ context "on GET to / without credentials" do
6
+ setup do
7
+ get '/'
8
+ end
9
+
10
+ should "respond with security error" do
11
+ assert !last_response.ok?
12
+ assert_equal 401, status
13
+ end
14
+ end
15
+
16
+ context "on GET to / with credentials" do
17
+ setup do
18
+ get '/', {}, basic_auth_creds
19
+ end
20
+
21
+ should "respond" do
22
+ assert last_response.ok?
23
+ end
24
+
25
+ context "when there is one Video" do
26
+ setup do
27
+ Video.make
28
+ get '/', {}, basic_auth_creds
29
+ end
30
+
31
+ should "work" do
32
+ assert last_response.ok?
33
+ end
34
+ end
35
+ end
36
+
37
+ context "on GET to /encoders" do
38
+ context "without credentials" do
39
+ setup do
40
+ get '/encoders'
41
+ end
42
+
43
+ should "respond with security error" do
44
+ assert !last_response.ok?
45
+ assert_equal 401, status
46
+ end
47
+ end
48
+
49
+ context "with credentials" do
50
+ setup do
51
+ get '/encoders', {}, basic_auth_creds
52
+ end
53
+
54
+ should "work" do
55
+ assert last_response.ok?
56
+ end
57
+
58
+ context "when some encoders exist" do
59
+ setup do
60
+ 2.times { Encoder.make }
61
+ end
62
+
63
+ should "still work" do
64
+ assert last_response.ok?
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ context "on GET to /encoder/:id" do
71
+ context "without credentials" do
72
+ setup do
73
+ get "/encoder/#{Encoder.first.id}"
74
+ end
75
+
76
+ should "respond with security error" do
77
+ assert !last_response.ok?
78
+ assert_equal 401, status
79
+ end
80
+ end
81
+
82
+ context "with credentials" do
83
+ setup do
84
+ get "/encoders/#{Encoder.first.id}", {:id => Encoder.first.id}, basic_auth_creds
85
+ end
86
+
87
+ should "work" do
88
+ assert last_response.ok?
89
+ end
90
+ end
91
+ end
92
+
93
+ context "on GET to /encoders/new" do
94
+ context "without credentials" do
95
+ setup do
96
+ get '/encoders/new'
97
+ end
98
+
99
+ should "respond with security error" do
100
+ assert !last_response.ok?
101
+ assert_equal 401, status
102
+ end
103
+ end
104
+
105
+ context "with credentials" do
106
+ setup do
107
+ get '/encoders/new', {}, basic_auth_creds
108
+ end
109
+
110
+ should "work" do
111
+ assert last_response.ok?
112
+ end
113
+ end
114
+ end
115
+
116
+ context "on GET to /encoders/edit" do
117
+ setup do
118
+ @encoder = Encoder.make
119
+ end
120
+
121
+ context "without credentials" do
122
+ setup do
123
+ get "/encoders/#{@encoder.id}/edit"
124
+ end
125
+
126
+ should "respond with security error" do
127
+ assert !last_response.ok?
128
+ assert_equal 401, status
129
+ end
130
+ end
131
+
132
+ context "with credentials" do
133
+ setup do
134
+ get "/encoders/#{@encoder.id}/edit", {}, basic_auth_creds
135
+ end
136
+
137
+ should "work" do
138
+ assert last_response.ok?
139
+ end
140
+ end
141
+ end
142
+
143
+ context "on POST to /encoders" do
144
+ context "without credentials" do
145
+ setup do
146
+ post "/encoders", Encoder.plan
147
+ end
148
+
149
+ should "respond with security error" do
150
+ assert !last_response.ok?
151
+ assert_equal 401, status
152
+ end
153
+ end
154
+
155
+ context "with credentials" do
156
+
157
+ context "and valid Encoder params" do
158
+ setup do
159
+ @num_encoders = Encoder.count
160
+ post "/encoders", {:encoder => Encoder.plan}, basic_auth_creds
161
+ follow_redirect!
162
+ end
163
+
164
+ should "create an Encoder object" do
165
+ assert_equal "http://example.org/encoders/#{Encoder.last.id}", last_request.url
166
+ assert_equal @num_encoders + 1, Encoder.count
167
+ end
168
+ end
169
+
170
+ context "and invalid Encoder params" do
171
+ setup do
172
+ @num_encoders = Encoder.count
173
+ post "/encoders", {:encoder => Encoder.plan.merge(:name => "")}, basic_auth_creds
174
+ end
175
+
176
+ should "redisplay the form" do
177
+ assert_equal "http://example.org/encoders", last_request.url
178
+ end
179
+
180
+ should "not create an Encoder object" do
181
+ assert_equal @num_encoders, Encoder.count
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ context "on PUT to /encoders/:id" do
188
+ context "without credentials" do
189
+ setup do
190
+ put "/encoders/#{Encoder.first.id}", {:encoder => Encoder.plan}
191
+ end
192
+
193
+ should "respond with security error" do
194
+ assert !last_response.ok?
195
+ assert_equal 401, status
196
+ end
197
+ end
198
+
199
+ context "with credentials" do
200
+ context "and valid encoder params" do
201
+ setup do
202
+ put "/encoders/#{Encoder.first.id}", {:id => Encoder.first.id, :encoder => Encoder.plan}, basic_auth_creds
203
+ @num_encoders = Encoder.count
204
+ follow_redirect!
205
+ end
206
+
207
+ should "work" do
208
+ assert_equal "http://example.org/encoders", last_request.url
209
+ end
210
+
211
+ should "not create a new Encoder object" do
212
+ assert_equal @num_encoders, Encoder.count
213
+ end
214
+ end
215
+
216
+ context "and invalid encoder params" do
217
+ setup do
218
+ put "/encoders/#{Encoder.first.id}", {
219
+ :id => Encoder.first.id,
220
+ :encoder => Encoder.plan.merge(:name => "")}, basic_auth_creds
221
+ @num_encoders = Encoder.count
222
+ end
223
+
224
+ should "redisplay the edit form" do
225
+ assert_equal "http://example.org/encoders/#{Encoder.first.id}", last_request.url
226
+ end
227
+
228
+ should "not create a new Encoder object" do
229
+ assert_equal @num_encoders, Encoder.count
230
+ end
231
+ end
232
+
233
+ end
234
+ end
235
+
236
+ context "on DELETE to /encoders" do
237
+ context "without credentials" do
238
+ setup do
239
+ @encoder = Encoder.make
240
+ delete "/encoders/#{@encoder.id}", {:id => @encoder.id}
241
+ end
242
+
243
+ should "respond with security error" do
244
+ assert !last_response.ok?
245
+ assert_equal 401, status
246
+ end
247
+ end
248
+
249
+ context "with credentials" do
250
+ setup do
251
+ @encoder = Encoder.make
252
+ @num_encoders = Encoder.count
253
+ delete "/encoders/#{@encoder.id}", {:id => @encoder.id}, basic_auth_creds
254
+ follow_redirect!
255
+ end
256
+
257
+ should "destroy the encoder" do
258
+ assert_equal @num_encoders - 1, Encoder.count
259
+ end
260
+
261
+ should "redirect to the encoder list page" do
262
+ assert_equal "http://example.org/encoders", last_request.url
263
+ end
264
+ end
265
+ end
266
+
267
+ context "on GET to /encoding_tasks/new/:encoder_id" do
268
+ context "without credentials" do
269
+ setup do
270
+ get "/encoding_tasks/new/#{Encoder.first.id}"
271
+ end
272
+
273
+ should "respond with security error" do
274
+ assert !last_response.ok?
275
+ assert_equal 401, status
276
+ end
277
+ end
278
+
279
+ context "with credentials" do
280
+ setup do
281
+ get "/encoding_tasks/new/#{Encoder.first.id}", {}, basic_auth_creds
282
+ end
283
+
284
+ should "work" do
285
+ assert last_response.ok?
286
+ end
287
+ end
288
+ end
289
+
290
+
291
+ context "on GET to /encoding_tasks/:id/edit" do
292
+ context "without credentials" do
293
+ setup do
294
+ get "/encoding_tasks/#{Encoder.first.id}/edit"
295
+ end
296
+
297
+ should "respond with security error" do
298
+ assert !last_response.ok?
299
+ assert_equal 401, status
300
+ end
301
+ end
302
+
303
+ context "with credentials" do
304
+ setup do
305
+ get "/encoding_tasks/#{Encoder.first.id}/edit", {}, basic_auth_creds
306
+ end
307
+
308
+ should "work" do
309
+ assert last_response.ok?
310
+ end
311
+ end
312
+ end
313
+
314
+
315
+ context "on POST to /encoding_tasks/:encoder_id" do
316
+ context "without credentials" do
317
+ setup do
318
+ post "/encoding_tasks/#{Encoder.first.id}"
319
+ end
320
+
321
+ should "respond with security error" do
322
+ assert !last_response.ok?
323
+ assert_equal 401, status
324
+ end
325
+ end
326
+
327
+ context "with credentials" do
328
+ context "and valid EncodingTask params" do
329
+ setup do
330
+ @num_tasks = EncodingTask.count
331
+ post "/encoding_tasks/#{Encoder.first.id}", {:encoding_task => EncodingTask.plan}, basic_auth_creds
332
+ follow_redirect!
333
+ end
334
+
335
+ should "create a new encoding task" do
336
+ assert_equal @num_tasks + 1, EncodingTask.count
337
+ end
338
+
339
+ should "redirect to parent encoder show page" do
340
+ assert_equal "http://example.org/encoders/#{Encoder.first.id}", last_request.url
341
+ end
342
+ end
343
+
344
+ context "and invalid EncodingTask params" do
345
+ setup do
346
+ @num_tasks = EncodingTask.count
347
+ post "/encoding_tasks/#{Encoder.first.id}", {
348
+ :encoding_task => EncodingTask.plan.merge(:name => "")}, basic_auth_creds
349
+ end
350
+
351
+ should "not create a new encoding task" do
352
+ assert_equal @num_tasks, EncodingTask.count
353
+ end
354
+
355
+ should "redisplay the EncodingTask form" do
356
+ assert last_response.ok?
357
+ end
358
+ end
359
+ end
360
+ end
361
+
362
+ context "on PUT to /encoding_tasks/:id" do
363
+ context "without credentials" do
364
+ setup do
365
+ put "/encoding_tasks/#{Encoder.first.id}"
366
+ end
367
+
368
+ should "respond with security error" do
369
+ assert !last_response.ok?
370
+ assert_equal 401, status
371
+ end
372
+ end
373
+
374
+ context "with credentials" do
375
+ context "and valid EncodingTask params" do
376
+ setup do
377
+ @encoding_task = EncodingTask.make(:with_encoder)
378
+ @num_tasks = EncodingTask.count
379
+ put "/encoding_tasks/#{@encoding_task.id}", {:id => @encoding_task.id, :encoding_task => EncodingTask.plan}, basic_auth_creds
380
+ follow_redirect!
381
+ end
382
+
383
+ should "not create a new encoding task" do
384
+ assert_equal @num_tasks, EncodingTask.count
385
+ end
386
+
387
+ should "redirect to parent encoder show page" do
388
+ assert_equal "http://example.org/encoders/#{@encoding_task.encoder.id}", last_request.url
389
+ end
390
+ end
391
+
392
+ context "and invalid EncodingTask params" do
393
+ setup do
394
+ @encoding_task = EncodingTask.make(:with_encoder)
395
+ @num_tasks = EncodingTask.count
396
+ put "/encoding_tasks/#{@encoding_task.id}", {
397
+ :encoding_task => EncodingTask.plan.merge(:name => "")}, basic_auth_creds
398
+ end
399
+
400
+ should "not create a new encoding task" do
401
+ assert_equal @num_tasks, EncodingTask.count
402
+ end
403
+
404
+ should "redisplay the EncodingTask form" do
405
+ assert last_response.ok?
406
+ end
407
+ end
408
+ end
409
+ end
410
+
411
+ context "on DELETE to /encoding_tasks/:id" do
412
+ context "without credentials" do
413
+ setup do
414
+ @task = EncodingTask.make
415
+ delete "/encoding_tasks/#{@task.id}"
416
+ end
417
+
418
+ should "respond with security error" do
419
+ assert !last_response.ok?
420
+ assert_equal 401, status
421
+ end
422
+ end
423
+
424
+ context "with credentials" do
425
+ setup do
426
+ @task = EncodingTask.make
427
+ @num_tasks = EncodingTask.count
428
+ delete "/encoding_tasks/#{@task.id}", {:id => @task.id}, basic_auth_creds
429
+ end
430
+
431
+ should "destroy the task" do
432
+ assert_equal @num_tasks - 1, EncodingTask.count
433
+ end
434
+
435
+ end
436
+ end
437
+
438
+
439
+ context "on GET to /videos" do
440
+ context "without credentials" do
441
+ setup do
442
+ get "/videos"
443
+ end
444
+
445
+ should "respond with security error" do
446
+ assert !last_response.ok?
447
+ assert_equal 401, status
448
+ end
449
+ end
450
+
451
+ context "with credentials" do
452
+ setup do
453
+ get "/videos", {}, basic_auth_creds
454
+ end
455
+
456
+ should "work" do
457
+ assert last_response.ok?
458
+ end
459
+ end
460
+ end
461
+
462
+ context "on GET to /videos/new" do
463
+ context "without credentials" do
464
+ setup do
465
+ get "/videos/new"
466
+ end
467
+
468
+ should "respond with security error" do
469
+ assert !last_response.ok?
470
+ assert_equal 401, status
471
+ end
472
+ end
473
+ end
474
+
475
+ context "with credentials" do
476
+ setup do
477
+ get "/videos/new", {}, basic_auth_creds
478
+ end
479
+
480
+ should "work" do
481
+ assert last_response.ok?
482
+ end
483
+ end
484
+
485
+ context "on POST to /videos" do
486
+ context "without credentials" do
487
+ setup do
488
+ post "/videos", {:video => Video.plan}
489
+ end
490
+
491
+ should "respond with security error" do
492
+ assert !last_response.ok?
493
+ assert_equal 401, status
494
+ end
495
+ end
496
+
497
+ context "with credentials" do
498
+ context "and valid video params" do
499
+ setup do
500
+ @num_videos = Video.count
501
+ post "/videos", {
502
+ :video => Video.plan,
503
+ :encoder_id => Encoder.make.id}, basic_auth_creds
504
+ follow_redirect!
505
+ end
506
+
507
+ should "create a video" do
508
+ assert_equal @num_videos + 1, Video.count
509
+ end
510
+
511
+ should "redirect to /videos" do
512
+ assert_equal "http://example.org/videos", last_request.url
513
+ end
514
+ end
515
+
516
+ context "and invalid video params" do
517
+ setup do
518
+ @num_videos = Video.count
519
+ post "/videos", {
520
+ :video => Video.plan.merge(:file => ""),
521
+ :encoder_id => Encoder.make.id}, basic_auth_creds
522
+ end
523
+
524
+ should "not create a new video" do
525
+ assert_equal @num_videos, Video.count
526
+ end
527
+
528
+ should "redisplay the video form" do
529
+ assert last_response.ok?
530
+ end
531
+ end
532
+ end
533
+ end
534
+
535
+ end
536
+
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestVideo < Test::Unit::TestCase
4
+
5
+
6
+ context "A Video instance" do
7
+
8
+ should "be invalid without a file path" do
9
+ resource = ::Video.make_unsaved
10
+ resource.file = ""
11
+ assert !resource.valid?
12
+ resource.file = nil
13
+ assert !resource.valid?
14
+ end
15
+
16
+ should "be valid with a file path" do
17
+ resource = ::Video.make
18
+ resource.file = "foo.mpg"
19
+ assert resource.valid?
20
+ end
21
+
22
+ should "belong to an Encoder" do
23
+ v = Video.make_unsaved
24
+ assert v.respond_to? "encoder"
25
+ end
26
+
27
+ should "allow itself to be associated with an Encoder" do
28
+ v = Video.make_unsaved
29
+ e = Encoder.make_unsaved
30
+ assert_nothing_raised do
31
+ v.encoder = e
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ context "The Video class" do
38
+
39
+ should "be able to grab all unencoded videos" do
40
+ assert Video.respond_to? "unencoded"
41
+ end
42
+
43
+ context "when one Video exists" do
44
+ setup do
45
+ clear_videos
46
+ Video.make(:state => "unencoded")
47
+ end
48
+
49
+ should "have one unencoded video" do
50
+ assert_equal 1, Video.unencoded.count
51
+ end
52
+ end
53
+
54
+ context "when two Videos exist" do
55
+ setup do
56
+ clear_videos
57
+ 2.times { Video.make }
58
+ end
59
+
60
+ should "have two unencoded videos" do
61
+ assert_equal 2, Video.unencoded.count
62
+ end
63
+ end
64
+
65
+ should "be able to grab all completed videos" do
66
+ assert Video.respond_to? "complete"
67
+ end
68
+
69
+ should "be able to grab all videos with errors" do
70
+ assert Video.respond_to? "with_errors"
71
+ end
72
+
73
+ should "be able to grab all videos that are encoding" do
74
+ assert Video.respond_to? "encoding"
75
+ end
76
+
77
+ end
78
+
79
+ def clear_videos
80
+ Video.all.each {|v| v.destroy }
81
+ end
82
+
83
+ end
84
+