2018-05-24 18:01:40 +02:00
|
|
|
RSpec.describe StringToHtmlHelper, type: :helper do
|
|
|
|
describe "#string_to_html" do
|
2023-02-03 15:17:12 +01:00
|
|
|
let(:allow_a) { false }
|
|
|
|
subject { string_to_html(description, allow_a:) }
|
2018-02-28 17:14:00 +01:00
|
|
|
|
|
|
|
context "with some simple texte" do
|
|
|
|
let(:description) { "1er ligne \n 2ieme ligne" }
|
|
|
|
|
|
|
|
it { is_expected.to eq("<p>1er ligne \n<br> 2ieme ligne</p>") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a link" do
|
2020-06-22 14:42:10 +02:00
|
|
|
context "using an authorized scheme" do
|
|
|
|
let(:description) { "Cliquez sur https://d-s.fr pour continuer." }
|
2023-02-03 15:17:12 +01:00
|
|
|
|
|
|
|
context 'with a tag authorized' do
|
|
|
|
let(:allow_a) { true }
|
|
|
|
it { is_expected.to eq("<p>Cliquez sur <a href=\"https://d-s.fr\" target=\"_blank\" rel=\"noopener\">https://d-s.fr</a> pour continuer.</p>") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a tag' do
|
|
|
|
it { is_expected.to eq("<p>Cliquez sur https://d-s.fr pour continuer.</p>") }
|
|
|
|
end
|
2020-06-22 14:42:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "using a non-authorized scheme" do
|
|
|
|
let(:description) { "Cliquez sur file://etc/password pour continuer." }
|
|
|
|
it { is_expected.to eq("<p>Cliquez sur file://etc/password pour continuer.</p>") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "not actually an URL" do
|
|
|
|
let(:description) { "Pour info: il ne devrait y avoir aucun lien." }
|
|
|
|
it { is_expected.to eq("<p>Pour info: il ne devrait y avoir aucun lien.</p>") }
|
|
|
|
end
|
2018-02-28 17:14:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with empty decription" do
|
|
|
|
let(:description) { nil }
|
|
|
|
|
2022-02-02 18:03:24 +01:00
|
|
|
it { is_expected.to eq nil }
|
2018-02-28 17:14:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a bad script" do
|
|
|
|
let(:description) { '<script>bad</script>' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('<p>bad</p>') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|