Sha256: 4e2d0e13caf13a1c1967b0e17d588851c72054140f355b05c5c51cad8ce2ad95

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require 'rubygems'
require 'test/unit'
require 'shoulda'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'action_mailer'
require 'sendgrid'

class SendgridCampaignTestMailer < ActionMailer::Base
  include SendGrid
  
  sendgrid_enable :opentrack, :clicktrack, :subscriptiontrack, :bypass_list_management
    
  REQUIRED_OPTIONS = [:to, :from, :category, :html_content, :subject]
  
  ##
  # options are:
  # :from the from address
  # :to an array of recipients
  # :substitutions a hash of substitutions of the form: 'text to be
  # replaced' => [replacements]. The order and size of the replacement
  # array must match the :to array
  # :category the sendgrid category used for tracking
  # :html_content, :text_content, :subject
  def create_test(options)
    handle_sendgrid_options(options)
    mail(options)
  end
  
  protected
  def handle_sendgrid_options(options)
    REQUIRED_OPTIONS.each do |option|
      raise ArgumentError.new("Required sendgrid option ':#{option}' missing") unless options[option]
    end
    
    sendgrid_recipients(options[:to])
    
    if options[:substitutions]
      options[:substitutions].each do |find, replace|
        sendgrid_substitute(find, replace)
      end
    end
    
    sendgrid_category(options[:category])
  end
end

class SendgridUniqueArgsMailer < ActionMailer::Base
  include SendGrid
  sendgrid_unique_args({ :test_arg => "test value" })
  
  def unique_args_test_email(options)
    sendgrid_unique_args({ :mailer_method_unique_arg => "some value" })
    mail(options)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sendgrid-1.2.4 test/test_helper.rb
sendgrid-1.2.0 test/test_helper.rb