Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default_url_options in test environment doesn't seem to work

I've put the following code into my config/environments/test.rb file:

config.action_mailer.default_url_options = { :host => "localhost:3000" }

however when I run my tests, all routes use http://test.host. I'm trying to work with an API that won't accept http://test.host as a valid callback URI, so I need to change this to properly receive the API response. Any idea why this isn't working? (I'm using RSpec, Guard, and Spork in my testing suite).

EDIT: Possibly relevant - this is being done inside of a controller spec.

EDIT2: It seems that it changes after a request is made via get, post, etc. Running the following code within the test:

Rails.logger.debug users_url
get 'http://google.com'
Rails.logger.debug users_url

would produce the following output:

http://localhost:3000/users
...get request related response here
http://google.com/users
like image 271
Nick Avatar asked Oct 22 '12 03:10

Nick


1 Answers

Rails.application.routes.default_url_options[:host]= 'localhost:3000'

In the developemnt.rb / test.rb, can be more concise as following:

Rails.application.configure do
  # ... other config ...

  routes.default_url_options[:host] = 'localhost:3000'
end
like image 59
Derek Fan Avatar answered Oct 17 '22 07:10

Derek Fan