Skip to content

Commit

Permalink
Improved attachments fix for Mail. Added specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Chistyakov committed Jul 4, 2012
1 parent 5d41761 commit 86ca3e4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
20 changes: 13 additions & 7 deletions 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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.9.11
0.9.12
25 changes: 15 additions & 10 deletions lib/postmark/attachments_fix_for_mail.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/postmark/version.rb
@@ -1,3 +1,3 @@
module Postmark
VERSION = "0.9.11"
VERSION = "0.9.12"
end
20 changes: 20 additions & 0 deletions spec/postmark_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 86ca3e4

Please sign in to comment.