phocoder-rails 0.0.33

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 (116) hide show
  1. data/.autotest +46 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +44 -0
  5. data/LICENSE.txt +20 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +3 -0
  8. data/Rakefile +56 -0
  9. data/VERSION +5 -0
  10. data/app/controllers/phocoder_controller.rb +118 -0
  11. data/app/helpers/phocoder_helper.rb +320 -0
  12. data/app/models/encodable_job.rb +91 -0
  13. data/app/views/phocoder/_offline_video_embed.html.erb +19 -0
  14. data/app/views/phocoder/_thumbnail_update.html.erb +3 -0
  15. data/app/views/phocoder/_video_embed.html.erb +23 -0
  16. data/app/views/phocoder/multi_thumbnail_update.json.erb +7 -0
  17. data/app/views/phocoder/thumbnail_update.js.erb +9 -0
  18. data/config/routes.rb +8 -0
  19. data/lib/generators/phocoder_rails/model_update_generator.rb +52 -0
  20. data/lib/generators/phocoder_rails/scaffold_generator.rb +94 -0
  21. data/lib/generators/phocoder_rails/setup_generator.rb +33 -0
  22. data/lib/generators/phocoder_rails/templates/controller.rb +71 -0
  23. data/lib/generators/phocoder_rails/templates/helper.rb +5 -0
  24. data/lib/generators/phocoder_rails/templates/migration.rb +24 -0
  25. data/lib/generators/phocoder_rails/templates/model.rb +20 -0
  26. data/lib/generators/phocoder_rails/templates/model_migration.rb +56 -0
  27. data/lib/generators/phocoder_rails/templates/model_thumbnail.rb +5 -0
  28. data/lib/generators/phocoder_rails/templates/model_update_migration.rb +64 -0
  29. data/lib/generators/phocoder_rails/templates/phocodable.yml +28 -0
  30. data/lib/generators/phocoder_rails/templates/views/_form.html.erb.tt +23 -0
  31. data/lib/generators/phocoder_rails/templates/views/index.html.erb.tt +26 -0
  32. data/lib/generators/phocoder_rails/templates/views/new.html.erb.tt +5 -0
  33. data/lib/generators/phocoder_rails/templates/views/show.html.erb.tt +12 -0
  34. data/lib/phocoder_rails.rb +12 -0
  35. data/lib/phocoder_rails/acts_as_phocodable.rb +1153 -0
  36. data/lib/phocoder_rails/engine.rb +24 -0
  37. data/lib/phocoder_rails/errors.rb +46 -0
  38. data/phocoder-rails.gemspec +219 -0
  39. data/public/images/building.gif +0 -0
  40. data/public/images/error.png +0 -0
  41. data/public/images/play_small.png +0 -0
  42. data/public/images/storing.gif +0 -0
  43. data/public/images/waiting.gif +0 -0
  44. data/public/javascripts/phocodable.js +110 -0
  45. data/public/javascripts/video-js-2.0.2/.DS_Store +0 -0
  46. data/public/javascripts/video-js-2.0.2/LICENSE.txt +165 -0
  47. data/public/javascripts/video-js-2.0.2/README.markdown +202 -0
  48. data/public/javascripts/video-js-2.0.2/demo-subtitles.srt +13 -0
  49. data/public/javascripts/video-js-2.0.2/demo.html +101 -0
  50. data/public/javascripts/video-js-2.0.2/skins/hu.css +116 -0
  51. data/public/javascripts/video-js-2.0.2/skins/tube.css +111 -0
  52. data/public/javascripts/video-js-2.0.2/skins/vim.css +89 -0
  53. data/public/javascripts/video-js-2.0.2/video-js.css +242 -0
  54. data/public/javascripts/video-js-2.0.2/video.js +1758 -0
  55. data/public/stylesheets/phocodable.css +19 -0
  56. data/spec/controllers/phocoder_controller_spec.rb +123 -0
  57. data/spec/dummy/Rakefile +7 -0
  58. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  59. data/spec/dummy/app/controllers/images_controller.rb +72 -0
  60. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  61. data/spec/dummy/app/helpers/images_helper.rb +5 -0
  62. data/spec/dummy/app/models/image.rb +20 -0
  63. data/spec/dummy/app/models/image_thumbnail.rb +5 -0
  64. data/spec/dummy/app/models/image_upload.rb +11 -0
  65. data/spec/dummy/app/views/images/_form.html.erb +23 -0
  66. data/spec/dummy/app/views/images/index.html.erb +26 -0
  67. data/spec/dummy/app/views/images/new.html.erb +5 -0
  68. data/spec/dummy/app/views/images/show.html.erb +12 -0
  69. data/spec/dummy/app/views/layouts/application.html.erb +18 -0
  70. data/spec/dummy/config.ru +4 -0
  71. data/spec/dummy/config/application.rb +45 -0
  72. data/spec/dummy/config/boot.rb +10 -0
  73. data/spec/dummy/config/database.yml +25 -0
  74. data/spec/dummy/config/environment.rb +8 -0
  75. data/spec/dummy/config/environments/development.rb +26 -0
  76. data/spec/dummy/config/environments/production.rb +49 -0
  77. data/spec/dummy/config/environments/test.rb +40 -0
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/spec/dummy/config/initializers/inflections.rb +10 -0
  80. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  81. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  82. data/spec/dummy/config/initializers/session_store.rb +8 -0
  83. data/spec/dummy/config/locales/en.yml +5 -0
  84. data/spec/dummy/config/routes.rb +60 -0
  85. data/spec/dummy/db/migrate/001_create_image_uploads.rb +37 -0
  86. data/spec/dummy/db/migrate/20110523165213_add_parent_type_to_image_uploads.rb +11 -0
  87. data/spec/dummy/db/migrate/20110523165522_create_encodable_jobs.rb +24 -0
  88. data/spec/dummy/db/migrate/20111101024507_create_images.rb +56 -0
  89. data/spec/dummy/db/schema.rb +99 -0
  90. data/spec/dummy/public/404.html +26 -0
  91. data/spec/dummy/public/422.html +26 -0
  92. data/spec/dummy/public/500.html +26 -0
  93. data/spec/dummy/public/favicon.ico +0 -0
  94. data/spec/dummy/public/index.html +239 -0
  95. data/spec/dummy/public/javascripts/application.js +2 -0
  96. data/spec/dummy/public/javascripts/controls.js +965 -0
  97. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  98. data/spec/dummy/public/javascripts/effects.js +1123 -0
  99. data/spec/dummy/public/javascripts/jquery-1.6.4.js +9046 -0
  100. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  101. data/spec/dummy/public/javascripts/rails.js +175 -0
  102. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  103. data/spec/dummy/script/rails +6 -0
  104. data/spec/engine_spec.rb +12 -0
  105. data/spec/fixtures/big_eye_tiny.jpg +0 -0
  106. data/spec/fixtures/octologo.png +0 -0
  107. data/spec/fixtures/test.txt +2 -0
  108. data/spec/fixtures/video-test.mov +0 -0
  109. data/spec/helpers/phocoder_helper_spec.rb +421 -0
  110. data/spec/integration/navigation_spec.rb +10 -0
  111. data/spec/models/acts_as_phocodable_spec.rb +664 -0
  112. data/spec/models/encodable_job_spec.rb +50 -0
  113. data/spec/phocoder_rails_spec.rb +8 -0
  114. data/spec/routing/phocoder_routing_spec.rb +19 -0
  115. data/spec/spec_helper.rb +75 -0
  116. metadata +375 -0
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ describe PhocoderRails::Engine do
5
+
6
+ it "should be valid" do
7
+ PhocoderRails::Engine.should be_a(Class)
8
+ end
9
+
10
+
11
+
12
+ end
Binary file
Binary file
@@ -0,0 +1,2 @@
1
+ This is a file that the plugin should not try to encode. Just place it an leave it.
2
+
Binary file
@@ -0,0 +1,421 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PhocoderHelper do #, :debug=>true
4
+
5
+ before(:each) do
6
+ @attr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'),:width => 200,:height=>197 }
7
+ @image = ImageUpload.new(@attr)
8
+ ActsAsPhocodable.storeage_mode = "local"
9
+ ActsAsPhocodable.processing_mode = "automatic"
10
+ end
11
+
12
+ describe "phocoder_includes" do
13
+ it "should include a javascript tag" do
14
+ helper.phocoder_includes.should match /phocodable.js/
15
+ end
16
+ it "should include a stylesheet tag" do
17
+ helper.phocoder_includes.should match /phocodable.css/
18
+ end
19
+ end
20
+
21
+ describe "phocoder_video_includes" do
22
+ it "should include a javascript tag" do
23
+ helper.phocoder_video_includes.should match /video.js/
24
+ end
25
+ it "should include a stylesheet tag" do
26
+ helper.phocoder_video_includes.should match /video-js.css/
27
+ end
28
+ end
29
+
30
+ describe "phocoder_link" do
31
+ before(:each) do
32
+ @attr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg') }
33
+ @image = ImageUpload.new(@attr)
34
+ end
35
+ it "should return raw text if the file is not ready" do
36
+ @image.encodable_status = "phocoding"
37
+ helper.phocoder_link("my link",@image).should == "my link"
38
+ end
39
+ it "should return a link if the file is ready" do
40
+ @image.encodable_status = "ready"
41
+ link = helper.phocoder_link("my link",@image)
42
+ puts "link = #{link}"
43
+ link.should match /my link/
44
+ link.should match /<a/
45
+ link.should match /href/
46
+ end
47
+ end
48
+
49
+
50
+ describe "phocoder_thumbnail" do
51
+ it "should delegate to phocoder_video_thumbnail for videos" do
52
+ vid = ImageUpload.new(:content_type=>'video/quicktime',:zencoder_status=>'s3',:id=>1,:filename=>"test.mov")
53
+ helper.should_receive(:phocoder_video_thumbnail).and_return(nil)
54
+ helper.phocoder_thumbnail(vid)
55
+ end
56
+ it "should delegate to phocoder_image_thumbnail for images" do
57
+ img = ImageUpload.new({ :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg') })
58
+ helper.should_receive(:phocoder_image_thumbnail).and_return(nil)
59
+ helper.phocoder_thumbnail(img)
60
+ end
61
+ it "should return an error div for elements that arent' video or image" do
62
+ obj = ImageUpload.new(:content_type=>'text/plain')
63
+ #puts "====================================================================================="
64
+ #puts "encodable.video? = #{obj.video?} - encodable.image? = #{obj.image?}"
65
+ #puts "helper.phocoder_thumbnail(obj) = #{helper.phocoder_thumbnail(obj)}"
66
+ #helper.should_receive(:error_div)
67
+ helper.phocoder_thumbnail(obj).should match /not an image or a video/
68
+ end
69
+ end
70
+
71
+ describe "phocoder_image_thumbnail" do
72
+
73
+ it "should call phocoder_image_offline if mode is offline" do
74
+ ActsAsPhocodable.storeage_mode = "offline"
75
+ helper.should_receive(:phocoder_image_offline).and_return(nil)
76
+ helper.phocoder_image_thumbnail(@image,nil,{})
77
+ end
78
+
79
+ it "should call phocoder_image_online if mode is not offline" do
80
+ ActsAsPhocodable.storeage_mode = "local"
81
+ helper.should_receive(:phocoder_image_online).and_return(nil)
82
+ helper.phocoder_image_thumbnail(@image,nil,{})
83
+ end
84
+
85
+ #it "should call display_image when the thumbnail is blank" do
86
+ # helper.should_receive(:display_image).and_return(nil)
87
+ # helper.phocoder_image_thumbnail(@image,nil,{})
88
+ #end
89
+
90
+ #it "should call find_or_create_thumbnail and then call display_thumbnail if a thumbnail is found" do
91
+ # helper.should_receive(:find_or_create_thumbnail).and_return(@image)
92
+ # helper.should_receive(:display_image_thumbnail).and_return(nil)
93
+ # helper.phocoder_image_thumbnail(@image,"test_thumb",{})
94
+ #end
95
+
96
+ #it "should call find_or_create_thumbnail and then call error_div if a thumbnail is not found" do
97
+ # helper.should_receive(:find_or_create_thumbnail).and_return(nil)
98
+ # helper.should_receive(:error_div).and_return(nil)
99
+ # helper.phocoder_image_thumbnail(@image,"test_thumb",{})
100
+ #end
101
+ end
102
+
103
+ describe "phocoder_image_offline" do
104
+
105
+ it "should return an error when !image.web_safe? and thumbnail.blank?" do
106
+ @image.content_type = "image/x-nikon-nef"
107
+ @image.web_safe?.should be_false
108
+ output = helper.phocoder_image_offline(@image,nil,{})
109
+ output.should match /phocoder_error/
110
+ output.should match @image.content_type
111
+ end
112
+
113
+ it "should return an image tag when image.web_safe? and thumbnail.blank?" do
114
+ output = phocoder_image_offline(@image,nil,{})
115
+ output.should match /<img/
116
+ output.should_not match /width/
117
+ output.should match @image.filename # the path in the thumbnail
118
+ end
119
+
120
+ it "should return an img tag when the thumbnail can be resolved" do
121
+ output = helper.phocoder_image_offline(@image,"small",{})
122
+ output.should match /<img/
123
+ output.should match /width=\"100\"/
124
+ end
125
+
126
+ it "should return an error if thumbnail attributes are not found" do
127
+ output = helper.phocoder_image_offline(@image,"bad-thumb",{})
128
+ output.should match /phocoder_error/
129
+ output.should match /bad-thumb/
130
+ end
131
+
132
+ #it "should return an image for the thumbnail if it's found and ready?" do
133
+ # pending "do this look at moving the stuff below. Refactor that shit!"
134
+ #end
135
+
136
+ #it "should return a pending image for the thumbnail if it's found and !ready?" do
137
+ # pending "do this"
138
+ #end
139
+
140
+ end
141
+
142
+ describe "phocoder_image_online" do
143
+
144
+ describe "when no thumbnail is passed" do
145
+ it "should return an error div if !image.web_safe" do
146
+ @image.content_type = "image/x-nikon-nef"
147
+ @image.web_safe?.should be_false
148
+ output = helper.phocoder_image_online(@image,nil,{})
149
+ output.should match /phocoder_error/
150
+ output.should match @image.content_type
151
+ end
152
+ it "should return an img tag with no width and height if !image.ready? and image.web_safe?" do
153
+ @image.encodable_status = 'phocoding'
154
+ output = phocoder_image_online(@image,nil,{})
155
+ output.should match /<img/
156
+ output.should_not match /width/
157
+ output.should match @image.filename # the path in the original
158
+ end
159
+ it "should return an img tag with width and height if image.ready? and image.web_safe?" do
160
+ @image.encodable_status = 'ready'
161
+ output = phocoder_image_online(@image,nil,{})
162
+ output.should match /<img/
163
+ output.should match /width/
164
+ output.should match @image.filename # the path in the original
165
+ end
166
+ end #describe "when no thumbnail is passed" do
167
+ describe "when a thumbnail is passed" do
168
+ it "should return an img tag for a thumbnail that can be resolved by label and is ready" do
169
+ ActsAsPhocodable.storeage_mode = "local"
170
+ @tattr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'), :width => 100, :height => 100 }
171
+ @thumb = ImageUpload.new(@tattr)
172
+ @thumb.filename = "big_eye_tiny_small.jpg"
173
+ @thumb.encodable_status = @image.encodable_status = "ready"
174
+ helper.should_receive(:find_or_create_thumbnail).and_return(@thumb)
175
+ output = helper.phocoder_image_online(@image,"small",{})
176
+ output.should match /<img/
177
+ output.should match /width="100"/
178
+ output.should match @thumb.filename # the path in the thumbnail
179
+ end
180
+
181
+ it "should create a thumbnail and return an img tag for a new size string" do
182
+ ActsAsPhocodable.storeage_mode = "local"
183
+ output = helper.phocoder_image_online(@image,"100x100",{})
184
+ output.should match /<img/
185
+ output.should match /width="100"/
186
+ output.should match /waiting\.gif/ # the path in the thumbnail
187
+ end
188
+
189
+ it "should call pending_phcoder_thumbnail if the thumb is not ready" do
190
+ ActsAsPhocodable.storeage_mode = "local"
191
+ @tattr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'), :width => 100, :height => 100 }
192
+ @thumb = ImageUpload.new(@tattr)
193
+ @thumb.filename = "big_eye_tiny_small.jpg"
194
+ @thumb.encodable_status = "phocoding"
195
+ @image.encodable_status = "ready"
196
+ helper.should_receive(:find_or_create_thumbnail).and_return(@thumb)
197
+ #helper.should_receive(:pending_phocoder_thumbnail)
198
+ output = helper.phocoder_image_online(@image,"small",{})
199
+ output.should match /waiting\.gif/ # the path in the thumbnail
200
+ end
201
+ it "should call pending_phcoder_thumbnail if the image is not ready" do
202
+ ActsAsPhocodable.storeage_mode = "local"
203
+ @image.encodable_status = "phocoding"
204
+ #helper.should_receive(:pending_phocoder_thumbnail)
205
+ output = helper.phocoder_image_online(@image,"small",{})
206
+ output.should match /waiting\.gif/ # the path in the thumbnail
207
+ end
208
+ it "should return an error div if the thumb can not be resolved" do
209
+ output = helper.phocoder_image_online(@image,"bad-thumb",{})
210
+ output.should match /phocoder_error/
211
+ output.should match /bad-thumb/
212
+ end
213
+ it "should return an error div if the thumb can not be resolved when the image is ready" do
214
+ @image.encodable_status = "ready"
215
+ output = helper.phocoder_image_online(@image,"bad-thumb",{})
216
+ output.should match /phocoder_error/
217
+ output.should match /bad-thumb/
218
+ end
219
+ end
220
+ end # describe "when a thumbnail is passed" do
221
+
222
+ describe "find_thumbnail_attributes" do
223
+ it "should call @image.thumbnail_attributes_for if the thumbnail argument is a String" do
224
+ atts = {:foo => "bar" }
225
+ @image.should_receive(:thumbnail_attributes_for).and_return(atts)
226
+ helper.find_thumbnail_attributes(@image,"small",{}).should == atts
227
+ end
228
+ it "should return the thumbnail argument if it is a Hash" do
229
+ atts = {:foo => "bar" }
230
+ helper.find_thumbnail_attributes(@image,atts,{}).should == atts
231
+ end
232
+
233
+ end
234
+
235
+ describe "find_or_create_thumbnail" do
236
+ it "should call @image.thumbnail_for if the thumbnail attribute is a String" do
237
+ @image.should_receive(:thumbnail_for)
238
+ helper.find_or_create_thumbnail(@image,"some_thumb")
239
+ end
240
+ # This is kind of an integration test. maybe it should go somewhere else...
241
+ it "should create a new thumbnail (by calling phocode) for a new size string" do
242
+ #@image.should_receive(:phocode).and_return([{ :label => "100x100" }])
243
+
244
+ Phocoder::Job.should_receive(:create).and_return(mock(Phocoder::Response,:body=>{
245
+ "job"=>{
246
+ "id"=>1,
247
+ "inputs"=>["id"=>1],
248
+ "thumbnails"=>[{"label"=>"small","filename"=>"small-test-file.jpg","id"=>1}]
249
+ }
250
+ }))
251
+ @image.save
252
+ Phocoder::Job.should_receive(:create).and_return(mock(Phocoder::Response,:body=>{
253
+ "job"=>{
254
+ "id"=>1,
255
+ "inputs"=>["id"=>1],
256
+ "thumbnails"=>[{"label"=>"100x100","filename"=>"100x100-test-file.jpg","id"=>1}]
257
+ }
258
+ }))
259
+ thumb = helper.find_or_create_thumbnail(@image,"100x100")
260
+
261
+ puts thumb.to_json
262
+ thumb.encodable_status.should_not == "ready"
263
+ end
264
+ end
265
+
266
+ # describe "display_image_thumbnail" do
267
+ # it "in offline mode it should call offline_phocoder_image_thumbnail" do
268
+ # ActsAsPhocodable.storeage_mode = "offline"
269
+ # helper.should_receive(:offline_phocoder_image_thumbnail).and_return(nil)
270
+ # helper.display_image_thumbnail(@image,@image,{})
271
+ # end
272
+ #
273
+ # it "if the thumbnail is ready, should return an image tag with the path and dimensions of the thumbnail" do
274
+ #
275
+ # end
276
+ #
277
+ # it "if the thumbnail is not ready, should call pending_phocoder_thumbnail" do
278
+ # ActsAsPhocodable.storeage_mode = "local"
279
+ # @tattr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'), :width => 100, :height => 100 }
280
+ # @thumb = ImageUpload.new(@tattr)
281
+ # @thumb.filename = "big_eye_tiny_thumbnail.jpg"
282
+ # @thumb.encodable_status = "phocoding"
283
+ # helper.should_receive(:pending_phocoder_thumbnail).and_return(nil)
284
+ # helper.display_image_thumbnail(@image,@thumb,{})
285
+ # #puts "-------- #{@thumb.public_url} ---- #{ActsAsPhocodable.storeage_mode}"
286
+ # #output = helper.display_image_thumbnail(@image,@thumb,{})
287
+ # #output.should match /<img/
288
+ # #output.should match /width="100"/
289
+ # #output.should match /big_eye_tiny_thumbnail.jpg/ # the path in the thumbnail
290
+ # end
291
+ # end
292
+
293
+ # describe "offline_phocoder_image_thumbnail" do
294
+ # it "should render a thumbnail with the path to the original but the dimensions of the thumbnail" do
295
+ # @tattr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'),:filename=>"big_eye_tiny_thumbnail.jpg", :width => 100, :height => 100 }
296
+ # @thumb = ImageUpload.new(@tattr)
297
+ # @thumb.filename = "big_eye_tiny_thumbnail.jpg"
298
+ # output = helper.offline_phocoder_image_thumbnail(@image,@thumb,{})
299
+ # output.should match /<img/
300
+ # output.should match /width="100"/
301
+ # output.should match /big_eye_tiny.jpg/ # the path in the @att at the top of the file
302
+ # end
303
+ # end
304
+
305
+ describe "pending_phocoder_thumbnail" do
306
+ it "should return an image tag that points to a waiting image with the dimensions of the thumbnail" do
307
+ @tattr = { :file => fixture_file_upload(fixture_path + '/big_eye_tiny.jpg','image/jpeg'), :width => 100, :height => 100 }
308
+ @thumb = ImageUpload.new(@tattr)
309
+ @thumb.filename = "big_eye_tiny_thumbnail.jpg"
310
+ output = helper.pending_phocoder_thumbnail(@image,@thumb,{})
311
+ output.should match /<img/
312
+ output.should match /width="100"/
313
+ output.should match /waiting\.gif/ # the path in the thumbnail
314
+ end
315
+ end
316
+
317
+ ####################
318
+ # These are more like integration tests, but whatever at least it's tested....
319
+ ####################
320
+
321
+
322
+ describe "phocoder_image_thumbnail" do
323
+
324
+ it "should return a preview_reload_timeout" do
325
+ preview_reload_timeout.should == 10000
326
+ end
327
+
328
+
329
+
330
+
331
+ describe "phcoder_thumbnail for local mode after processing" do
332
+ before(:each) do
333
+ ActsAsPhocodable.storeage_mode = "local"
334
+
335
+ @thumb = ImageUpload.new(@attr.merge :parent_id=>@image.id,:thumbnail=>"small")
336
+ #@thumb.save
337
+ #set the main image to ready, but not the thumb
338
+ @image.encodable_status = "ready"
339
+ @image.stub!(:thumbnail_for).and_return(@thumb)
340
+ #@image.save
341
+ end
342
+
343
+ after(:each) do
344
+ #@thumb.destroy
345
+ end
346
+
347
+
348
+ it "should return a pending img for a known thumbnail that is not ready" do
349
+ phocoder_image_thumbnail(@image,"small").should match(/data-phocoder-waiting="true"/)
350
+ end
351
+
352
+ it "should return a local url for a known thumbnail" do
353
+ #act like we've already been updated from phocoder
354
+ @thumb.encodable_status = "ready"
355
+ #@thumb.save
356
+ puts "@image.encodable_status = #{@image.encodable_status}"
357
+ puts "@thumb.encodable_status = #{@thumb.encodable_status}"
358
+
359
+ phocoder_image_thumbnail(@image,"small").should match(@thumb.public_url)
360
+ end
361
+
362
+ end
363
+
364
+ end # describe "image operations" do
365
+
366
+
367
+ describe "phocoder_video_thumbnail" do
368
+ end
369
+
370
+
371
+
372
+ describe "video preview functions" do
373
+ # before(:each) do
374
+ # @vid_attr = {
375
+ # :file => fixture_file_upload(fixture_path + '/video-test.mov', 'video/quicktime')
376
+ # }
377
+ # Zencoder::Job.stub!(:create).and_return(mock(Zencoder::Response,:body=>{
378
+ # "id"=>1,
379
+ # "inputs"=>["id"=>1],
380
+ # "outputs"=>[{"label"=>"small","url"=>"http://someurl/","filename"=>"small-test-file.mp4","id"=>1}]
381
+ # }))
382
+ # end
383
+ #
384
+ # after(:each) do
385
+ #
386
+ # end
387
+
388
+ it "should render a pending img for a vid that is not ready" do
389
+ vid = ImageUpload.new(:content_type=>'video/quicktime',:zencoder_status=>'s3',:id=>1,:filename=>"test.mov")
390
+ phocoder_video_thumbnail(vid,"small",true).should match(/data-phocoder-waiting="true"/)
391
+ end
392
+
393
+ it "should render an image for a video that is ready but live_video = false" do
394
+ vid = ImageUpload.new(:content_type=>'video/quicktime',:zencoder_status=>'ready',:id=>1,:filename=>"test.mov",:encodable_status=>"ready")
395
+ vid.stub!(:thumbnail_for).and_return(vid)
396
+ vid.video?.should be_true
397
+ phocoder_video_thumbnail(vid,"small",false).should match("video_poster")
398
+ end
399
+
400
+
401
+
402
+ it "should render a video js embed for a video that is ready" do
403
+ vid = ImageUpload.new(:content_type=>'video/quicktime',:zencoder_status=>'ready',:id=>1,:filename=>"test.mov",:encodable_status=>"ready")
404
+ vid.stub!(:thumbnail_for).and_return(vid)
405
+ vid.video?.should be_true
406
+ phocoder_video_thumbnail(vid,"small",true).should match("video-js")
407
+ end
408
+
409
+ end # describe "video preview functions" do
410
+
411
+ describe "offline_phocoder_video_embed" do
412
+ it "should render a video tag" do
413
+ vid = ImageUpload.new(:content_type=>'video/quicktime',:zencoder_status=>'ready',:id=>1,:filename=>"test.mov",:encodable_status=>"ready")
414
+ vid.stub!(:thumbnail_for).and_return(vid)
415
+ vid.video?.should be_true
416
+ offline_phocoder_video_embed(vid,"small",{}).should match("video-js")
417
+ end
418
+
419
+ end
420
+
421
+ end