fogged 0.0.2

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 (89) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/controllers/fogged/resources_controller.rb +259 -0
  5. data/app/jobs/fogged/resources/zencoder_poll_job.rb +39 -0
  6. data/app/models/fogged/resource.rb +153 -0
  7. data/app/models/fogged/resources/aws_encoder.rb +64 -0
  8. data/app/models/fogged/resources/encoder.rb +13 -0
  9. data/app/serializers/fogged/resource_serializer.rb +35 -0
  10. data/config/locales/en.yml +6 -0
  11. data/config/locales/fr.yml +6 -0
  12. data/config/routes.rb +4 -0
  13. data/db/migrate/20141103143408_create_fogged_resources.rb +20 -0
  14. data/lib/fogged.rb +46 -0
  15. data/lib/fogged/acts_as_having_many_resources.rb +30 -0
  16. data/lib/fogged/acts_as_having_one_resource.rb +34 -0
  17. data/lib/fogged/engine.rb +50 -0
  18. data/lib/fogged/version.rb +3 -0
  19. data/lib/tasks/fogged_tasks.rake +4 -0
  20. data/test/controllers/fogged/resources_controller/confirm_test.rb +56 -0
  21. data/test/controllers/fogged/resources_controller/create_test.rb +56 -0
  22. data/test/controllers/fogged/resources_controller/destroy_test.rb +29 -0
  23. data/test/controllers/fogged/resources_controller/show_test.rb +35 -0
  24. data/test/controllers/fogged/resources_controller/update_test.rb +31 -0
  25. data/test/dummy/Rakefile +6 -0
  26. data/test/dummy/app/assets/javascripts/application.js +13 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/test/dummy/app/controllers/application_controller.rb +5 -0
  29. data/test/dummy/app/controllers/images_controller.rb +5 -0
  30. data/test/dummy/app/helpers/application_helper.rb +2 -0
  31. data/test/dummy/app/models/image.rb +3 -0
  32. data/test/dummy/app/models/movie.rb +4 -0
  33. data/test/dummy/app/models/movie_fogged_resource.rb +4 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/bin/bundle +3 -0
  36. data/test/dummy/bin/delayed_job +5 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/bin/rake +4 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +23 -0
  41. data/test/dummy/config/boot.rb +5 -0
  42. data/test/dummy/config/database.yml +25 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +37 -0
  45. data/test/dummy/config/environments/production.rb +78 -0
  46. data/test/dummy/config/environments/test.rb +39 -0
  47. data/test/dummy/config/initializers/assets.rb +8 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/test/dummy/config/initializers/fog.rb +1 -0
  52. data/test/dummy/config/initializers/fogged.rb +7 -0
  53. data/test/dummy/config/initializers/inflections.rb +16 -0
  54. data/test/dummy/config/initializers/mime_types.rb +4 -0
  55. data/test/dummy/config/initializers/session_store.rb +3 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +23 -0
  58. data/test/dummy/config/routes.rb +4 -0
  59. data/test/dummy/config/secrets.yml +22 -0
  60. data/test/dummy/db/development.sqlite3 +0 -0
  61. data/test/dummy/db/migrate/20141104135257_create_images.rb +10 -0
  62. data/test/dummy/db/migrate/20141104152227_create_movies.rb +9 -0
  63. data/test/dummy/db/migrate/20141104152345_create_movie_fogged_resources.rb +10 -0
  64. data/test/dummy/db/migrate/20141105073909_create_delayed_jobs.rb +22 -0
  65. data/test/dummy/db/schema.rb +72 -0
  66. data/test/dummy/db/test.sqlite3 +0 -0
  67. data/test/dummy/log/development.log +234 -0
  68. data/test/dummy/log/test.log +20250 -0
  69. data/test/dummy/public/404.html +67 -0
  70. data/test/dummy/public/422.html +67 -0
  71. data/test/dummy/public/500.html +66 -0
  72. data/test/dummy/public/favicon.ico +0 -0
  73. data/test/dummy/test/controllers/resources_controller/index_test.rb +56 -0
  74. data/test/dummy/test/models/image_test.rb +24 -0
  75. data/test/dummy/test/models/movie_test.rb +26 -0
  76. data/test/fixtures/fogged/resources.yml +31 -0
  77. data/test/fixtures/images.yml +5 -0
  78. data/test/fixtures/movie_fogged_resources.yml +19 -0
  79. data/test/fixtures/movies.yml +8 -0
  80. data/test/fogged_test.rb +7 -0
  81. data/test/integration/navigation_test.rb +10 -0
  82. data/test/jobs/fogged/resources/zencoder_poll_job_test.rb +92 -0
  83. data/test/models/fogged/resource_test.rb +97 -0
  84. data/test/models/fogged/resources/aws_encoder_test.rb +54 -0
  85. data/test/models/fogged/resources/encoder_test.rb +18 -0
  86. data/test/support/concerns/json_test_helper.rb +43 -0
  87. data/test/support/concerns/resource_test_helper.rb +28 -0
  88. data/test/test_helper.rb +59 -0
  89. metadata +354 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,56 @@
