From e6090e713b53ed748dc1a8fef962732bdf37ddfe Mon Sep 17 00:00:00 2001 From: jakeburden Date: Tue, 3 Sep 2019 17:26:39 -0400 Subject: [PATCH] Allow for the passing of options to external_link --- app/helpers/external_link_helper.rb | 4 ++-- spec/helpers/external_link_helper_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/external_link_helper.rb b/app/helpers/external_link_helper.rb index fe908b3ae1c..9dbad1f5032 100644 --- a/app/helpers/external_link_helper.rb +++ b/app/helpers/external_link_helper.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module ExternalLinkHelper - def external_link(body, url) - link_to url, target: '_blank', rel: 'noopener noreferrer' do + def external_link(body, url, options = {}) + link_to url, { target: '_blank', rel: 'noopener noreferrer' }.merge(options) do "#{body} #{icon('external-link')}".html_safe end end diff --git a/spec/helpers/external_link_helper_spec.rb b/spec/helpers/external_link_helper_spec.rb index 60ad188e98b..7fc4ef18731 100644 --- a/spec/helpers/external_link_helper_spec.rb +++ b/spec/helpers/external_link_helper_spec.rb @@ -9,4 +9,9 @@ describe ExternalLinkHelper do expect(external_link('https://gitlab.com', 'https://gitlab.com').to_s) .to eq('https://gitlab.com ') end + + it 'allows options when creating external link with icon' do + expect(external_link('https://gitlab.com', 'https://gitlab.com', { "data-foo": "bar", class: "externalLink" }).to_s) + .to eq('https://gitlab.com ') + end end