Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm having trouble getting my rspec routing tests working with a subdomain constraint.

Specifically I have a route

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

and (among others) a test

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

If I remove the subdomain constraint this test passes, but with it it fails. I have to tell rspec to use the subdomain but I'm at a loss as to how

TIA

Andy

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
948 views
Welcome To Ask or Share your Answers For Others

1 Answer

I usually do:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...