This repository was archived by the owner on Jul 24, 2020. It is now read-only.
This repository was archived by the owner on Jul 24, 2020. It is now read-only.
user_mailer.rb call to uninitialized AppConfig.first causes RSpec to fatally fail to start #398
Closed
Description
When RSpec is run with the default ...
line uncommented, RSpec fails to start. The reason is that there is no AppConfig.first
record while in test mode. Therefore, the call to
class UserMailer < ActionMailer::Base
default :from => AppConfig.first.admin_email, :cc => AppConfig.first.admin_email
# (snip)
results in the error
jane-ribeira (Simon): ~/Coding/reservations [396_model_tests|✚ 2]
05:41 PM $ rspec
/Users/Simon/Coding/reservations/app/mailers/user_mailer.rb:6:in `<class:UserMailer>': undefined method `admin_email' for nil:NilClass (NoMethodError)
from /Users/Simon/Coding/reservations/app/mailers/user_mailer.rb:2:in `<top (required)>'
(snip)
This if-statement fixes the problem temporarily:
class UserMailer < ActionMailer::Base
# Workaround so that RSpec start-up doesn't fail. TODO: Have RSpec initialize AppConfig with configuration.
unless (AppConfig.first.nil?)
default :from => AppConfig.first.admin_email, :cc => AppConfig.first.admin_email
end
# (snip)
The workaround prevents the line from being executed and ensures that RSpec can run, but also means that we cannot test the proper setup of user_mailer.rb
. It is not clear, however, at what stage of test-environment loading this error happens and how it can be prevented.
That may prove difficult, as reversing the condition and debugging in the following manner caused the first Ruby segmentation fault I have ever seen:
class UserMailer < ActionMailer::Base
if (AppConfig.first.nil?)
binding.pry
default :from => AppConfig.first.admin_email, :cc => AppConfig.first.admin_email
end
jane-ribeira (Simon): ~/Coding/reservations [396_model_tests|✚ 1]
05:45 PM $ rspec
Frame number: 0/25
Frame type: class
From: /Users/Simon/Coding/reservations/app/mailers/user_mailer.rb @ line 7 :
/Users/Simon/.rvm/gems/ruby-1.9.3-p327/gems/coderay-1.0.8/lib/coderay.rb:170: [BUG] Segmentation fault
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
-- Control frame information -----------------------------------------------
c:0081 p:0013 s:0315 b:0315 l:000314 d:000314 METHOD /Users/Simon/.rvm/gems/ruby-1.9.3-p327/gems/coderay-1.0.8/lib/coderay.rb:170
c:0080 p:0031 s:0308 b:0305 l:000296 d:000304 BLOCK /Users/Simon/.rvm/gems/ruby-1.9.3-p327/gems/pry-0.9.10/lib/pry/code.rb:312
c:0079 p:---- s:0302 b:0302 l:000301 d:000301 FINISH
c:0078 p:---- s:0300 b:0300 l:000299 d:000299 CFUNC :each
c:0077 p:0044 s:0297 b:0297 l:000296 d:000296 METHOD /Users/Simon/.rvm/gems/ruby-1.9.3-p327/gems/pry-0.9.10/lib/pry/code.rb:311
c:0076 p:0011 s:0292 b:0292 l:000291 d:000291 METHOD /Users/Simon/.rvm/gems/ruby-1.9.3-p327/gems/pry-0.9.10/lib/pry/code.rb:391
(snip)
Activity