Skip to content

Commit

Permalink
delivery schedule option working
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTVsFrank authored and dgoerlich committed Apr 11, 2016
1 parent b6e17cd commit 5e87c6a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def prepare_options_from mail, sparkpost_data
prepare_transactional_from sparkpost_data
prepare_skip_suppression_from sparkpost_data
prepare_ip_pool_from sparkpost_data
prepare_delivery_schedule_from sparkpost_data
prepare_delivery_schedule_from mail
end

def prepare_sandbox_mode_from sparkpost_data
Expand Down Expand Up @@ -284,19 +284,11 @@ def prepare_ip_pool_from sparkpost_data
end
end

def prepare_delivery_schedule_from sparkpost_data
if sparkpost_data[:start_time]
@data[:options][:start_time] = sparkpost_data[:start_time]
def prepare_delivery_schedule_from mail
# Format YYYY-MM-DDTHH:MM:SS+-HH:MM or "now". Example: '2015-02-11T08:00:00-04:00'. -From SparkPost API Docs
if mail.date && (mail.date > DateTime.now) && (mail.date < (DateTime.now + 1.year))
@data[:options][:start_time] = mail.date.strftime("%Y-%m-%dT%H:%M:%S%:z")
end

# if sparkpost_data.has_key?(:start_time)
# if sparkpost_data[:start_time].class == DateTime
# start_time = sparkpost_data[:start_time]
# if (start_time > DateTime.now) && (start_time < DateTime.one_year_from_now)
# @data[:options][:start_time] = start_time.to_s
# end
# end
# end
end

def prepare_headers_from sparkpost_data
Expand Down
46 changes: 46 additions & 0 deletions spec/delivery_schedule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

describe SparkPostRails::DeliveryMethod do

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

context "Delivery Schedule" do
it "handles supplied future DateTime value less than a year from now" do
start_time = (DateTime.now + 4.hours)
formatted_start_time = start_time.strftime("%Y-%m-%dT%H:%M:%S%:z")

test_email = Mailer.test_email date: start_time
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:options][:start_time]).to eq(formatted_start_time)
end

it "does not include start_time if date is in the past" do
start_time = (DateTime.now - 4.hours)

test_email = Mailer.test_email date: start_time
@delivery_method.deliver!(test_email)

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

it "does not include start_time if date is more than 1 year from now" do
start_time = (DateTime.now + 4.years)

test_email = Mailer.test_email date: start_time
@delivery_method.deliver!(test_email)

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

it "does not include start_time if not set" do
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)

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

0 comments on commit 5e87c6a

Please sign in to comment.