I'm trying to test routes with rspec. The following gives an error of "Expected block to return true value".
I'm not sure what I am missing. Through a browser I can post to this url and it is successful.
Any ideas? Thanks!
Routes
resources :forum_topics do
resources :forum_sub_topics
end
Test:
it "recognizes and generates nested #create" do
{ :post => "/forum_topics/1/forum_sub_topics" }.should route_to(:controller => "forum_sub_topics", :action => "create", :forum_topic_id => 1)
end
Well nobody officially answered my question, so I will :)
{ :post => "/forum_topics/1/forum_sub_topics" }.should route_to(:controller => "forum_sub_topics", :action => "create", :forum_topic_id => 1)
It comes down to :forum_topic_id => 1 not being equal to :forum_topic_id => "1" Perhaps my PHP days have crept up to bite me. Strings and Integers :)
I know it comes down to the same thing but if you'd like to shorten your code you could also do:
{ :post => "/forum_topics/1/forum_sub_topics" }.should route_to("forum_sub_topics#create", :forum_topic_id => 1)
I find it easier to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With