Class: Emailer::TestingMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/emailer/testing_middleware.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TestingMiddleware

Returns a new instance of TestingMiddleware.



14
15
16
# File 'lib/emailer/testing_middleware.rb', line 14

def initialize(app)
  @app = app
end

Class Attribute Details

.testing_pathObject

Returns the value of attribute testing_path.



7
8
9
# File 'lib/emailer/testing_middleware.rb', line 7

def testing_path
  @testing_path
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/emailer/testing_middleware.rb', line 18

def call(env)
  if  env["PATH_INFO"].index(TestingMiddleware.testing_path)

    uuid = env["PATH_INFO"][TestingMiddleware.testing_path.length..-1]
    
    return [200, {"Content-Type" => "text/plain"},['Emailer::SmtpFacade.default is not a MockSmtpFacade']] unless
      Emailer::SmtpFacade.default.instance_of? Emailer::MockSmtpFacade 
    
    return [200, {"Content-Type" => "text/plain"},['No email sent']] unless Emailer::SmtpFacade.default.sent.count > 0
    
    return [200, {"Content-Type" => "text/plain"},['No email with that ID']] unless Emailer::SmtpFacade.default.sent[uuid]
    
    return [200, {"Content-Type" => "text/html"}, [Emailer::SmtpFacade.default.sent[uuid][:body].to_s]]
  end
  
  @app.call env
end