Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test hook

  • Loading branch information...
commit 5ebab1a816d8ceabccc930f47ddc93e0a8a68431 1 parent 850621e
@fphilipe fphilipe authored
Showing with 72 additions and 0 deletions.
  1. +72 −0 spec/premailer-rails3/hook_spec.rb
View
72 spec/premailer-rails3/hook_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe PremailerRails::Hook do
+ describe '.delivering_email' do
+ def run_hook(message)
+ PremailerRails::Hook.delivering_email(message)
+ end
+
+ context 'when message contains html part' do
+ let(:message) { Fixtures::Message.with_parts :html }
+
+ it 'should create a text part from the html part' do
+ PremailerRails::Premailer.any_instance.expects(:to_plain_text)
+ run_hook(message)
+ message.text_part.should be_a Mail::Part
+ end
+
+ it 'should inline the css in the html part' do
+ PremailerRails::Premailer.any_instance.expects(:to_inline_css)
+ run_hook(message)
+ end
+ end
+
+ context 'when message contains text part' do
+ let(:message) { Fixtures::Message.with_parts :text }
+
+ it 'should not modify the message' do
+ Premailer.expects(:new).never
+ run_hook(message)
+ end
+ end
+
+ context 'when message contains html and text part' do
+ let(:message) { Fixtures::Message.with_parts :html, :text }
+
+ it 'should not create a text part from the html part' do
+ PremailerRails::Premailer.any_instance.expects(:to_plain_text).never
+ run_hook(message)
+ message.text_part.should be_a Mail::Part
+ end
+
+ it 'should inline the css in the html part' do
+ PremailerRails::Premailer.any_instance.expects(:to_inline_css)
+ run_hook(message)
+ end
+ end
+
+ context 'when message contains html body' do
+ let(:message) { Fixtures::Message.with_body :html }
+
+ it 'should create a text part from the html part' do
+ PremailerRails::Premailer.any_instance.expects(:to_plain_text)
+ run_hook(message)
+ end
+
+ it 'should create a html part and inline the css' do
+ PremailerRails::Premailer.any_instance.expects(:to_inline_css)
+ run_hook(message)
+ message.html_part.should be_a Mail::Part
+ end
+ end
+
+ context 'when message contains text body' do
+ let(:message) { Fixtures::Message.with_body :text }
+
+ it 'should not modify the message' do
+ Premailer.expects(:new).never
+ run_hook(message)
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.