test/action_mailer.rb in ar_mailer-1.0.1 vs test/action_mailer.rb in ar_mailer-1.1.0
- old
+ new
@@ -1,18 +1,21 @@
require 'net/smtp'
require 'time'
class Net::SMTP
+ @reset_called = 0
+
@deliveries = []
@send_message_block = nil
class << self
attr_reader :deliveries
attr_reader :send_message_block
+ attr_accessor :reset_called
alias old_start start
end
@@ -22,16 +25,29 @@
def self.on_send_message(&block)
@send_message_block = block
end
+ def self.reset
+ deliveries.clear
+ on_send_message
+ @reset_called = 0
+ end
+
+ alias old_reset reset if instance_methods.include? 'reset'
+
+ def reset
+ self.class.reset_called += 1
+ end
+
alias old_send_message send_message
def send_message(mail, to, from)
return self.class.send_message_block.call(mail, to, from) unless
self.class.send_message_block.nil?
self.class.deliveries << [mail, to, from]
+ return "queued"
end
end
##
@@ -53,10 +69,14 @@
meth.to_s =~ /deliver_(.*)/
super unless $1
new($1, *args).deliver!
end
+ def self.reset
+ server_settings.clear
+ end
+
def self.server_settings
@server_settings
end
def initialize(meth = nil)
@@ -91,30 +111,37 @@
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.nil? or r.last_send_attempt < now
+ r.last_send_attempt < now
end
end
+ def self.reset
+ @id = 0
+ records.clear
+ end
+
def initialize(from, to, mail)
@from = from
@to = to
@mail = mail
@id = self.class.id += 1
@created_on = START + @id
+ @last_send_attempt = 0
end
def destroy
self.class.records.delete self
self.freeze
end
def ==(other)
- other.from == from and
- other.to == to and
- other.mail == mail
+ other.id == id
+ end
+
+ def save
end
end
class String