Commit 1c68caa0f2dc515b7523165187cb403dd074d5d1

Authored by Aurélio A. Heckert
1 parent 331e4e98

Makes FilePresenter to work with all noosfero tests II

ActionItem2373
app/helpers/blog_helper.rb
@@ -42,7 +42,7 @@ module BlogHelper @@ -42,7 +42,7 @@ module BlogHelper
42 42
43 def display_post(article, format = 'full') 43 def display_post(article, format = 'full')
44 no_comments = (format == 'full') ? false : true 44 no_comments = (format == 'full') ? false : true
45 - html = send("display_#{format}_format", article) 45 + html = send "display_#{format}_format", FilePresenter.for(article)
46 46
47 article_title(article, :no_comments => no_comments) + html 47 article_title(article, :no_comments => no_comments) + html
48 end 48 end
app/models/article_block.rb
@@ -12,7 +12,7 @@ class ArticleBlock < Block @@ -12,7 +12,7 @@ class ArticleBlock < Block
12 block = self 12 block = self
13 lambda do 13 lambda do
14 block_title(block.title) + 14 block_title(block.title) +
15 - (block.article ? article_to_html(block.article, 15 + (block.article ? article_to_html(FilePresenter.for(block.article),
16 :gallery_view => false, 16 :gallery_view => false,
17 :inside_block => block, # For Blogs and folders 17 :inside_block => block, # For Blogs and folders
18 :format => block.visualization_format # For Articles and contents 18 :format => block.visualization_format # For Articles and contents
lib/file_presenter/image.rb
@@ -4,6 +4,7 @@ class FilePresenter::Image < FilePresenter @@ -4,6 +4,7 @@ class FilePresenter::Image < FilePresenter
4 end 4 end
5 5
6 def self.accepts?(f) 6 def self.accepts?(f)
  7 + return nil unless f.respond_to? :image?
7 f.image? ? 10 : nil 8 f.image? ? 10 : nil
8 end 9 end
9 10
plugins/html5_video/lib/file_presenter/video.rb
@@ -4,7 +4,7 @@ class FilePresenter::Video < FilePresenter @@ -4,7 +4,7 @@ class FilePresenter::Video < FilePresenter
4 end 4 end
5 5
6 def self.accepts?(f) 6 def self.accepts?(f)
7 - return nil if f.content_type.nil? 7 + return nil if !f.respond_to?(:content_type) || f.content_type.nil?
8 ( f.content_type[0..4] == 'video' ) ? 10 : nil 8 ( f.content_type[0..4] == 'video' ) ? 10 : nil
9 end 9 end
10 10
test/unit/article_block_test.rb
@@ -110,9 +110,12 @@ class ArticleBlockTest < ActiveSupport::TestCase @@ -110,9 +110,12 @@ class ArticleBlockTest < ActiveSupport::TestCase
110 block.article = image 110 block.article = image
111 block.save! 111 block.save!
112 112
113 - expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image')  
114 -  
115 - assert_match(/image/, instance_eval(&block.content)) 113 + assert_tag_in_string instance_eval(&block.content),
  114 + :tag => 'img',
  115 + :attributes => {
  116 + :src => image.public_filename(:display),
  117 + :class => /file-image/
  118 + }
116 end 119 end
117 120
118 should 'not display gallery pages navigation in content' do 121 should 'not display gallery pages navigation in content' do
@@ -123,8 +126,6 @@ class ArticleBlockTest < ActiveSupport::TestCase @@ -123,8 +126,6 @@ class ArticleBlockTest < ActiveSupport::TestCase
123 block.article = image 126 block.article = image
124 block.save! 127 block.save!
125 128
126 - expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image')  
127 -  
128 assert_no_match(/Previous/, instance_eval(&block.content)) 129 assert_no_match(/Previous/, instance_eval(&block.content))
129 end 130 end
130 131
test/unit/blog_helper_test.rb
@@ -94,10 +94,10 @@ class BlogHelperTest < ActiveSupport::TestCase @@ -94,10 +94,10 @@ class BlogHelperTest < ActiveSupport::TestCase
94 should 'display link to file if post is an uploaded_file' do 94 should 'display link to file if post is an uploaded_file' do
95 file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) 95 file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog)
96 96
97 - expects(:article_to_html).with(file).returns('TO HTML')  
98 -  
99 result = display_post(file) 97 result = display_post(file)
100 - assert_tag_in_string result, :content => /TO HTML/ 98 + assert_tag_in_string result, :tag => 'a',
  99 + :attributes => { :href => file.public_filename },
  100 + :content => file.filename
101 end 101 end
102 102
103 should 'display image if post is an image' do 103 should 'display image if post is an image' do
test/unit/file_presenter_test.rb
@@ -40,4 +40,22 @@ class FilePresenterTest < ActiveSupport::TestCase @@ -40,4 +40,22 @@ class FilePresenterTest < ActiveSupport::TestCase
40 assert_equal '/path/to/file.xyz', p.icon_name 40 assert_equal '/path/to/file.xyz', p.icon_name
41 end 41 end
42 42
  43 + should 'not crach when accepts? method receives a pure article' do
  44 + assert_nothing_raised do
  45 + FilePresenter.for Article.new
  46 + end
  47 + end
  48 +
  49 + should 'not crach when accepts? method receives a non-sense object' do
  50 + assert_nothing_raised do
  51 + FilePresenter.for nil
  52 + end
  53 + assert_nothing_raised do
  54 + FilePresenter.for({:key => 'value'})
  55 + end
  56 + assert_nothing_raised do
  57 + FilePresenter.for 'a string'
  58 + end
  59 + end
  60 +
43 end 61 end
test/unit/profile_list_block_test.rb
@@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper'
2 2
3 class ProfileListBlockTest < ActiveSupport::TestCase 3 class ProfileListBlockTest < ActiveSupport::TestCase
4 4
  5 + include ActionView::Helpers::TagHelper
  6 +
5 should 'describe itself' do 7 should 'describe itself' do
6 assert_not_equal Block.description, ProfileListBlock.description 8 assert_not_equal Block.description, ProfileListBlock.description
7 end 9 end
test/unit/uploaded_file_test.rb
@@ -8,9 +8,6 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -8,9 +8,6 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
8 attr_reader :profile 8 attr_reader :profile
9 9
10 should 'return a default icon for uploaded files' do 10 should 'return a default icon for uploaded files' do
11 - ENV.stubs('[]').with('RAILS_ENV').returns('other')  
12 - Rails.logger.expects(:warn) # warn about deprecatede usage of UploadedFile.icon_name  
13 - stubs(:puts)  
14 assert_equal 'upload-file', UploadedFile.icon_name 11 assert_equal 'upload-file', UploadedFile.icon_name
15 end 12 end
16 13