Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber default_url_options[:host] everytime "www.example.com" even if specified in environtemnts/test.rb

I specified the default_url_options in my environments/test.rb with

config.action_mailer.default_url_options = { :host => "www.xyu.at" }

This is quite ok and in my cucumber story, where i test registration of users, the user-activation link gets generated right

invitation_activation_url(1)
=> "www.xyu.at/signup/1231hj23jh23"

But when I try to follow the link provided in the email with following code in features/steps/user_steps.rb (using email-rspec from http://github.com/bmabey/email-spec/tree/master):

When /^I follow the invitation link$/ do
  When 'I follow "'+invitation_activation_url(1) + '" in the email'
end

Here the url gets created with the default-host:

invitation_activation_url(1)
=> "www.example.com/signup/1231hj23jh23"

Can anybody help me? I don't get what I'm doing wrong....

Thanks!

EDIT:

It seems to do with the method

current_url

but I dont know where it comes from..?

EDIT:

And I have the right environment specified in my features/support/env.rb

ENV["RAILS_ENV"] ||= "test"

EDIT:

My temporary solution is, what edbond said,

invitation_activation_url(1, :host => "www.xyz.at")
  => "www.xyz.at/signup/1231hj23jh23"

but I dont want to name the domain explicit this way (i specified it already in my environments/test.rb file - that way it wouldnt be dry)

like image 573
BvuRVKyUVlViVIc7 Avatar asked Nov 06 '22 20:11

BvuRVKyUVlViVIc7


1 Answers

Use :host option in your url.

invitation_activation_url(1, :host => "www.xyz.at")
  => "www.xyz.at/signup/1231hj23jh23"

EDIT:

You can parse email body and get link

  mail = YourMailer.deliveries.last
  email_html = Nokogiri::HTML mail.body.to_s
  approve_link = email_html.at_css("a")["href"]
like image 177
edbond Avatar answered Nov 11 '22 04:11

edbond