Sha256: a452590da72438ef97e117cfeb3b3780d5acf6ae6bec9774941812a1ec5bc28e

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Mailstro
  module TestStrategy
    def self.enable
      Mailstro.strategy = Mailstro::TestStrategy
    end

    @@deliveries   = []
    @@subscribes   = []
    @@unsubscribes = []

    def self.deliveries
      @@deliveries
    end

    def self.clear
      @@deliveries   = []
      @@subscribes   = []
      @@unsubscribes = []
    end

    def self.deliver(options)
      @@deliveries << Delivery.new(options)
    end

    def self.list_deliver(options)
      @@deliveries << ListDelivery.new(options)
    end

    def self.subscribe(contact_email, list_type, list_name)
      @@subscribes << ListSubscribe.new(contact_email, list_type, list_name)
    end

    def self.unsubscribe(contact_email, list_type, list_name)
      @@unsubscribes << ListUnsubscribe.new(contact_email, list_type, list_name)
    end

    def self.has_delivered?(template_name)
      @@deliveries.map(&:template_name).include?(template_name)
    end

    def self.has_subscribed?(contact_email, list_type, list_name)
      @@subscribes.any? do |subscribe|
        subscribe.contact_email == contact_email &&
        subscribe.list_type     == list_type &&
        subscribe.list_name     == list_name
      end
    end

    def self.has_unsubscribed?(contact_email, list_type, list_name)
      @@unsubscribes.any? do |unsubscribe|
        unsubscribe.contact_email == contact_email &&
        unsubscribe.list_type     == list_type &&
        unsubscribe.list_name     == list_name
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mailstro-0.0.7 lib/mailstro/test_strategy.rb