How do I change the default “www.example.com” domain for testing in rails?

后端 未结 10 668
囚心锁ツ
囚心锁ツ 2020-11-30 04:17

I have a rails application which acts differently depending on what domain it\'s accessed at (for example www.myapp.com will invoke differently to user.myapp.com). In produc

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 05:04

    I tried many variations of @request.host, host!, and post path, args, {'SERVER_NAME' => my_secret_domain} without success, both as controller tests and feature tests. Very aggravating, as so many others reported success with those approaches.

    The solution for me was:

    request.headers["SERVER_NAME"] = my_secret_domain
    post path, args
    

    I'm running ruby 2.1.5p273, rspec 3.1.7 and Rails 4.2.0

提交回复
热议问题