fix project_helper.rb and add couple specs to it

This commit is contained in:
Maxim Rydkin 2017-09-06 19:26:01 +03:00
parent 0a08e07303
commit 2a54cbcab8
No known key found for this signature in database
GPG Key ID: B7BCD8B7C2B9E3B3
2 changed files with 19 additions and 5 deletions

View File

@ -17,11 +17,13 @@ module ProjectsHelper
def link_to_member_avatar(author, opts = {})
default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" }
opts = default_opts.merge(opts)
classes = %w[avatar avatar-inline]
classes << "s#{opts[:size]}"
return unless opts[:avatar]
classes = %W[avatar avatar-inline s#{opts[:size]}]
classes << opts[:avatar_class] if opts[:avatar_class]
image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: classes, alt: '') if opts[:avatar]
image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: classes, alt: '')
end
def link_to_member(project, author, opts = {}, &block)

View File

@ -193,13 +193,25 @@ describe ProjectsHelper do
describe '#link_to_member_avatar' do
let(:user) { build_stubbed(:user) }
let(:expected) { double }
it 'returns image tag for member avatar' do
allow(helper).to receive(:image_tag).with(nil, { width: 16, class: ["avatar", "avatar-inline", "s16"], alt: "" })
allow(helper).to receive(:avatar_icon).with(user, 16)
expect(helper).to receive(:avatar_icon).with(user, 16).and_return(expected)
expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16"], alt: "" })
helper.link_to_member_avatar(user)
end
it 'returns image tag with avatar class' do
expect(helper).to receive(:avatar_icon).with(user, 16).and_return(expected)
expect(helper).to receive(:image_tag).with(expected, { width: 16, class: ["avatar", "avatar-inline", "s16", "any-avatar-class"], alt: "" })
helper.link_to_member_avatar(user, avatar_class: "any-avatar-class")
end
it 'returns no image tag if avatar is nil' do
expect(helper.link_to_member_avatar(user, avatar: nil)).to eq(nil)
end
end
describe '#link_to_member' do