blob: 83c95c01a1f63e59db8083ea69ab2c3777330ac5 (
plain) (
blame)
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
|
require "test_helper"
require "database/setup"
class User < ActiveRecord::Base
has_one_attached :avatar
end
class ActiveStorage::ImageTagTest < ActionView::TestCase
tests ActionView::Helpers::AssetTagHelper
setup do
@blob = create_image_blob filename: "racecar.jpg"
end
test "blob" do
assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url @blob}" />), image_tag(@blob)
end
test "variant" do
variant = @blob.variant(resize: "100x100")
assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url variant}" />), image_tag(variant)
end
test "attachment" do
attachment = ActiveStorage::Attachment.new(blob: @blob)
assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url attachment}" />), image_tag(attachment)
end
test "error when attachment's empty" do
@user = User.create!(name: "DHH")
assert_not @user.avatar.attached?
assert_raises(ArgumentError) { image_tag(@user.avatar) }
end
test "error when object can't be resolved into url" do
unresolvable_object = ActionView::Helpers::AssetTagHelper
assert_raises(ArgumentError) { image_tag(unresolvable_object) }
end
end
|