Skip to content

Commit

Permalink
add ip_pool option for config and message, fixed transactional_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTVsFrank authored and dgoerlich committed Apr 11, 2016
1 parent 69525b5 commit 371b479
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/sparkpost_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Configuration
attr_accessor :return_path

attr_accessor :transactional
attr_accessor :ip_pool

def initialize
set_defaults
Expand All @@ -44,6 +45,7 @@ def set_defaults
@return_path = nil

@transactional = false
@ip_pool = nil
end
end
end
14 changes: 14 additions & 0 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def prepare_options_from mail, sparkpost_data
prepare_return_path_from mail
prepare_transactional_from sparkpost_data
prepare_skip_suppression_from sparkpost_data
prepare_ip_pool_from sparkpost_data
end

def prepare_sandbox_mode_from sparkpost_data
Expand Down Expand Up @@ -263,6 +264,19 @@ def prepare_skip_suppression_from sparkpost_data
end
end


def prepare_ip_pool_from sparkpost_data
ip_pool = SparkPostRails.configuration.ip_pool

if sparkpost_data.has_key?(:ip_pool)
ip_pool = sparkpost_data[:ip_pool]
end

if ip_pool
@data[:options][:ip_pool] = ip_pool
end
end

def prepare_headers
@headers = {
"Authorization" => SparkPostRails.configuration.api_key,
Expand Down
50 changes: 50 additions & 0 deletions spec/ip_pool_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 "IP Pool" do
it "handles ip_pool set in the configuration" do
SparkPostRails.configure do |c|
c.ip_pool = "default_ip"
end

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

expect(@delivery_method.data[:options][:ip_pool]).to eq("default_ip")
end

it "handles ip_pool set on an individual message" do
test_email = Mailer.test_email sparkpost_data: {ip_pool: "message_ip"}

@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:options][:ip_pool]).to eq("message_ip")
end

it "handles the value on an individual message overriding configuration" do
SparkPostRails.configure do |c|
c.ip_pool = "default_ip"
end

test_email = Mailer.test_email sparkpost_data: {ip_pool: "message_ip"}

@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:options][:ip_pool]).to eq("message_ip")
end

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

expect(@delivery_method.data[:options].has_key?(:ip_pool)).to eq(false)
end

end
end
2 changes: 1 addition & 1 deletion spec/skip_suppression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@delivery_method = SparkPostRails::DeliveryMethod.new
end

context "Substitution Data" do
context "Skip Suppression" do
it "handles skip_suppression value from message" do
test_email = Mailer.test_email sparkpost_data: {skip_suppression: true}

Expand Down
4 changes: 2 additions & 2 deletions spec/transactional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
expect(@delivery_method.data[:options][:transactional]).to eq(false)
end

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

expect(@delivery_method.data[:options].has_key?(:trasactional)).to eq(false)
expect(@delivery_method.data[:options][:transactional]).to eq(false)
end

end
Expand Down

0 comments on commit 371b479

Please sign in to comment.