test/action_mailer.rb in ar_mailer-1.2.0 vs test/action_mailer.rb in ar_mailer-1.3.1
- old
+ new
@@ -8,10 +8,12 @@
@deliveries = []
@send_message_block = nil
+ @start_block = nil
+
class << self
attr_reader :deliveries
attr_reader :send_message_block
attr_accessor :reset_called
@@ -19,19 +21,25 @@
send :remove_method, :start
end
def self.start(*args)
+ @start_block.call if @start_block
yield new(nil)
end
def self.on_send_message(&block)
@send_message_block = block
end
+ def self.on_start(&block)
+ @start_block = block
+ end
+
def self.reset
deliveries.clear
+ on_start
on_send_message
@reset_called = 0
end
alias test_old_reset reset if instance_methods.include? 'reset'
@@ -103,15 +111,31 @@
@id = 0
class << self; attr_accessor :records, :id; end
def self.create(record)
- record = new record[:from], record[:to], record[:mail]
+ record = new record[:from], record[:to], record[:mail],
+ record[:last_send_attempt]
records << record
return record
end
+ def self.destroy_all(conditions)
+ timeout = conditions.last
+ found = []
+
+ records.each do |record|
+ next if record.last_send_attempt == 0
+ next if record.created_on == 0
+ next unless record.created_on < timeout
+ record.destroy
+ found << record
+ end
+
+ found
+ end
+
def self.find(_, conditions = nil)
return records if conditions.nil?
now = Time.now.to_i - 300
return records.select do |r|
r.last_send_attempt < now
@@ -121,16 +145,16 @@
def self.reset
@id = 0
records.clear
end
- def initialize(from, to, mail)
+ def initialize(from, to, mail, last_send_attempt = nil)
@from = from
@to = to
@mail = mail
@id = self.class.id += 1
@created_on = START + @id
- @last_send_attempt = 0
+ @last_send_attempt = last_send_attempt || 0
end
def destroy
self.class.records.delete self
self.freeze