1
+ require "test_helper"
2
+
3
+ class ResourcesControllerIndexTest < ActionController::TestCase
4
+ tests Fogged::ResourcesController
5
+ include ResourceTestHelper
6
+
7
+ def setup
8
+ super
9
+ @movie = movies(:movie_one)
10
+ end
11
+
12
+ test "should index all resources for movies" do
13
+ get :index, :type => "movie", :use_route => :fogged
14
+
15
+ assert_json_resources(Movie.all.map(&:resources).flatten)
16
+ end
17
+
18
+ test "should index resources for a movie" do
19
+ get :index, :type => "movie", :type_id => @movie.id, :use_route => :fogged
20
+
21
+ assert_json_resources(@movie.resources.to_a)
22
+ end
23
+
24
+ test "should index resources for movies" do
25
+ resources = movies(:movie_one, :movie_two).map(&:resources).flatten
26
+ get :index,
27
+ :type => "movie",
28
+ :type_ids => movies(:movie_one, :movie_two).map(&:id),
29
+ :use_route => :fogged
30
+
31
+ assert_json_resources(resources)
32
+ end
33
+
34
+ test "should index resources for a movie with search query on name" do
35
+ res = Fogged::Resource.create(
36
+ :name => "footest barish",
37
+ :extension => "txt",
38
+ :content_type => "text/plain"
39
+ )
40
+ @movie.resources << res
41
+
42
+ get :index,
43
+ :type => "movie",
44
+ :type_id => @movie.id,
45
+ :query => "test",
46
+ :use_route => :fogged
47
+
48
+ assert_json_resources([res])
49
+ end
50
+
51
+ test "should index resources with invalid movie id" do
52
+ get :index, :type => "movie", :type_id => 1234567890, :use_route => :fogged
53
+
54
+ assert_json_resources([])
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class ImageTest < ActiveSupport::TestCase
4
+ def setup
5
+ super
6
+ @image = Image.new(:name => "test")
7
+ end
8
+
9
+ test "should save image without resource" do
10
+ assert @image.save
11
+ end
12
+
13
+ test "should save image with uploaded resource" do
14
+ assert @image.update(:resource => fogged_resources(:resource_text_1))
15
+
16
+ end
17
+
18
+ test "should not save image with uploading resource" do
19
+ resource = fogged_resources(:resource_text_1)
20
+ resource.update!(:uploading => true)
21
+
22
+ refute @image.update(:resource => resource)
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class MovieTest < ActiveSupport::TestCase
4
+ def setup
5
+ @movie = Movie.new(:name => "test")
6
+ end
7
+
8
+ test "should save movie with no resources" do
9
+ assert @movie.save
10
+ end
11
+
12
+ test "should save movie with several resources" do
13
+ @movie.resources = fogged_resources(:resource_text_1, :resource_text_2)
14
+
15
+ assert @movie.save
16
+ end
17
+
18
+ test "should not save movie with uploading resource" do
19
+ @movie.resources = fogged_resources(:resource_text_1, :resource_text_2)
20
+ resource = fogged_resources(:resource_text_4)
21
+ resource.update!(:uploading => true)
22
+ @movie.resources << resource
23
+
24
+ refute @movie.save
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ <% 5.times do |n| %>
2
+ resource_text_<%= n %>:
3
+ extension: txt
4
+ uploading: false
5
+ content_type: text/plain
6
+ name: resource text <%= n %>
7
+ token: qwertzuiop<%= n %>
8
+ <% end %>
9
+
10
+ resource_mov:
11
+ extension: mov
12
+ uploading: false
13
+ content_type: video/quicktime
14
+ name: resource mov 1
15
+ token: 1234567890mov
16
+
17
+ resource_png:
18
+ extension: png
19
+ uploading: false
20
+ content_type: image/png
21
+ name: resource png 1
22
+ token: 1234567890png
23
+
24
+ encoding_resource:
25
+ extension: mov
26
+ uploading: false
27
+ content_type: video/quicktime
28
+ name: resource mov 1
29
+ token: 1234567890mov
30
+ encoding_job_id: 1234567890
31
+ encoding_progress: 10
@@ -0,0 +1,5 @@
1
+ image_one:
2
+ name: image one
3
+
4
+ image_two:
5
+ name: image two
@@ -0,0 +1,19 @@
1
+ movie_one_resource_one:
2
+ movie: movie_one
3
+ resource: resource_text_1
4
+
5
+ movie_one_resource_two:
6
+ movie: movie_one
7
+ resource: resource_text_2
8
+
9
+ movie_two_resource_one:
10
+ movie: movie_two
11
+ resource: resource_text_3
12
+
13
+ movie_two_resource_two:
14
+ movie: movie_two
15
+ resource: resource_text_4
16
+
17
+ movie_two_resource_one:
18
+ movie: movie_two
19
+ resource: resource_text_5
@@ -0,0 +1,8 @@
1
+ movie_one:
2
+ name: Movie one
3
+
4
+ movie_two:
5
+ name: Movie two
6
+
7
+ movie_three:
8
+ name: Movie three
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class FoggedTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Fogged
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,92 @@
1
+ require "test_helper"
2
+
3
+ module Fogged
4
+ module Resources
5
+ class ZencoderPollJobTest < ActiveSupport::TestCase
6
+ def setup
7
+ super
8
+ @resource = fogged_resources(:encoding_resource)
9
+ @job = ZencoderPollJob.new(@resource.id)
10
+ end
11
+
12
+ test "should poll job with status success" do
13
+ in_a_fork do
14
+ require "zencoder"
15
+ require "delayed_job_active_record"
16
+
17
+ Zencoder::Job.expects(:progress).with("1234567890").returns(
18
+ OpenStruct.new(:body => progress_output("finished"))
19
+ )
20
+ Zencoder::Job.expects(:details).with("1234567890").returns(
21
+ OpenStruct.new(:body => details_output)
22
+ )
23
+
24
+ assert_no_difference("Delayed::Job.count") do
25
+ @job.perform
26
+ end
27
+ refute @resource.reload.encoding?
28
+ assert_equal 800, @resource.width
29
+ assert_equal 600, @resource.height
30
+ assert_equal 15, @resource.duration
31
+ end
32
+ end
33
+
34
+ %w(processing waiting).each do |status|
35
+ test "should poll job with status #{status}" do
36
+ in_a_fork do
37
+ require "zencoder"
38
+ require "delayed_job_active_record"
39
+
40
+ Zencoder::Job.expects(:progress).with("1234567890").returns(
41
+ OpenStruct.new(:body => progress_output(status))
42
+ )
43
+
44
+ assert_difference("Delayed::Job.count") do
45
+ @job.perform
46
+ end
47
+ assert @resource.reload.encoding?
48
+ assert_equal 55, @resource.encoding_progress
49
+ end
50
+ end
51
+ end
52
+
53
+ test "should poll job with status unknown" do
54
+ in_a_fork do
55
+ require "zencoder"
56
+ require "delayed_job_active_record"
57
+
58
+ Zencoder::Job.expects(:progress).with("1234567890").returns(
59
+ OpenStruct.new(:body => progress_output("unknown"))
60
+ )
61
+
62
+ assert_raise(ArgumentError) do
63
+ assert_no_difference("Delayed::Job.count") do
64
+ @job.perform
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def progress_output(state)
73
+ {
74
+ :state => state,
75
+ :progress => "55.5"
76
+ }.with_indifferent_access
77
+ end
78
+
79
+ def details_output
80
+ {
81
+ :job => {
82
+ :output_media_files => [{
83
+ :width => 800,
84
+ :height => 600,
85
+ :duration_in_ms => 15753
86
+ }]
87
+ }
88
+ }.with_indifferent_access
89
+ end
90
+ end
91
+ end
92
+ end