2018-05-24 18:01:40 +02:00
|
|
|
RSpec.describe StringToHtmlHelper, type: :helper do
|
|
|
|
describe "#string_to_html" do
|
|
|
|
subject { string_to_html(description) }
|
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." }
|
|
|
|
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 "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 }
|
|
|
|
|
|
|
|
it { is_expected.to eq('<p></p>') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a bad script" do
|
|
|
|
let(:description) { '<script>bad</script>' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('<p>bad</p>') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|