FIX: emails with embedded posts should always use absolute URLs

This commit is contained in:
Neil Lalonde
2013-11-28 15:57:21 -05:00
parent a13c7c26f9
commit 4ec0543362
3 changed files with 46 additions and 1 deletions
+29
View File
@@ -177,4 +177,33 @@ describe PrettyText do
end
end
describe "make_all_links_absolute" do
let(:base_url) { "http://baseurl.net" }
before do
Discourse.stubs(:base_url).returns(base_url)
end
it "adds base url to relative links" do
html = "<p><a class=\"mention\" href=\"/users/wiseguy\">@wiseguy</a>, <a class=\"mention\" href=\"/users/trollol\">@trollol</a> what do you guys think? </p>"
output = described_class.make_all_links_absolute(html)
output.should == "<p><a class=\"mention\" href=\"#{base_url}/users/wiseguy\">@wiseguy</a>, <a class=\"mention\" href=\"#{base_url}/users/trollol\">@trollol</a> what do you guys think? </p>"
end
it "doesn't change external absolute links" do
html = "<p>Check out <a href=\"http://mywebsite.com/users/boss\">this guy</a>.</p>"
described_class.make_all_links_absolute(html).should == html
end
it "doesn't change internal absolute links" do
html = "<p>Check out <a href=\"#{base_url}/users/boss\">this guy</a>.</p>"
described_class.make_all_links_absolute(html).should == html
end
it "can tolerate invalid URLs" do
html = "<p>Check out <a href=\"not a real url\">this guy</a>.</p>"
expect { described_class.make_all_links_absolute(html) }.to_not raise_error
end
end
end