]> git.openstreetmap.org Git - rails.git/blob - test/helpers/user_helper_test.rb
Update wiki_pages.yml, fix http url in update script
[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="/assets/users/images/large-.*" />$}, image
12
13     image = user_image(user, :class => "foo")
14     assert_match %r{^<img class="foo" .* src="/assets/users/images/large-.*" />$}, 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="/assets/users/images/small-.*" />$}, image
29
30     image = user_thumbnail(user, :class => "foo")
31     assert_match %r{^<img class="foo" .* src="/assets/users/images/small-.*" />$}, 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="/assets/users/images/small-.*" />$}, image
46
47     image = user_thumbnail_tiny(user, :class => "foo")
48     assert_match %r{^<img class="foo" .* src="/assets/users/images/small-.*" />$}, 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, :image_file_name => "test.jpg", :image_fingerprint => "d41d8cd98f00b204e9800998ecf8427e")
59     gravatar_user = create(:user, :image_use_gravatar => true)
60
61     url = user_image_url(user)
62     assert_match %r{^/attachments/users/images/\d{3}/\d{3}/\d{3}/original/d41d8cd98f00b204e9800998ecf8427e.jpg$}, url
63
64     url = user_image_url(gravatar_user)
65     assert_match %r{^http://www.gravatar.com/avatar/}, url
66   end
67
68   def test_openid_logo
69     logo = openid_logo
70     assert_match %r{^<img .* class="openid_logo" src="/images/openid_small.png" />$}, logo
71   end
72
73   def test_auth_button
74     button = auth_button("google", "google")
75     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>"
76
77     button = auth_button("yahoo", "openid", :openid_url => "yahoo.com")
78     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>"
79   end
80
81   private
82
83   def request
84     controller.request
85   end
86 end