aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2015-05-04 10:43:52 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2015-05-04 10:56:59 +0100
commit60239f3e5a3303b4135e30469ba7dbf27890008d (patch)
tree4da42b69cae65df57d5caaab6a7d9259846204a5 /railties/test/application
parent9f39d3126fe85c94198371fd1cccd408c268529c (diff)
downloadrails-60239f3e5a3303b4135e30469ba7dbf27890008d.tar.gz
rails-60239f3e5a3303b4135e30469ba7dbf27890008d.tar.bz2
rails-60239f3e5a3303b4135e30469ba7dbf27890008d.zip
Add support for inline images to mailer previews
Use a preview interceptor to search for inline cid: urls in src attributes and convert them to data urls.
Diffstat (limited to 'railties/test/application')
-rw-r--r--railties/test/application/mailer_previews_test.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb
index e727509610..3c9de0115f 100644
--- a/railties/test/application/mailer_previews_test.rb
+++ b/railties/test/application/mailer_previews_test.rb
@@ -487,13 +487,14 @@ module ApplicationTests
end
test "plain text mailer preview with attachment" do
- image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioc\na/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=="
+ image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="
mailer 'notifier', <<-RUBY
class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
+ attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
mail to: "to@example.org"
end
end
@@ -523,14 +524,14 @@ module ApplicationTests
end
test "multipart mailer preview with attachment" do
- image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioc\na/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=="
+ image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="
mailer 'notifier', <<-RUBY
class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
- attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png")
+ attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
mail to: "to@example.org"
end
end
@@ -568,14 +569,14 @@ module ApplicationTests
end
test "multipart mailer preview with inline attachment" do
- image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioc\na/JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=="
+ image_file "pixel.png", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="
mailer 'notifier', <<-RUBY
class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
- attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png")
+ attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
mail to: "to@example.org"
end
end
@@ -611,6 +612,7 @@ module ApplicationTests
get "/rails/mailers/notifier/foo?part=text/html"
assert_equal 200, last_response.status
assert_match %r[<p>Hello, World!</p>], last_response.body
+ assert_match %r[src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEWzIioca_JlAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJgggo="], last_response.body
end
test "multipart mailer preview with attached email" do
@@ -693,7 +695,7 @@ module ApplicationTests
end
def image_file(name, contents)
- app_file("public/images/#{name}", Base64.decode64(contents))
+ app_file("public/images/#{name}", Base64.urlsafe_decode64(contents), 'wb')
end
end
end