3 class UserHelperTest < ActionView::TestCase
8 gravatar_user = create(:user, :image_use_gravatar => true)
10 image = user_image(user)
11 assert_match %r{^<img class="user_image border border-secondary-subtle bg-body" .* src="/images/avatar.svg" />$}, image
13 image = user_image(user, :class => "foo")
14 assert_match %r{^<img class="foo" .* src="/images/avatar.svg" />$}, image
15 image = user_image(gravatar_user)
16 assert_match %r{^<img class="user_image border border-secondary-subtle bg-body" .* src="http://www.gravatar.com/avatar/.*" />$}, image
18 image = user_image(gravatar_user, :class => "foo")
19 assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
22 def test_user_thumbnail
24 gravatar_user = create(:user, :image_use_gravatar => true)
26 image = user_thumbnail(user)
27 assert_match %r{^<img class="user_thumbnail border border-secondary-subtle bg-body" .* src="/images/avatar.svg" />$}, image
29 image = user_thumbnail(user, :class => "foo")
30 assert_match %r{^<img class="foo" .* src="/images/avatar.svg" />$}, image
32 image = user_thumbnail(gravatar_user)
33 assert_match %r{^<img class="user_thumbnail border border-secondary-subtle bg-body" .* src="http://www.gravatar.com/avatar/.*" />$}, image
35 image = user_thumbnail(gravatar_user, :class => "foo")
36 assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
39 def test_user_thumbnail_tiny
41 gravatar_user = create(:user, :image_use_gravatar => true)
43 image = user_thumbnail_tiny(user)
44 assert_match %r{^<img class="user_thumbnail_tiny border border-secondary-subtle bg-body" .* src="/images/avatar.svg" />$}, image
46 image = user_thumbnail_tiny(user, :class => "foo")
47 assert_match %r{^<img class="foo" .* src="/images/avatar.svg" />$}, image
49 image = user_thumbnail_tiny(gravatar_user)
50 assert_match %r{^<img class="user_thumbnail_tiny border border-secondary-subtle bg-body" .* src="http://www.gravatar.com/avatar/.*" />$}, image
52 image = user_thumbnail_tiny(gravatar_user, :class => "foo")
53 assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
56 def test_user_image_url
58 user.avatar.attach(:io => File.open("test/gpx/fixtures/a.gif"), :filename => "a.gif")
59 gravatar_user = create(:user, :image_use_gravatar => true)
61 url = user_image_url(user)
62 assert_match %r{^http://test.host/rails/active_storage/representations/redirect/[^/]+/[^/]+/a.gif$}, url
64 url = user_image_url(gravatar_user)
65 assert_match %r{^http://www.gravatar.com/avatar/}, url
68 def test_user_image_sizes_default_image
71 image = user_image(user)
72 assert_match %r{^<img .* width="100" height="100" .* />$}, image
74 thumbnail = user_thumbnail(user)
75 assert_match %r{^<img .* width="50" height="50" .* />$}, thumbnail
78 def test_user_image_sizes_avatar
80 user.avatar.attach(:io => File.open("test/gpx/fixtures/a.gif"), :filename => "a.gif")
82 # first time access, no width or height is found
83 image = user_image(user)
84 assert_no_match %r{^<img .* width="100" height="100" .* />$}, image
86 thumbnail = user_thumbnail(user)
87 assert_no_match %r{^<img .* width="50" height="50" .* />$}, thumbnail
89 # Small hacks to simulate what happens when the images have been fetched at least once before
90 variant = user.avatar.variant(:resize_to_limit => [100, 100])
91 variant.processed.send(:record).image.blob.analyze
92 variant = user.avatar.variant(:resize_to_limit => [50, 50])
93 variant.processed.send(:record).image.blob.analyze
95 image = user_image(user)
96 assert_match %r{^<img .* width="100" height="100" .* />$}, image
98 thumbnail = user_thumbnail(user)
99 assert_match %r{^<img .* width="50" height="50" .* />$}, thumbnail
102 def test_user_image_sizes_gravatar
103 user = create(:user, :image_use_gravatar => true)
105 image = user_image(user)
106 assert_match %r{^<img .* width="100" height="100" .* />$}, image
108 thumbnail = user_thumbnail(user)
109 assert_match %r{^<img .* width="50" height="50" .* />$}, thumbnail
114 assert_match %r{^<img .* src="/images/openid_small.png" />$}, logo
118 button = auth_button("google", "google")
119 img_tag = "<img alt=\"Log in with a Google OpenID\" class=\"rounded-1\" src=\"/images/google.svg\" width=\"24\" height=\"24\" />"
120 assert_equal("<a class=\"auth_button p-2 d-block\" title=\"Log in with Google\" rel=\"nofollow\" data-method=\"post\" href=\"/auth/google\">#{img_tag}</a>", button)