diff --git a/lib/file_presenter.rb b/lib/file_presenter.rb
index 1554a8f..272db6a 100644
--- a/lib/file_presenter.rb
+++ b/lib/file_presenter.rb
@@ -22,6 +22,15 @@ class FilePresenter
@file
end
+ def id
+ @file.id
+ end
+
+ def reload
+ @file.reload
+ self
+ end
+
# This method must be overridden in subclasses.
#
# If the class accepts the file, return a number that represents the
@@ -33,6 +42,10 @@ class FilePresenter
nil
end
+ def short_description
+ _("File (%s)") % content_type
+ end
+
# Define the css classes to style the page fragment with the file related
# content. If you want other classes to identify this area to your
# customized presenter, so do this:
@@ -88,3 +101,7 @@ class FilePresenter
end
end
+
+# Preload FilePresenters to allow `FilePresenter.for()` to work
+FilePresenter::Generic
+FilePresenter::Image
diff --git a/lib/file_presenter/image.rb b/lib/file_presenter/image.rb
index 1192715..c9488f6 100644
--- a/lib/file_presenter/image.rb
+++ b/lib/file_presenter/image.rb
@@ -8,6 +8,10 @@ class FilePresenter::Image < FilePresenter
end
def icon_name
- article.public_filename :icon
+ public_filename :icon
+ end
+
+ def short_description
+ _('Image (%s)') % content_type.split('/')[1].upcase
end
end
diff --git a/plugins/html5_video/lib/file_presenter/video.rb b/plugins/html5_video/lib/file_presenter/video.rb
index 53ad7d8..2dcdfd8 100644
--- a/plugins/html5_video/lib/file_presenter/video.rb
+++ b/plugins/html5_video/lib/file_presenter/video.rb
@@ -7,4 +7,8 @@ class FilePresenter::Video < FilePresenter
return nil if f.content_type.nil?
( f.content_type[0..4] == 'video' ) ? 10 : nil
end
+
+ def short_description
+ _('Video (%s)') % content_type.split('/')[1].upcase
+ end
end
diff --git a/plugins/html5_video/test/functional/content_viewer_controler_test.rb b/plugins/html5_video/test/functional/content_viewer_controler_test.rb
new file mode 100644
index 0000000..5a0f494
--- /dev/null
+++ b/plugins/html5_video/test/functional/content_viewer_controler_test.rb
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require 'content_viewer_controller'
+
+class ContentViewerController
+ # Re-raise errors caught by the controller.
+ def rescue_action(e) raise e end
+ append_view_path File.join(File.dirname(__FILE__) + '/../../views')
+end
+
+class ContentViewerControllerTest < ActionController::TestCase
+
+ all_fixtures
+
+ def setup
+ @controller = ContentViewerController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @profile = create_user('testinguser').person
+ @environment = @profile.environment
+ end
+ attr_reader :profile, :environment
+
+ should 'add html5 video tag to the page of file type video' do
+ file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'video/ogg'), :profile => profile)
+ get :view_page, file.url.merge(:view=>:true)
+ assert_select '#article video'
+ end
+
+end
diff --git a/plugins/html5_video/views/file_presenter/_video.html.erb b/plugins/html5_video/views/file_presenter/_video.html.erb
index abf9b0c..04a40b7 100644
--- a/plugins/html5_video/views/file_presenter/_video.html.erb
+++ b/plugins/html5_video/views/file_presenter/_video.html.erb
@@ -1,5 +1,5 @@
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index f0f76c4..d195d03 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -931,8 +931,8 @@ class CmsControllerTest < ActionController::TestCase
:article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}
process_delayed_job_queue
- file = profile.articles.find_by_name('rails.png')
- assert File.exists?(file.class.icon_name(file))
+ file = FilePresenter.for profile.articles.find_by_name('rails.png')
+ assert File.exists?(file.icon_name)
file.destroy
end
@@ -942,8 +942,8 @@ class CmsControllerTest < ActionController::TestCase
:article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}
process_delayed_job_queue
- file = profile.articles.find_by_name('rails.png')
- assert File.exists?(file.class.icon_name(file))
+ file = FilePresenter.for profile.articles.find_by_name('rails.png')
+ assert File.exists?(file.icon_name)
file.destroy
end
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index 0e5a994..2ffcc7f 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1502,4 +1502,12 @@ end
assert_response 404
end
+ should 'display link to download of non-recognized file types on its page' do
+ file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'bin/unknown'), :profile => profile)
+ get :view_page, file.url.merge(:view=>:true)
+ assert_tag :tag => 'a',
+ :content => file.filename,
+ :attributes => { :href => file.public_filename }
+ end
+
end
diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb
index 9bc0626..f0872e5 100644
--- a/test/unit/cms_helper_test.rb
+++ b/test/unit/cms_helper_test.rb
@@ -41,6 +41,7 @@ class CmsHelperTest < ActiveSupport::TestCase
should 'display image and link if article is an image' do
profile = fast_create(Profile)
file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = FilePresenter.for file
icon = icon_for_article(file)
expects(:image_tag).with(icon).returns('icon')
diff --git a/test/unit/file_presenter_test.rb b/test/unit/file_presenter_test.rb
new file mode 100644
index 0000000..fe1e7a0
--- /dev/null
+++ b/test/unit/file_presenter_test.rb
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class FilePresenterTest < ActiveSupport::TestCase
+
+ should 'notify about deprecated method UploadedFile.icon_name' do
+ profile = fast_create(Profile)
+ file = UploadedFile.create!(
+ :profile => profile,
+ :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
+ )
+ assert_raise NoMethodError do
+ UploadedFile.icon_name file
+ end
+ ENV.stubs('[]').with('RAILS_ENV').returns('other')
+ Rails.logger.expects(:warn) # must warn on any other RAILS_ENV
+ stubs(:puts)
+ UploadedFile.icon_name file
+ end
+
+ should 'notify about deprecated method UploadedFile#to_html' do
+ profile = fast_create(Profile)
+ file = UploadedFile.create!(
+ :profile => profile,
+ :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
+ )
+ assert_raise NoMethodError do
+ file.to_html
+ end
+ ENV.stubs('[]').with('RAILS_ENV').returns('other')
+ Rails.logger.expects(:warn) # must warn on any other RAILS_ENV
+ stubs(:puts)
+ file.to_html
+ end
+
+ should 'return a thumbnail as icon for images ' do
+ f = UploadedFile.new
+ f.stubs(:image?).returns(true)
+ p = FilePresenter.for f
+ p.expects(:public_filename).with(:icon).returns('/path/to/file.xyz')
+ assert_equal '/path/to/file.xyz', p.icon_name
+ end
+
+end
diff --git a/test/unit/folder_helper_test.rb b/test/unit/folder_helper_test.rb
index c28aee1..54c4562 100644
--- a/test/unit/folder_helper_test.rb
+++ b/test/unit/folder_helper_test.rb
@@ -26,6 +26,7 @@ class FolderHelperTest < ActiveSupport::TestCase
should 'display icon for images' do
profile = fast_create(Profile)
file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile)
+ file = FilePresenter.for file
process_delayed_job_queue
assert_match /rails_icon\.png/, icon_for_article(file.reload)
diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb
index 55f774f..c128b4b 100644
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -7,14 +7,10 @@ class UploadedFileTest < ActiveSupport::TestCase
end
attr_reader :profile
- should 'return a thumbnail as icon for images ' do
- f = UploadedFile.new
- f.expects(:image?).returns(true)
- f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz')
- assert_equal '/path/to/file.xyz', UploadedFile.icon_name(f)
- end
-
should 'return a default icon for uploaded files' do
+ ENV.stubs('[]').with('RAILS_ENV').returns('other')
+ Rails.logger.expects(:warn) # warn about deprecatede usage of UploadedFile.icon_name
+ stubs(:puts)
assert_equal 'upload-file', UploadedFile.icon_name
end
@@ -113,8 +109,11 @@ class UploadedFileTest < ActiveSupport::TestCase
p = create_user('test_user').person
file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => p)
+ ENV.stubs('[]').with('RAILS_ENV').returns('other')
+ Rails.logger.expects(:warn) # warn about deprecatede usage of UploadedFile#to_html
+ stubs(:puts)
stubs(:content_tag).returns('link')
- expects(:link_to).with(file.name, file.url, :class => file.css_class_name)
+ expects(:link_to).with(file.name, file.url)
instance_eval(&file.to_html)
end
@@ -206,13 +205,6 @@ class UploadedFileTest < ActiveSupport::TestCase
file.destroy
end
- should 'return the default thumbnail image as icon for images ' do
- f = UploadedFile.new
- f.expects(:image?).returns(true)
- f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz')
- assert_equal '/path/to/file.xyz', UploadedFile.icon_name(f)
- end
-
should 'store width and height after processing' do
file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
file.create_thumbnails
@@ -287,12 +279,6 @@ class UploadedFileTest < ActiveSupport::TestCase
assert_equal '', f.lead
end
- should 'survive when try to get icon_name from a file with mime_type nil' do
- f = UploadedFile.new
- f.expects(:mime_type).returns(nil)
- assert_equal 'upload-file', UploadedFile.icon_name(f)
- end
-
should 'upload to a folder with same name as the schema if database is postgresql' do
uses_postgresql 'image_schema_one'
file1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile)
--
libgit2 0.21.2