diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index 3e39cd9..596f2c3 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -42,7 +42,7 @@ module BlogHelper def display_post(article, format = 'full') no_comments = (format == 'full') ? false : true - html = send("display_#{format}_format", article) + html = send "display_#{format}_format", FilePresenter.for(article) article_title(article, :no_comments => no_comments) + html end diff --git a/app/models/article_block.rb b/app/models/article_block.rb index e30a9c8..a369d9e 100644 --- a/app/models/article_block.rb +++ b/app/models/article_block.rb @@ -12,7 +12,7 @@ class ArticleBlock < Block block = self lambda do block_title(block.title) + - (block.article ? article_to_html(block.article, + (block.article ? article_to_html(FilePresenter.for(block.article), :gallery_view => false, :inside_block => block, # For Blogs and folders :format => block.visualization_format # For Articles and contents diff --git a/lib/file_presenter/image.rb b/lib/file_presenter/image.rb index c9488f6..5427d36 100644 --- a/lib/file_presenter/image.rb +++ b/lib/file_presenter/image.rb @@ -4,6 +4,7 @@ class FilePresenter::Image < FilePresenter end def self.accepts?(f) + return nil unless f.respond_to? :image? f.image? ? 10 : nil end diff --git a/plugins/html5_video/lib/file_presenter/video.rb b/plugins/html5_video/lib/file_presenter/video.rb index 2dcdfd8..b8051f2 100644 --- a/plugins/html5_video/lib/file_presenter/video.rb +++ b/plugins/html5_video/lib/file_presenter/video.rb @@ -4,7 +4,7 @@ class FilePresenter::Video < FilePresenter end def self.accepts?(f) - return nil if f.content_type.nil? + return nil if !f.respond_to?(:content_type) || f.content_type.nil? ( f.content_type[0..4] == 'video' ) ? 10 : nil end diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index 2d5a74d..279c15a 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -110,9 +110,12 @@ class ArticleBlockTest < ActiveSupport::TestCase block.article = image block.save! - expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image') - - assert_match(/image/, instance_eval(&block.content)) + assert_tag_in_string instance_eval(&block.content), + :tag => 'img', + :attributes => { + :src => image.public_filename(:display), + :class => /file-image/ + } end should 'not display gallery pages navigation in content' do @@ -123,8 +126,6 @@ class ArticleBlockTest < ActiveSupport::TestCase block.article = image block.save! - expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image') - assert_no_match(/Previous/, instance_eval(&block.content)) end diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index 57833b9..4af3fee 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -94,10 +94,10 @@ class BlogHelperTest < ActiveSupport::TestCase should 'display link to file if post is an uploaded_file' do file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) - expects(:article_to_html).with(file).returns('TO HTML') - result = display_post(file) - assert_tag_in_string result, :content => /TO HTML/ + assert_tag_in_string result, :tag => 'a', + :attributes => { :href => file.public_filename }, + :content => file.filename end should 'display image if post is an image' do diff --git a/test/unit/file_presenter_test.rb b/test/unit/file_presenter_test.rb index fe1e7a0..60f91aa 100644 --- a/test/unit/file_presenter_test.rb +++ b/test/unit/file_presenter_test.rb @@ -40,4 +40,22 @@ class FilePresenterTest < ActiveSupport::TestCase assert_equal '/path/to/file.xyz', p.icon_name end + should 'not crach when accepts? method receives a pure article' do + assert_nothing_raised do + FilePresenter.for Article.new + end + end + + should 'not crach when accepts? method receives a non-sense object' do + assert_nothing_raised do + FilePresenter.for nil + end + assert_nothing_raised do + FilePresenter.for({:key => 'value'}) + end + assert_nothing_raised do + FilePresenter.for 'a string' + end + end + end diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb index 3077f73..14c4237 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' class ProfileListBlockTest < ActiveSupport::TestCase + include ActionView::Helpers::TagHelper + should 'describe itself' do assert_not_equal Block.description, ProfileListBlock.description end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index c128b4b..a554a77 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -8,9 +8,6 @@ class UploadedFileTest < ActiveSupport::TestCase attr_reader :profile 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 -- libgit2 0.21.2