Module: Mailstro::TestStrategy

Defined in:
lib/mailstro/test_strategy.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.clearObject



11
12
13
14
15
# File 'lib/mailstro/test_strategy.rb', line 11

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

.deliver(options) ⇒ Object



17
18
19
# File 'lib/mailstro/test_strategy.rb', line 17

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

.enableObject



3
4
5
# File 'lib/mailstro/test_strategy.rb', line 3

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

.has_delivered?(conditions) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mailstro/test_strategy.rb', line 33

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

.has_subscribed?(contact_email, list_type, list_name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/mailstro/test_strategy.rb', line 56

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

.has_unsubscribed?(contact_email, list_type, list_name) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/mailstro/test_strategy.rb', line 64

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

.list_deliver(options) ⇒ Object



21
22
23
# File 'lib/mailstro/test_strategy.rb', line 21

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

.subscribe(contact_email, list_type, list_name) ⇒ Object



25
26
27
# File 'lib/mailstro/test_strategy.rb', line 25

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

.unsubscribe(contact_email, list_type, list_name) ⇒ Object



29
30
31
# File 'lib/mailstro/test_strategy.rb', line 29

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