]> git.openstreetmap.org Git - rails.git/blob - test/helpers/user_helper_test.rb
397a90a63d0f5113c8bee401f6801e7099a6c727
[rails.git] / test / helpers / user_helper_test.rb
1 require "test_helper"
2
3 class UserHelperTest < ActionView::TestCase
4   include ERB::Util
5
6   def test_user_image
7     user = create(:user)
8     gravatar_user = create(:user, :image_use_gravatar => true)
9
10     image = user_image(user)
11     assert_match %r{^<img class="user_image" .* src="/images/avatar_large.png" />$}, image
12
13     image = user_image(user, :class => "foo")
14     assert_match %r{^<img class="foo" .* src="/images/avatar_large.png" />$}, image
15
16     image = user_image(gravatar_user)
17     assert_match %r{^<img class="user_image" .* src="http://www.gravatar.com/avatar/.*" />$}, image
18
19     image = user_image(gravatar_user, :class => "foo")
20     assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
21   end
22
23   def test_user_thumbnail
24     user = create(:user)
25     gravatar_user = create(:user, :image_use_gravatar => true)
26
27     image = user_thumbnail(user)
28     assert_match %r{^<img class="user_thumbnail" .* src="/images/avatar_small.png" />$}, image
29
30     image = user_thumbnail(user, :class => "foo")
31     assert_match %r{^<img class="foo" .* src="/images/avatar_small.png" />$}, image
32
33     image = user_thumbnail(gravatar_user)
34     assert_match %r{^<img class="user_thumbnail" .* src="http://www.gravatar.com/avatar/.*" />$}, image
35
36     image = user_thumbnail(gravatar_user, :class => "foo")
37     assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
38   end
39
40   def test_user_thumbnail_tiny
41     user = create(:user)
42     gravatar_user = create(:user, :image_use_gravatar => true)
43
44     image = user_thumbnail_tiny(user)
45     assert_match %r{^<img class="user_thumbnail_tiny" .* src="/images/avatar_small.png" />$}, image
46
47     image = user_thumbnail_tiny(user, :class => "foo")
48     assert_match %r{^<img class="foo" .* src="/images/avatar_small.png" />$}, image
49
50     image = user_thumbnail_tiny(gravatar_user)
51     assert_match %r{^<img class="user_thumbnail_tiny" .* src="http://www.gravatar.com/avatar/.*" />$}, image
52
53     image = user_thumbnail_tiny(gravatar_user, :class => "foo")
54     assert_match %r{^<img class="foo" .* src="http://www.gravatar.com/avatar/.*" />$}, image
55   end
56
57   def test_user_image_url
58     user = create(:user)
59     user.avatar.attach(:io => File.open("test/gpx/fixtures/a.gif"), :filename => "a.gif")
60     gravatar_user = create(:user, :image_use_gravatar => true)
61
62     url = user_image_url(user)
63     assert_match %r{^http://test.host/rails/active_storage/representations/[^/]+/[^/]+/a.gif$}, url
64
65     url = user_image_url(gravatar_user)
66     assert_match %r{^http://www.gravatar.com/avatar/}, url
67   end
68
69   def test_openid_logo
70     logo = openid_logo
71     assert_match %r{^<img .* class="openid_logo" src="/images/openid_small.png" />$}, logo
72   end
73
74   def test_auth_button
75     button = auth_button("google", "google")
76     assert_equal button, "<a class=\"auth_button\" title=\"Login with Google\" href=\"/auth/google\"><img alt=\"Login with a Google OpenID\" src=\"/images/google.png\" /></a>"
77
78     button = auth_button("yahoo", "openid", :openid_url => "yahoo.com")
79     assert_equal button, "<a class=\"auth_button\" title=\"Login with Yahoo\" href=\"/auth/openid?openid_url=yahoo\.com\"><img alt=\"Login with a Yahoo OpenID\" src=\"/images/yahoo.png\" /></a>"
80   end
81
82   private
83
84   def request
85     controller.request
86   end
87 end