From 86ca3e4f5f1ddfdb101c567d80f1b30e0913d0f1 Mon Sep 17 00:00:00 2001 From: Artem Chistyakov Date: Wed, 4 Jul 2012 13:26:18 +0800 Subject: [PATCH] Improved attachments fix for Mail. Added specs. --- CHANGELOG.rdoc | 20 ++++++++++++------- VERSION | 2 +- lib/postmark/attachments_fix_for_mail.rb | 25 ++++++++++++++---------- lib/postmark/version.rb | 2 +- spec/postmark_spec.rb | 20 +++++++++++++++++++ 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 5ecf07e..3ca4673 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,23 +1,29 @@ = Changelog +== 0.9.12 + +* Fixed a problem of attachments processing when using deliver! method on Mail object. +* Removed activesupport dependency for Postmark::AttachmentsFixForMail. +* Added specs for AttachmentFixForMail. + == 0.9.11 -* Replaced Jeweler by Bundler -* Updated RSpec to 2.8 -* Fixed specs -* Refactored the codebase +* Replaced Jeweler by Bundler. +* Updated RSpec to 2.8. +* Fixed specs. +* Refactored the codebase. == 0.9.10 -* Fixed Ruby 1.9 compatibility issue +* Fixed Ruby 1.9 compatibility issue. == 0.9.9 -* Added support for non-array reply_to addresses +* Added support for non-array reply_to addresses. == 0.9.8 -* Fixed bug that caused unexpected multiple email deliveries on Ruby1.9.2/Rails3.0.7 +* Fixed bug that caused unexpected multiple email deliveries on Ruby 1.9.2/Rails 3.0.7. == 0.9.7 diff --git a/VERSION b/VERSION index 8225a4b..583b27a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.11 +0.9.12 diff --git a/lib/postmark/attachments_fix_for_mail.rb b/lib/postmark/attachments_fix_for_mail.rb index 2ab8a5f..3c062a1 100644 --- a/lib/postmark/attachments_fix_for_mail.rb +++ b/lib/postmark/attachments_fix_for_mail.rb @@ -19,25 +19,30 @@ module Postmark module AttachmentsFixForMail def self.included(base) - base.class_eval do - alias_method_chain :deliver, :postmark_hook + base.class_eval do + alias_method :deliver_without_postmark_hook, :deliver + alias_method :deliver_without_postmark_hook!, :deliver! + + def deliver! + remove_postmark_attachments_from_standard_fields + deliver_without_postmark_hook! + end + + def deliver + remove_postmark_attachments_from_standard_fields + deliver_without_postmark_hook + end end end - - def deliver_with_postmark_hook - remove_postmark_attachments_from_standard_fields - deliver_without_postmark_hook - end - + private - + def remove_postmark_attachments_from_standard_fields field = self['POSTMARK-ATTACHMENTS'] return if field.nil? self.postmark_attachments = field.value header.fields.delete_if{|f| f.name == 'postmark-attachments'} end - end end \ No newline at end of file diff --git a/lib/postmark/version.rb b/lib/postmark/version.rb index 6eaa2e1..68d3bdd 100644 --- a/lib/postmark/version.rb +++ b/lib/postmark/version.rb @@ -1,3 +1,3 @@ module Postmark - VERSION = "0.9.11" + VERSION = "0.9.12" end diff --git a/spec/postmark_spec.rb b/spec/postmark_spec.rb index ccfa5b9..a46b1bb 100644 --- a/spec/postmark_spec.rb +++ b/spec/postmark_spec.rb @@ -158,6 +158,26 @@ def response_body(status, message="") end end + context "attachments hook", :ruby => 1.9 do + before(:all) { Mail::Message.send(:include, Postmark::AttachmentsFixForMail) } + + before do + mail_message.delivery_method Mail::Postmark + mail_message.should_receive(:remove_postmark_attachments_from_standard_fields) + Postmark.should_receive(:send_through_postmark).with(mail_message) + end + + it "should run postmark attachments hook when using deliver! method" do + mail_message.deliver! + end + + it "should run postmark attachments hook when using deliver method" do + mail_message.deliver + end + + + end + context "JSON library support" do [:Json, :ActiveSupport, :Yajl].each do |lib| begin