mardi 3 février 2015

Testing with subdomains

I am using this method of subdomains to access "shows" in my Rails project. In my controller tests, I set up a show with the subdomain "test":



class ShowsControllerTest < ActionController::TestCase
def setup
@show = Show.new(id: 1, name: 'My Show', user_id: 1, subdomain: 'test')
end

test "should do something"
get show_path @show
end
end


show_path is defined elsewhere:



def show_path(show)
root_url(subdomain: show.subdomain)
end


Unfortunately, any test with get show_path @show causes this error (line returns added for ease of reading):



ActionController::UrlGenerationError:
ActionController::UrlGenerationError:
No route matches {:action=>"http://test.test.host/", :controller=>"shows"}


As far as I can tell, the issue is the hostname that the testing environment is using, and I can find a lot of articles about testing with subdomains, but they all related specifically to capybara and cucumber (I am using Ruby's default testing setup) and I cannot find sufficient parallels to fix the issue I am running into.


Aucun commentaire:

Enregistrer un commentaire