Commit a41ff9d0 authored by nicolasdular's avatar nicolasdular

Fix broadcast message rendering

With the broadcast placeholders we're using
`Banzai#render_and_post_process` instead of `Banzai#render_field` like
before. `render_and_post_process` is using `render` instead of
`render_field` internally, which means that we need to pass in the text
of a broadcast message instead of which field should be rendered.

However another difference of this method is that it is not
automatically using the `BroadcastMessagePipeline` for rendering. We
could overcome this by passing `pipeline: :broadcast_message` in the
context but I've instead added another method
`render_field_and_post_process` which calls `render_field` internally
instead to align with the behaviour that we used before.
parent c25b124e
......@@ -48,7 +48,7 @@ module BroadcastMessagesHelper
def render_broadcast_message(broadcast_message)
if Feature.enabled?(:broadcast_message_placeholders)
Banzai.render_and_post_process(broadcast_message.message, {
Banzai.render_field_and_post_process(broadcast_message, :message, {
current_user: current_user,
skip_project_check: true,
broadcast_message_placeholders: true
......
......@@ -8,6 +8,10 @@ module Banzai
post_process(render(text, context), context)
end
def self.render_field_and_post_process(object, field, context = {})
post_process(render_field(object, field, context), context)
end
def self.render(text, context = {})
Renderer.render(text, context)
end
......
......@@ -68,4 +68,16 @@ describe 'Broadcast Messages' do
expect(page).to have_content "Hi #{user.name}"
end
it 'renders broadcast message with placeholders and styled links' do
create(:broadcast_message, broadcast_type: 'notification', message: "Hi {{name}} <a href='gitlab.com' style='color: purple'>click</a>")
user = create(:user)
sign_in(user)
visit root_path
expected_html = "<p>Hi #{user.name} <a href=\"gitlab.com\" style=\"color: purple\">click</a></p>"
expect(page.body).to include(expected_html)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment