module Mailstro module TestStrategy def self.enable Mailstro.strategy = Mailstro::TestStrategy end @@deliveries = [] @@subscribes = [] @@unsubscribes = [] 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?(conditions) @@deliveries.any? do |delivery| result = true if conditions.is_a?(Hash) if conditions[:template_name] result = result && delivery.template_name == conditions[:template_name] end if conditions[:to] result = result && delivery.contact_email == conditions[:to] end if conditions[:to_list_type] result = result && delivery.list_type == conditions[:to_list_type] end if conditions[:to_list_name] result = result && delivery.list_name == conditions[:to_list_name] end else result = delivery.template_name == conditions end result end 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