1 require File.dirname(__FILE__) + '/abstract_unit'
 
   2 require File.dirname(__FILE__) + '/fixtures/entry'
 
   4 class UrlForFileColumnTest < Test::Unit::TestCase
 
   5   include FileColumnHelper
 
   8     Entry.file_column :image
 
   9     @request = RequestMock.new
 
  12   def test_url_for_file_column_with_temp_entry
 
  13     @e = Entry.new(:image => upload(f("skanthak.png")))
 
  14     url = url_for_file_column("e", "image")
 
  15     assert_match %r{^/entry/image/tmp/\d+(\.\d+)+/skanthak.png$}, url
 
  18   def test_url_for_file_column_with_saved_entry
 
  19     @e = Entry.new(:image => upload(f("skanthak.png")))
 
  22     url = url_for_file_column("e", "image")
 
  23     assert_equal "/entry/image/#{@e.id}/skanthak.png", url
 
  26   def test_url_for_file_column_works_with_symbol
 
  27     @e = Entry.new(:image => upload(f("skanthak.png")))
 
  30     url = url_for_file_column(:e, :image)
 
  31     assert_equal "/entry/image/#{@e.id}/skanthak.png", url
 
  34   def test_url_for_file_column_works_with_object
 
  35     e = Entry.new(:image => upload(f("skanthak.png")))
 
  38     url = url_for_file_column(e, "image")
 
  39     assert_equal "/entry/image/#{e.id}/skanthak.png", url
 
  42   def test_url_for_file_column_should_return_nil_on_no_uploaded_file
 
  44     assert_nil url_for_file_column(e, "image")
 
  47   def test_url_for_file_column_without_extension
 
  49     e.image = uploaded_file(file_path("kerb.jpg"), "something/unknown", "local_filename")
 
  51     assert_equal "/entry/image/#{e.id}/local_filename", url_for_file_column(e, "image")
 
  55 class UrlForFileColumnTest < Test::Unit::TestCase
 
  56   include FileColumnHelper
 
  57   include ActionView::Helpers::AssetTagHelper
 
  58   include ActionView::Helpers::TagHelper
 
  59   include ActionView::Helpers::UrlHelper
 
  62     Entry.file_column :image
 
  64     # mock up some request data structures for AssetTagHelper
 
  65     @request = RequestMock.new
 
  66     @request.relative_url_root = "/foo/bar"
 
  74   IMAGE_URL = %r{^/foo/bar/entry/image/.+/skanthak.png$}
 
  75   def test_with_image_tag
 
  76     e = Entry.new(:image => upload(f("skanthak.png")))
 
  77     html = image_tag url_for_file_column(e, "image")
 
  78     url = html.scan(/src=\"(.+)\"/).first.first
 
  80     assert_match IMAGE_URL, url
 
  83   def test_with_link_to_tag
 
  84     e = Entry.new(:image => upload(f("skanthak.png")))
 
  85     html = link_to "Download", url_for_file_column(e, "image", :absolute => true)
 
  86     url = html.scan(/href=\"(.+)\"/).first.first
 
  88     assert_match IMAGE_URL, url
 
  91   def test_relative_url_root_not_modified
 
  92     e = Entry.new(:image => upload(f("skanthak.png")))
 
  93     url_for_file_column(e, "image", :absolute => true)
 
  95     assert_equal "/foo/bar", @request.relative_url_root