diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /spec/helpers/safe_format_helper_spec.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'spec/helpers/safe_format_helper_spec.rb')
-rw-r--r-- | spec/helpers/safe_format_helper_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/helpers/safe_format_helper_spec.rb b/spec/helpers/safe_format_helper_spec.rb new file mode 100644 index 00000000000..ced48b0c9c1 --- /dev/null +++ b/spec/helpers/safe_format_helper_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe SafeFormatHelper, feature_category: :shared do + describe '#safe_format' do + shared_examples 'safe formatting' do |format, args:, result:| + subject { helper.safe_format(format, **args) } + + it { is_expected.to eq(result) } + it { is_expected.to be_html_safe } + end + + it_behaves_like 'safe formatting', '', args: {}, result: '' + it_behaves_like 'safe formatting', 'Foo', args: {}, result: 'Foo' + + it_behaves_like 'safe formatting', '<b>strong</b>', args: {}, + result: '<b>strong</b>' + + it_behaves_like 'safe formatting', '%{open}strong%{close}', + args: { open: '<b>'.html_safe, close: '</b>'.html_safe }, + result: '<b>strong</b>' + + it_behaves_like 'safe formatting', '%{open}strong%{close} %{user_input}', + args: { open: '<b>'.html_safe, close: '</b>'.html_safe, + user_input: '<a href="">link</a>' }, + result: '<b>strong</b> <a href="">link</a>' + + context 'when format is marked as html_safe' do + let(:format) { '<b>strong</b>'.html_safe } + let(:args) { {} } + + it 'raises an error' do + message = 'Argument `format` must not be marked as html_safe!' + + expect { helper.safe_format(format, **args) } + .to raise_error ArgumentError, message + end + end + end +end |