Question

Je vais avoir du mal à obtenir mes tests de routage rspec de travail avec une contrainte de sous-domaine.

Plus précisément, j'ai une route

constraints :subdomain => "api" do
  resources :sign_ups, :only => [:create]
end

et (entre autres) un test

it "does allow creation of sign ups" do
  {:post => "/sign_ups"}.should route_to(
    :controller => "sign_ups",
    :action => "create",
  )
end

Si je supprime la contrainte subdomain ce test passe, mais il échoue. Je dois dire rspec d'utiliser le sous-domaine, mais je suis à une perte sur la façon

TIA

Andy

Était-ce utile?

La solution

Je fais habituellement:

let(:url)     { "http://api.domain.com"     }
let(:bad_url) { "http://bad_url.domain.com" }

it "does allow creation of sign ups" do
  {:post => "#{url}/sign_ups"}.should route_to(
   :controller => "sign_ups",
   :action => "create",
  )
end

it "should not route" do
  {:post => "#{bad_url}/sign_ups"}.should_not route_to(
   :controller => "sign_ups",
   :action => "create",
  )
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top