Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rspec failing "Missing host to link to!..."

I'm currently getting the following error:

 1) Organization.invite_user should create a new user for a specific orgs initial user
     Failure/Error: organization.invite_user(second_email)
     ActionView::Template::Error:
       Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
     # ./app/views/devise/mailer/reset_password_instructions.html.erb:5:in `_app_views_devise_mailer_reset_password_instructions_html_erb___4480543240081585515_70131221479860'
     # ./app/models/organization.rb:34:in `invite_user'
     # ./spec/models/organization_spec.rb:24:in `block (3 levels) in <top (required)>'

Anyone know what could be happening here in rspec?

like image 833
locoboy Avatar asked Oct 25 '25 21:10

locoboy


2 Answers

in your config/environments/test.rb file, you should provide the following configuration:

config.action_mailer.default_url_options = { host: 'www.example.com' }

for links to be generated by ActionMailer

like image 137
sailor Avatar answered Oct 28 '25 14:10

sailor


The error seems pretty self explanatory: you need to provide more information to your mailer initializer so that it knows how to actually render the links.

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

If you don't do that, the links would have to be relatives, which makes no sense when talking about links in emails.

like image 44
marcgg Avatar answered Oct 28 '25 13:10

marcgg