From 2e31c85a97183814ffa7ba5cc58f7bbad668fb2b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 18 Mar 2020 00:09:16 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../broadcast_message_placeholders_filter_spec.rb | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb (limited to 'spec/lib/banzai') diff --git a/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb b/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb new file mode 100644 index 00000000000..1a90abc12d9 --- /dev/null +++ b/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Banzai::Filter::BroadcastMessagePlaceholdersFilter do + include FilterSpecHelper + + subject { filter(text, current_user: user, broadcast_message_placeholders: true).to_html } + + describe 'when current user is set' do + let_it_be(:user) { create(:user, email: "helloworld@example.com", name: "GitLab Tanunki :)") } + + context 'replaces placeholder in text' do + let(:text) { 'Email: {{email}}' } + + it { expect(subject).to eq("Email: #{user.email}") } + end + + context 'replaces placeholder when they are in a link' do + let(:text) { 'link' } + + it { expect(subject).to eq("link") } + end + + context 'replaces placeholder when they are in an escaped link' do + let(:text) { 'link' } + + it { expect(subject).to eq("link") } + end + + context 'works with empty text' do + let(:text) {" "} + + it { expect(subject).to eq(" ") } + end + + context 'replaces multiple placeholders in a given text' do + let(:text) { "{{email}} {{name}}" } + + it { expect(subject).to eq("#{user.email} #{user.name}") } + end + + context 'available placeholders' do + context 'replaces the email of the user' do + let(:text) { "{{email}}"} + + it { expect(subject).to eq(user.email) } + end + + context 'replaces the name of the user' do + let(:text) { "{{name}}"} + + it { expect(subject).to eq(user.name) } + end + + context 'replaces the ID of the user' do + let(:text) { "{{user_id}}" } + + it { expect(subject).to eq(user.id.to_s) } + end + + context 'replaces the username of the user' do + let(:text) { "{{username}}" } + + it { expect(subject).to eq(user.username) } + end + + context 'replaces the instance_id' do + before do + stub_application_setting(uuid: '123') + end + + let(:text) { "{{instance_id}}" } + + it { expect(subject).to eq(Gitlab::CurrentSettings.uuid) } + end + end + end + + describe 'when there is no current user set' do + let(:user) { nil } + + context 'replaces placeholder with empty string' do + let(:text) { "Email: {{email}}" } + + it { expect(subject).to eq("Email: ") } + end + end +end -- cgit v1.2.1