Skip to content

Commit

Permalink
Implement return path from individual message
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoerlich committed Apr 7, 2016
1 parent b0b1e1f commit 9d1fdca
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
17 changes: 13 additions & 4 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ def prepare_options_from mail, sparkpost_data
prepare_open_tracking_from sparkpost_data
prepare_click_tracking_from sparkpost_data
prepare_campaign_id_from sparkpost_data

unless SparkPostRails.configuration.return_path.nil?
@data[:return_path] = SparkPostRails.configuration.return_path
end
prepare_return_path_from mail

end

Expand Down Expand Up @@ -238,6 +235,18 @@ def prepare_campaign_id_from sparkpost_data
end
end

def prepare_return_path_from mail
return_path = SparkPostRails.configuration.return_path

unless mail.return_path.nil?
return_path = mail.return_path
end

if return_path
@data[:return_path] = return_path
end
end

def prepare_headers
@headers = {
"Authorization" => SparkPostRails.configuration.api_key,
Expand Down
29 changes: 0 additions & 29 deletions spec/options_spec.rb

This file was deleted.

50 changes: 50 additions & 0 deletions spec/return_path_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'spec_helper'

describe SparkPostRails::DeliveryMethod do

before(:each) do
SparkPostRails.configuration.set_defaults
@delivery_method = SparkPostRails::DeliveryMethod.new
end

context "Return Path" do
it "handles return path set in the configuration" do
SparkPostRails.configure do |c|
c.return_path = "[email protected]"
end

test_email = Mailer.test_email
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:return_path]).to eq('[email protected]')
end

it "handles return path on an individual message" do
test_email = Mailer.test_email return_path: "[email protected]"

@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:return_path]).to eq('[email protected]')
end

it "handles the value on an individual message overriding configuration" do
SparkPostRails.configure do |c|
c.return_path = "[email protected]"
end

test_email = Mailer.test_email return_path: "[email protected]"

@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:return_path]).to eq('[email protected]')
end

it "handles a default setting of none" do
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)

expect(@delivery_method.data.has_key?(:return_path)).to eq(false)
end

end
end

0 comments on commit 9d1fdca

Please sign in to comment.