A platform for community discussion. Free, open, simple.
# frozen_string_literal: true
RSpec.describe AdminNotice do
it { is_expected.to validate_presence_of(:identifier) }
describe "#message" do
def store_problem_translation(text)
I18n.backend.store_translations(:en, { "dashboard" => { "problem" => { "test" => text } } })
end
it "interpolates the notice details into the translation" do
store_problem_translation("Something is wrong with the %{thing}")
notice = Fabricate(:admin_notice, identifier: "test", details: { thing: "world" })
expect(notice.message).to eq("Something is wrong with the world")
end
it "keeps allowed tags and strips the others" do
store_problem_translation("Rename <code>%{old}</code> <b>now</b>")
notice = Fabricate(:admin_notice, identifier: "test", details: { old: "a/b" })
expect(notice.message).to eq("Rename <code>a/b</code> now")
end
it "expands setting markers into links that survive sanitization" do
store_problem_translation("Configure {{setting:title}} to fix this")
notice = Fabricate(:admin_notice, identifier: "test")
expect(notice.message).to eq(
"Configure #{SiteSettings::LabelFormatter.linkify(:title)} to fix this",
)
end
end
end