Commit 1c68caa0f2dc515b7523165187cb403dd074d5d1
1 parent
331e4e98
Exists in
master
and in
28 other branches
Makes FilePresenter to work with all noosfero tests II
ActionItem2373
Showing
9 changed files
with
33 additions
and
14 deletions
Show diff stats
app/helpers/blog_helper.rb
| ... | ... | @@ -42,7 +42,7 @@ module BlogHelper |
| 42 | 42 | |
| 43 | 43 | def display_post(article, format = 'full') |
| 44 | 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 | 47 | article_title(article, :no_comments => no_comments) + html |
| 48 | 48 | end | ... | ... |
app/models/article_block.rb
| ... | ... | @@ -12,7 +12,7 @@ class ArticleBlock < Block |
| 12 | 12 | block = self |
| 13 | 13 | lambda do |
| 14 | 14 | block_title(block.title) + |
| 15 | - (block.article ? article_to_html(block.article, | |
| 15 | + (block.article ? article_to_html(FilePresenter.for(block.article), | |
| 16 | 16 | :gallery_view => false, |
| 17 | 17 | :inside_block => block, # For Blogs and folders |
| 18 | 18 | :format => block.visualization_format # For Articles and contents | ... | ... |
lib/file_presenter/image.rb
plugins/html5_video/lib/file_presenter/video.rb
test/unit/article_block_test.rb
| ... | ... | @@ -110,9 +110,12 @@ class ArticleBlockTest < ActiveSupport::TestCase |
| 110 | 110 | block.article = image |
| 111 | 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 | 119 | end |
| 117 | 120 | |
| 118 | 121 | should 'not display gallery pages navigation in content' do |
| ... | ... | @@ -123,8 +126,6 @@ class ArticleBlockTest < ActiveSupport::TestCase |
| 123 | 126 | block.article = image |
| 124 | 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 | 129 | assert_no_match(/Previous/, instance_eval(&block.content)) |
| 129 | 130 | end |
| 130 | 131 | ... | ... |
test/unit/blog_helper_test.rb
| ... | ... | @@ -94,10 +94,10 @@ class BlogHelperTest < ActiveSupport::TestCase |
| 94 | 94 | should 'display link to file if post is an uploaded_file' do |
| 95 | 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 | 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 | 101 | end |
| 102 | 102 | |
| 103 | 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 | 40 | assert_equal '/path/to/file.xyz', p.icon_name |
| 41 | 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 | 61 | end | ... | ... |
test/unit/profile_list_block_test.rb
| ... | ... | @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | |
| 3 | 3 | class ProfileListBlockTest < ActiveSupport::TestCase |
| 4 | 4 | |
| 5 | + include ActionView::Helpers::TagHelper | |
| 6 | + | |
| 5 | 7 | should 'describe itself' do |
| 6 | 8 | assert_not_equal Block.description, ProfileListBlock.description |
| 7 | 9 | end | ... | ... |
test/unit/uploaded_file_test.rb
| ... | ... | @@ -8,9 +8,6 @@ class UploadedFileTest < ActiveSupport::TestCase |
| 8 | 8 | attr_reader :profile |
| 9 | 9 | |
| 10 | 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 | 11 | assert_equal 'upload-file', UploadedFile.icon_name |
| 15 | 12 | end |
| 16 | 13 | ... | ... |