Skip to content

Commit

Permalink
Added tag support.
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Mar 23, 2010
1 parent b7742b3 commit c85f583
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
15 changes: 13 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ Then
# ...
end

# tagging message for tracking delivery

class TestMailer < ActionMailer::Base
def tagged_message
subject 'hello'
recipients '[email protected]'
from '[email protected]'
tag 'delivery' # Tag should be a single string
end
end

== Limitations
Currently postmark API does not support multiple recipients, or attachments. For more information, check the docs here:
TODO: URL to docs.
Currently postmark API does not support attachments. For more information, check the docs here:
http://developer.postmarkapp.com

== Requirements

Expand Down
28 changes: 24 additions & 4 deletions lib/postmark-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@ module PostmarkMethods
def perform_delivery_postmark(message)
Postmark.send_through_postmark(message)
end

def tag(value)
@tag = value
end

def self.included(base)
base.extend(ClassMethods)
base.class_eval do
alias_method_chain :create_mail, :tag
end
end

def create_mail_with_tag
returning create_mail_without_tag do |mail|
mail.tag = @tag if @tag
end
end

module ClassMethods
def postmark_api_key=(value)
Postmark.api_key = value
end
end

end

class ActionMailer::Base
include PostmarkMethods

def self.postmark_api_key=(value)
Postmark.api_key = value
end
end
7 changes: 7 additions & 0 deletions spec/fixtures/models/test_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ def multipart_message
from '[email protected]'
end

def tagged_message
subject 'hello'
recipients '[email protected]'
from '[email protected]'
tag 'delivery'
end

end
1 change: 1 addition & 0 deletions spec/fixtures/views/test_mailer/tagged_message.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
8 changes: 8 additions & 0 deletions spec/postmark-rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "PostmarkRails" do

it "should use postmark for delivery" do
Postmark.should_receive(:send_through_postmark) do |message|
message.subject.should == "hello"
end
TestMailer.deliver_simple_message
end

it "should allow tagging of message" do
Postmark.should_receive(:send_through_postmark) do |message|
message.tag.to_s.should == "delivery"
end
TestMailer.deliver_tagged_message
end

end

0 comments on commit c85f583

Please sign in to comment.