Skip to content

Commit

Permalink
Fix #575
Browse files Browse the repository at this point in the history
Fix padrino-mailer tests
  • Loading branch information
DAddYE committed Aug 30, 2011
1 parent 807658b commit 8496dca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion padrino-mailer/lib/padrino-mailer/ext.rb
Expand Up @@ -228,7 +228,7 @@ def render(engine, data=nil, options={}, locals={}, &block)
part do |p|
p.content_type(format)
p.send(:render, engine, data, options, locals, &block)
add_multipart_alternate_header unless html_part.blank?
add_multipart_alternate_header if html_part.present? || provides.include?(:html)
end
end
# Setup the body if we don't have provides
Expand Down
8 changes: 4 additions & 4 deletions padrino-mailer/test/test_email.rb
Expand Up @@ -68,7 +68,7 @@ class TestEmail < Test::Unit::TestCase
assert_equal ['padrino@me.com'], email.from
assert_equal ['padrino@you.com'], email.to
assert_equal 'Hello there Padrino', email.subject
assert_equal 'This is a body of text from a template', email.body.to_s
assert_equal 'This is a body of text from a template', email.body.to_s.chomp
end

should 'send emails with scoped mailer defaults' do
Expand All @@ -93,7 +93,7 @@ class TestEmail < Test::Unit::TestCase
assert_equal ['padrino@from.com'], email.from, "should have used default value"
assert_equal ['padrino@different.com'], email.to, "should have overwritten default value"
assert_equal 'Hello there again Padrino', email.subject
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s.chomp
end

should 'send emails with app mailer defaults' do
Expand All @@ -117,7 +117,7 @@ class TestEmail < Test::Unit::TestCase
assert_equal ['padrino@from.com'], email.from, "should have used default value"
assert_equal ['padrino@different.com'], email.to, "should have overwritten default value"
assert_equal 'This is a test', email.subject
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s.chomp
end

should 'send emails without layout' do
Expand All @@ -142,7 +142,7 @@ class TestEmail < Test::Unit::TestCase
assert_equal ['padrino@me.com'], email.from
assert_equal ['padrino@you.com'], email.to
assert_equal 'Hello there Padrino', email.subject
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s
assert_equal 'This is a foo message in mailers/alternate dir', email.body.to_s.chomp
assert_match /TestMailer/, email.delivery_method.to_s
end

Expand Down
18 changes: 9 additions & 9 deletions padrino-mailer/test/test_message.rb
Expand Up @@ -14,7 +14,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'This is a body of text', message.body.to_s
assert_equal 'This is a body of text', message.body.to_s.chomp
end

should "raise an error if template was not found" do
Expand All @@ -40,7 +40,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'Im Foo!', message.body.to_s
assert_equal 'Im Foo!', message.body.to_s.chomp
end

should "use views paths" do
Expand All @@ -55,7 +55,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'This is a bar message in mailers dir', message.body.to_s
assert_equal 'This is a bar message in mailers dir', message.body.to_s.chomp
end

should "use views and mailers paths" do
Expand All @@ -70,7 +70,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'This is a foo message in mailers/alternate dir', message.body.to_s
assert_equal 'This is a foo message in mailers/alternate dir', message.body.to_s.chomp
end

should "use layouts" do
Expand All @@ -85,7 +85,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'Layout Sample This is a foo message in mailers/sample dir', message.body.to_s
assert_equal 'Layout Sample This is a foo message in mailers/sample dir', message.body.to_s.strip
end

should "use i18n" do
Expand All @@ -102,7 +102,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'Hello World', message.body.to_s
assert_equal 'Hello World', message.body.to_s.chomp

I18n.locale = :it

Expand All @@ -117,7 +117,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'Salve Mondo', message.body.to_s
assert_equal 'Salve Mondo', message.body.to_s.chomp
end

should "auto lookup template for the given content_type" do
Expand All @@ -133,7 +133,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'text html', message.body.to_s
assert_equal 'text html', message.body.to_s.chomp

message = Mail::Message.new do
views File.dirname(__FILE__) + '/fixtures/views/mailers'
Expand All @@ -147,7 +147,7 @@ class TestMessage < Test::Unit::TestCase
assert_equal ['padrino@me.com'], message.from
assert_equal ['padrino@you.com'], message.to
assert_equal 'Hello there Padrino', message.subject
assert_equal 'plain text', message.body.to_s
assert_equal 'plain text', message.body.to_s.chomp
end
end
end
15 changes: 8 additions & 7 deletions padrino-mailer/test/test_part.rb
Expand Up @@ -29,7 +29,7 @@ class TestPart < Test::Unit::TestCase
assert_equal :plain, message.parts[0].content_type
assert_equal "plain text", message.parts[0].body.decoded
assert_equal :html, message.parts[1].content_type
assert_equal "This is a foo message in mailers/sample dir", message.parts[1].body.decoded
assert_equal "This is a foo message in mailers/sample dir", message.parts[1].body.decoded.chomp
assert_equal :plain, message.parts[2].content_type
assert_equal "other", message.parts[2].body.decoded
end
Expand All @@ -54,9 +54,9 @@ class TestPart < Test::Unit::TestCase
assert_not_nil message.text_part
assert_equal 2, message.parts.length
assert_equal :plain, message.parts[0].content_type
assert_equal "plain text", message.parts[0].body.decoded
assert_equal "plain text", message.parts[0].body.decoded.chomp
assert_equal :html, message.parts[1].content_type
assert_equal "text html", message.parts[1].body.decoded
assert_equal "text html", message.parts[1].body.decoded.chomp
end

should "works with less explict multipart templates" do
Expand All @@ -74,9 +74,9 @@ class TestPart < Test::Unit::TestCase
assert_not_nil message.text_part
assert_equal 2, message.parts.length
assert_equal :plain, message.parts[0].content_type
assert_equal "plain text", message.parts[0].body.decoded
assert_equal "plain text", message.parts[0].body.decoded.chomp
assert_equal :html, message.parts[1].content_type
assert_equal "text html", message.parts[1].body.decoded
assert_equal "text html", message.parts[1].body.decoded.chomp
end

should "works with provides" do
Expand All @@ -89,11 +89,12 @@ class TestPart < Test::Unit::TestCase
render 'multipart/basic'
end

assert_match /^multipart\/alternative/, message['content-type'].value
assert_equal 2, message.parts.length
assert_equal :plain, message.parts[0].content_type
assert_equal "plain text", message.parts[0].body.decoded
assert_equal "plain text", message.parts[0].body.decoded.chomp
assert_equal :html, message.parts[1].content_type
assert_equal "text html", message.parts[1].body.decoded
assert_equal "text html", message.parts[1].body.decoded.chomp
end

# should "provide a way to instantiate a new part as you go down" do
Expand Down

0 comments on commit 8496dca

Please sign in to comment.