<\/div><\/div>/)
end
end
@@ -56,51 +68,75 @@ describe Email::Styles do
end
it "attaches a style to h3 tags" do
- frag = html_fragment("
hello
")
- expect(frag.at('h3')['style']).to be_present
+ doc = html_doc("
hello
")
+ expect(doc.at('h3')['style']).to be_present
end
it "attaches a style to hr tags" do
- frag = html_fragment("hello
")
- expect(frag.at('hr')['style']).to be_present
+ doc = html_doc("hello
")
+ expect(doc.at('hr')['style']).to be_present
end
it "attaches a style to a tags" do
- frag = html_fragment("
wat")
- expect(frag.at('a')['style']).to be_present
+ doc = html_doc("
wat")
+ expect(doc.at('a')['style']).to be_present
end
it "attaches a style to a tags" do
- frag = html_fragment("
wat")
- expect(frag.at('a')['style']).to be_present
+ doc = html_doc("
wat")
+ expect(doc.at('a')['style']).to be_present
end
it "attaches a style to ul and li tags" do
- frag = html_fragment("
")
- expect(frag.at('ul')['style']).to be_present
- expect(frag.at('li')['style']).to be_present
+ doc = html_doc("
")
+ expect(doc.at('ul')['style']).to be_present
+ expect(doc.at('li')['style']).to be_present
end
it "converts iframes to links" do
iframe_url = "http://www.youtube.com/embed/7twifrxOTQY?feature=oembed&wmode=opaque"
- frag = html_fragment("
")
- expect(frag.at('iframe')).to be_blank
- expect(frag.at('a')).to be_present
- expect(frag.at('a')['href']).to eq(iframe_url)
+ doc = html_doc("
")
+ expect(doc.at('iframe')).to be_blank
+ expect(doc.at('a')).to be_present
+ expect(doc.at('a')['href']).to eq(iframe_url)
end
it "won't allow non URLs in iframe src, strips them with no link" do
iframe_url = "alert('xss hole')"
- frag = html_fragment("
")
- expect(frag.at('iframe')).to be_blank
- expect(frag.at('a')).to be_blank
+ doc = html_doc("
")
+ expect(doc.at('iframe')).to be_blank
+ expect(doc.at('a')).to be_blank
+ end
+ end
+
+ context "format notifications" do
+ it "adds both styles and attributes" do
+ doc = notification_doc("
")
+ expect(doc.at('td')['style']).to eq('padding-top:5px;')
+ expect(doc.at('td')['colspan']).to eq('2')
+ end
+
+ it "adds attributes when no styles are present" do
+ doc = notification_doc("
")
+ expect(doc.at('img')['width']).to eq('45')
+ end
+
+ it "adds correct styles to the wrapper" do
+ doc = notification_doc('
')
+ expect(doc.at('center')['style']).to eq('width:100%;table-layout:fixed;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;')
+ end
+
+ it "doesn't override inline attributes" do
+ doc = notification_doc('
')
+ expect(doc.at('table')['align']).to eq('center')
+ expect(doc.at('table')['width']).to eq('600')
end
end
context "rewriting protocol relative URLs to the forum" do
it "doesn't rewrite a url to another site" do
- frag = html_fragment('
hello')
- expect(frag.at('a')['href']).to eq("//youtube.com/discourse")
+ doc = html_doc('
hello')
+ expect(doc.at('a')['href']).to eq("//youtube.com/discourse")
end
context "without https" do
@@ -109,18 +145,18 @@ describe Email::Styles do
end
it "rewrites the href to have http" do
- frag = html_fragment('
hello')
- expect(frag.at('a')['href']).to eq("http://test.localhost/discourse")
+ doc = html_doc('
hello')
+ expect(doc.at('a')['href']).to eq("http://test.localhost/discourse")
end
it "rewrites the href for attachment files to have http" do
- frag = html_fragment('
attachment_file.txt')
- expect(frag.at('a')['href']).to eq("http://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
+ doc = html_doc('
attachment_file.txt')
+ expect(doc.at('a')['href']).to eq("http://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
end
it "rewrites the src to have http" do
- frag = html_fragment('

')
- expect(frag.at('img')['src']).to eq("http://test.localhost/blah.jpg")
+ doc = html_doc('

')
+ expect(doc.at('img')['src']).to eq("http://test.localhost/blah.jpg")
end
end
@@ -130,18 +166,18 @@ describe Email::Styles do
end
it "rewrites the forum URL to have https" do
- frag = html_fragment('
hello')
- expect(frag.at('a')['href']).to eq("https://test.localhost/discourse")
+ doc = html_doc('
hello')
+ expect(doc.at('a')['href']).to eq("https://test.localhost/discourse")
end
it "rewrites the href for attachment files to have https" do
- frag = html_fragment('
attachment_file.txt')
- expect(frag.at('a')['href']).to eq("https://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
+ doc = html_doc('
attachment_file.txt')
+ expect(doc.at('a')['href']).to eq("https://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
end
it "rewrites the src to have https" do
- frag = html_fragment('

')
- expect(frag.at('img')['src']).to eq("https://test.localhost/blah.jpg")
+ doc = html_doc('

')
+ expect(doc.at('img')['src']).to eq("https://test.localhost/blah.jpg")
end
end
@@ -152,16 +188,15 @@ describe Email::Styles do
emoji = "

"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
- expect(style.to_html).to match_html(emoji)
+ expect(style.to_html).to match_html("#{emoji}")
end
it "works for lonesome emoji with title" do
emoji = "

"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
- expect(style.to_html).to match_html("cry_cry")
+ expect(style.to_html).to match_html("cry_cry")
end
end
-
end
diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb
index 4c250f18e..7b56e2bb7 100644
--- a/spec/mailers/user_notifications_spec.rb
+++ b/spec/mailers/user_notifications_spec.rb
@@ -35,6 +35,10 @@ describe UserNotifications do
expect(subject.body).to be_present
end
+ it "does not use the layout" do
+ expect(subject.html_part.to_s.scan(/
/).count).to eq(0)
+ end
+
end
describe ".forgot_password" do
@@ -48,6 +52,10 @@ describe UserNotifications do
expect(subject.body).to be_present
end
+ it "does not use the layout" do
+ expect(subject.html_part.to_s.scan(/
/).count).to eq(0)
+ end
+
end
describe '.digest' do
@@ -77,6 +85,10 @@ describe UserNotifications do
expect(subject.text_part.body.to_s).to be_present
end
+ it "uses the layout" do
+ expect(subject.html_part.to_s.scan(/
/).count).to eq(1)
+ end
+
it "includes email_prefix in email subject instead of site title" do
SiteSetting.email_prefix = "Try Discourse"
SiteSetting.title = "Discourse Meta"
@@ -104,6 +116,8 @@ describe UserNotifications do
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
+ # meta tag should be present from the layout
+ expect(mail.html_part.to_s.scan(/
/).count).to eq(1)
# from should include full user name
expect(mail[:from].display_names).to eql(['John Doe'])
@@ -156,6 +170,9 @@ describe UserNotifications do
notification_data_hash: notification.data_hash
)
+ # meta tag should be present from the layout
+ expect(mail.html_part.to_s.scan(/
/).count).to eq(1)
+
# from should not include full user name if "show user full names" is disabled
expect(mail[:from].display_names).to_not eql(['John Doe'])
@@ -193,6 +210,9 @@ describe UserNotifications do
notification_data_hash: notification.data_hash
)
+ # meta tag should be present from the layout
+ expect(mail.html_part.to_s.scan(/
/).count).to eq(1)
+
# from should include username if full user name is not provided
expect(mail[:from].display_names).to eql(['john'])