From 87a7829eb8b82efd0f5252d5b89259e0f6a4d6a5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 6 Jul 2017 19:11:21 +0100 Subject: [PATCH] Add some tests for the user helper --- app/helpers/user_helper.rb | 2 + test/helpers/user_helper_test.rb | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 test/helpers/user_helper_test.rb diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index 6043edf5f..27d6faa8c 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -57,6 +57,8 @@ module UserHelper ) end + private + # Gravatar support # See http://en.gravatar.com/site/implement/images/ for details. diff --git a/test/helpers/user_helper_test.rb b/test/helpers/user_helper_test.rb new file mode 100644 index 000000000..ea3464052 --- /dev/null +++ b/test/helpers/user_helper_test.rb @@ -0,0 +1,86 @@ +require "test_helper" + +class UserHelperTest < ActionView::TestCase + include ERB::Util + + def test_user_image + user = create(:user) + gravatar_user = create(:user, :image_use_gravatar => true) + + image = user_image(user) + assert_match %r{^$}, image + + image = user_image(user, :class => "foo") + assert_match %r{^$}, image + + image = user_image(gravatar_user) + assert_match %r{^$}, image + + image = user_image(gravatar_user, :class => "foo") + assert_match %r{^$}, image + end + + def test_user_thumbnail + user = create(:user) + gravatar_user = create(:user, :image_use_gravatar => true) + + image = user_thumbnail(user) + assert_match %r{^$}, image + + image = user_thumbnail(user, :class => "foo") + assert_match %r{^$}, image + + image = user_thumbnail(gravatar_user) + assert_match %r{^$}, image + + image = user_thumbnail(gravatar_user, :class => "foo") + assert_match %r{^$}, image + end + + def test_user_thumbnail_tiny + user = create(:user) + gravatar_user = create(:user, :image_use_gravatar => true) + + image = user_thumbnail_tiny(user) + assert_match %r{^$}, image + + image = user_thumbnail_tiny(user, :class => "foo") + assert_match %r{^$}, image + + image = user_thumbnail_tiny(gravatar_user) + assert_match %r{^$}, image + + image = user_thumbnail_tiny(gravatar_user, :class => "foo") + assert_match %r{^$}, image + end + + def test_user_image_url + user = create(:user) + gravatar_user = create(:user, :image_use_gravatar => true) + + url = user_image_url(user) + assert_match %r{^/users/images/original.png$}, url + + url = user_image_url(gravatar_user) + assert_match %r{^http://www.gravatar.com/avatar/}, url + end + + def test_openid_logo + logo = openid_logo + assert_match %r{^$}, logo + end + + def test_auth_button + button = auth_button("google", "google") + assert_equal button, "\"Login" + + button = auth_button("yahoo", "openid", :openid_url => "yahoo.com") + assert_equal button, "\"Login" + end + + private + + def request + controller.request + end +end -- 2.39.5