locoboy
locoboy

Reputation: 38900

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?

Upvotes: 4

Views: 832

Answers (2)

sailor
sailor

Reputation: 8034

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

Upvotes: 9

marcgg
marcgg

Reputation: 66436

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.

Upvotes: 1

Related Questions