diff options
Diffstat (limited to 'spec/helpers/markup_helper_spec.rb')
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 088519248c6..a9f99f29f6d 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -534,6 +534,45 @@ RSpec.describe MarkupHelper do helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) end.not_to change { Gitlab::GitalyClient.get_request_count } end + + it 'strips non-user links' do + html = 'This a cool [website](https://gitlab.com/).' + + object = create_object(html) + result = helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) + + expect(result).to include('This a cool website.') + end + + it 'styles the current user link', :aggregate_failures do + another_user = create(:user) + html = "Please have a look, @#{user.username} @#{another_user.username}!" + + object = create_object(html) + result = helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) + links = Nokogiri::HTML.parse(result).css('//a') + + expect(links[0].classes).to include('current-user') + expect(links[1].classes).not_to include('current-user') + end + + context 'when current_user is nil' do + before do + allow(helper).to receive(:current_user).and_return(nil) + end + + it 'renders the link with no styling when current_user is nil' do + another_user = create(:user) + html = "Please have a look, @#{user.username} @#{another_user.username}!" + + object = create_object(html) + result = helper.first_line_in_markdown(object, attribute, 100, is_todo: true, project: project) + links = Nokogiri::HTML.parse(result).css('//a') + + expect(links[0].classes).not_to include('current-user') + expect(links[1].classes).not_to include('current-user') + end + end end context 'when the asked attribute can be redacted' do |