2017-03-23 04:43:34 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe AvatarsHelper do
|
2017-06-02 03:42:18 -04:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2017-03-23 04:43:34 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe '#user_avatar' do
|
|
|
|
subject { helper.user_avatar(user: user) }
|
|
|
|
|
|
|
|
it "links to the user's profile" do
|
|
|
|
is_expected.to include("href=\"#{user_path(user)}\"")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the user's name as title" do
|
|
|
|
is_expected.to include("title=\"#{user.name}\"")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the user's avatar image" do
|
2017-05-10 00:26:17 -04:00
|
|
|
is_expected.to include(CGI.escapeHTML(user.avatar_url(size: 16)))
|
2017-03-23 04:43:34 -04:00
|
|
|
end
|
|
|
|
end
|
2017-06-02 03:42:18 -04:00
|
|
|
|
|
|
|
describe '#user_avatar_without_link' do
|
|
|
|
let(:options) { { user: user } }
|
|
|
|
subject { helper.user_avatar_without_link(options) }
|
|
|
|
|
|
|
|
it 'displays user avatar' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: 'avatar s16 has-tooltip lazy',
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
2017-07-24 13:36:52 -04:00
|
|
|
data: { container: 'body', src: avatar_icon(user, 16) }
|
2017-06-02 03:42:18 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with css_class parameter' do
|
|
|
|
let(:options) { { user: user, css_class: '.cat-pics' } }
|
|
|
|
|
|
|
|
it 'uses provided css_class' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: "avatar s16 #{options[:css_class]} has-tooltip lazy",
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
|
|
|
data: { container: 'body', src: avatar_icon(user, 16) }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with size parameter' do
|
|
|
|
let(:options) { { user: user, size: 99 } }
|
|
|
|
|
|
|
|
it 'uses provided size' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: "avatar s#{options[:size]} has-tooltip lazy",
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
2017-07-24 13:36:52 -04:00
|
|
|
data: { container: 'body', src: avatar_icon(user, options[:size]) }
|
2017-06-02 03:42:18 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with url parameter' do
|
|
|
|
let(:options) { { user: user, url: '/over/the/rainbow.png' } }
|
|
|
|
|
|
|
|
it 'uses provided url' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: 'avatar s16 has-tooltip lazy',
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
2017-07-24 13:36:52 -04:00
|
|
|
data: { container: 'body', src: options[:url] }
|
2017-06-02 03:42:18 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-22 17:41:17 -04:00
|
|
|
context 'with has_tooltip parameter' do
|
|
|
|
context 'with has_tooltip set to true' do
|
|
|
|
let(:options) { { user: user, has_tooltip: true } }
|
|
|
|
|
|
|
|
it 'adds has-tooltip' do
|
|
|
|
is_expected.to eq image_tag(
|
|
|
|
LazyImageTagHelper.placeholder_image,
|
|
|
|
class: 'avatar s16 has-tooltip lazy',
|
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
|
|
|
data: { container: 'body', src: avatar_icon(user, 16) }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with has_tooltip set to false' do
|
|
|
|
let(:options) { { user: user, has_tooltip: false } }
|
|
|
|
|
|
|
|
it 'does not add has-tooltip or data container' do
|
|
|
|
is_expected.to eq image_tag(
|
|
|
|
LazyImageTagHelper.placeholder_image,
|
|
|
|
class: 'avatar s16 lazy',
|
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
|
|
|
data: { src: avatar_icon(user, 16) }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-02 03:42:18 -04:00
|
|
|
context 'with user_name parameter' do
|
|
|
|
let(:options) { { user_name: 'Tinky Winky', user_email: 'no@f.un' } }
|
|
|
|
|
|
|
|
context 'with user parameter' do
|
|
|
|
let(:options) { { user: user, user_name: 'Tinky Winky' } }
|
|
|
|
|
|
|
|
it 'prefers user parameter' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: 'avatar s16 has-tooltip lazy',
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{user.name}'s avatar",
|
|
|
|
title: user.name,
|
2017-07-24 13:36:52 -04:00
|
|
|
data: { container: 'body', src: avatar_icon(user, 16) }
|
2017-06-02 03:42:18 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses user_name and user_email parameter if user is not present' do
|
|
|
|
is_expected.to eq image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
LazyImageTagHelper.placeholder_image,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: 'avatar s16 has-tooltip lazy',
|
2017-06-02 03:42:18 -04:00
|
|
|
alt: "#{options[:user_name]}'s avatar",
|
|
|
|
title: options[:user_name],
|
2017-07-24 13:36:52 -04:00
|
|
|
data: { container: 'body', src: avatar_icon(options[:user_email], 16) }
|
2017-06-02 03:42:18 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-23 04:43:34 -04:00
|
|
|
end
|