forked from huerlisi/file_column
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_column_helper_test.rb
97 lines (76 loc) · 2.74 KB
/
file_column_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require File.dirname(__FILE__) + '/abstract_unit'
require File.dirname(__FILE__) + '/fixtures/entry'
class UrlForFileColumnTest < Test::Unit::TestCase
include FileColumnHelper
def setup
Entry.file_column :image
@request = RequestMock.new
end
def test_url_for_file_column_with_temp_entry
@e = Entry.new(:image => upload(f("skanthak.png")))
url = url_for_file_column("e", "image")
assert_match %r{^/entry/image/tmp/\d+(\.\d+)+/skanthak.png$}, url
end
def test_url_for_file_column_with_saved_entry
@e = Entry.new(:image => upload(f("skanthak.png")))
assert @e.save
url = url_for_file_column("e", "image")
assert_equal "/entry/image/#{@e.id}/skanthak.png", url
end
def test_url_for_file_column_works_with_symbol
@e = Entry.new(:image => upload(f("skanthak.png")))
assert @e.save
url = url_for_file_column(:e, :image)
assert_equal "/entry/image/#{@e.id}/skanthak.png", url
end
def test_url_for_file_column_works_with_object
e = Entry.new(:image => upload(f("skanthak.png")))
assert e.save
url = url_for_file_column(e, "image")
assert_equal "/entry/image/#{e.id}/skanthak.png", url
end
def test_url_for_file_column_should_return_nil_on_no_uploaded_file
e = Entry.new
assert_nil url_for_file_column(e, "image")
end
def test_url_for_file_column_without_extension
e = Entry.new
e.image = uploaded_file(file_path("kerb.jpg"), "something/unknown", "local_filename")
assert e.save
assert_equal "/entry/image/#{e.id}/local_filename", url_for_file_column(e, "image")
end
end
class UrlForFileColumnTest < Test::Unit::TestCase
include FileColumnHelper
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
def setup
Entry.file_column :image
# mock up some request data structures for AssetTagHelper
@request = RequestMock.new
@request.relative_url_root = "/foo/bar"
@controller = self
end
def request
@request
end
IMAGE_URL = %r{^/foo/bar/entry/image/.+/skanthak.png$}
def test_with_image_tag
e = Entry.new(:image => upload(f("skanthak.png")))
html = image_tag url_for_file_column(e, "image")
url = html.scan(/src=\"(.+)\"/).first.first
assert_match IMAGE_URL, url
end
def test_with_link_to_tag
e = Entry.new(:image => upload(f("skanthak.png")))
html = link_to "Download", url_for_file_column(e, "image", :absolute => true)
url = html.scan(/href=\"(.+)\"/).first.first
assert_match IMAGE_URL, url
end
def test_relative_url_root_not_modified
e = Entry.new(:image => upload(f("skanthak.png")))
url_for_file_column(e, "image", :absolute => true)
assert_equal "/foo/bar", @request.relative_url_root
end
end