ryanb / letter_opener

Preview mail in the browser instead of sending.
MIT License
3.71k stars 236 forks source link

Load mail before check_delivery_params #129

Closed sj26 closed 8 years ago

sj26 commented 8 years ago

Requiring mail/check_delivery_params before mail itself has been required creates an empty top-level constant Mail which prevents autoloading Mail itself or any of its contents, causing problems like:

$ rails console
Loading development environment (Rails 5.0.0.1)
irb> Mail.new
NoMethodError: undefined method `new' for Mail:Module

because:

irb> defined? Mail
=> "constant"
irb> Mail.methods - Module.instance_methods
=> []
irb> Mail.constants
=> [:CheckDeliveryParams]

This happens because letter opener is requiring mail/check_delivery_params which defines an empty Mail module. Requiring mail itself fixes this:

irb> require "mail"
irb> Mail.new
=> #<Mail::Message:70122492953160, Multipart: false, Headers: >

This is the simplest solution: require mail itself before requiring the check delivery params module. But this means that folks including letter_opener in rails during development will now be pre-loading all of the mail gem every time they boot rails. I'll address this in another PR to add autoloading.