Frage

Ich habe Probleme, meine RSPEC -Routing -Tests mit einer Subdomain -Einschränkung zu machen.

Insbesondere habe ich eine Route

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

und (unter anderem) ein Test

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

Wenn ich die Subdomain -Einschränkung entferne, wird dieser Test bestehen, aber damit fehlschlägt sie. Ich muss RSPEC sagen, dass sie das Subdomain verwenden sollen, aber ich bin ratlos, wie

Tia

Andy

War es hilfreich?

Lösung

Normalerweise mache ich:

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top