Just prints the filename followed by a bunch of question marks when unable to find image
| 45 | def link_for_resource(prefix, res, options=[]) | def link_for_resource(prefix, res, options=[]) | 45 |
|---|---|---|---|
| 46 | if prefix.downcase == 'image' | if prefix.downcase == 'image' | 46 |
| 47 | image = @page.images.to_a.find {|img| res.downcase == img.filename.downcase} | image = @page.images.to_a.find {|img| res.downcase == img.filename.downcase} | 47 |
| 48 | %[<img src="#{image.public_filename}" width="#{image.width}" height="#{image.height}" />] | image.nil? ? "[[#{prefix}:#{res}???]]" : | 48 |
%[<img src="#{image.public_filename}" width="#{image.width}" height="#{image.height}" />] | 49 | ||
| 49 | end | end | 50 |
| 50 | end | end | 51 |
| 51 | 52 |
| 27 | 27 | ||
|---|---|---|---|
| 28 | require 'rubygems' | require 'rubygems' | 28 |
| 29 | require 'flexmock' | require 'flexmock' | 29 |
require 'hpricot' | 30 | ||
| 30 | 31 | ||
| 31 | class Test::Unit::TestCase | class Test::Unit::TestCase | 32 |
| 32 | # Transactional fixtures accelerate your tests by wrapping each test method | # Transactional fixtures accelerate your tests by wrapping each test method | 33 |
| 40 more lines | |||
| 73 | Page.new(:name => nil).revise(bob, now, attrs) | Page.new(:name => nil).revise(bob, now, attrs) | 74 |
| 74 | end | end | 75 |
| 75 | 76 | ||
def assert_same_html(expected, result, message=nil) | 77 | ||
assert_equal(Hpricot(expected).to_s, Hpricot(result).to_s, message) | 78 | ||
end | 79 | ||
| 76 | end | end | 80 |
| 269 | 269 | ||
|---|---|---|---|
| 270 | def test_marks_references_to_finished_features | def test_marks_references_to_finished_features | 270 |
| 271 | name = pages('finished_feature').name | name = pages('finished_feature').name | 271 |
| 272 | assert_equal "<p>Yada yada yada <a #{{:href => 'http://test.host/wiki/show/' + name, :class => 'done'}.to_att}>#{name}</a></p>", | assert_same_html "<p>Yada yada yada <a #{{:href => 'http://test.host/wiki/show/' + name, :class => 'done'}.to_att}>#{name}</a></p>", | 272 |
| 273 | renderer.render_wiki_text('Yada yada yada [[FinishedFeature]]') | renderer.render_wiki_text('Yada yada yada [[FinishedFeature]]') | 273 |
| 274 | end | end | 274 |
| 275 | 275 | ||
| 276 | def test_renders_images | def test_embeds_images | 276 |
| 277 | page = pages('page_with_image') | page = pages('page_with_image') | 277 |
| 278 | expected = "<h2><a name='My_image'></a> My image </h2>\n" + | expected = "<h2><a name='My_image'></a> My image </h2>\n" + | 278 |
| 279 | "<p><img src=\"/wikimages/0000/0001/test.jpg\" width=\"497\" height=\"497\" /></p>" | "<p><img src=\"/wikimages/0000/0001/test.jpg\" width=\"497\" height=\"497\" /></p>" | 279 |
| 2 more lines | |||
| 282 | assert_equal expected, renderer.render_wiki_text("== My image ==\n\n[[image:Test.JPG]]", page) | assert_equal expected, renderer.render_wiki_text("== My image ==\n\n[[image:Test.JPG]]", page) | 282 |
| 283 | end | end | 283 |
| 284 | 284 | ||
def test_when_unable_to_embed_image_renders_text | 285 | ||
page = pages('page_with_image') | 286 | ||
assert_equal "<h2><a name='My_broken_image'></a> My broken image </h2>\n" + | 287 | ||
"<p>[[image:broken.jpg???]]</p>", | 288 | ||
renderer.render_wiki_text("== My broken image ==\n\n[[image:broken.jpg]]", page) | 289 | ||
end | 290 | ||
| 291 | |||
| 285 | private | private | 292 |
| 286 | 293 | ||
| 287 | def url_generator; TestingWikiLinkHandler.new; end | def url_generator; TestingWikiLinkHandler.new; end | 294 |