2012-02-17 11 views
8

rspecルーティングテストでサブドメイン制約を使用するのに問題があります。私はサブドメインの制約を削除した場合rspecを使用してサブドメイン制約付きルートをテストする

は、具体的に、私はルート(とりわけ)

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

及び試験

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

を有し、この試験に合格するが、それには失敗します。私はサブドメインを使用するRSpecの指示する必要がありますが、私は私が通常行う方法

TIA

アンディ

答えて

25

へと途方に暮れてよ:

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 
+0

素晴らしい、それは動作しますが、感謝を。 .. – Andy

+0

私はこの情報がはっきりしていなかったことを覚えているし、それを得るためにいくつかの痛みがあった;) – apneadiving

+0

Crikey、これは既存のアプリケーションを変更している場合、多くの仕事のようです。 – toxaq

関連する問題