Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing nested routes with rspec

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
like image 940
recursive_acronym Avatar asked May 09 '11 00:05

recursive_acronym


2 Answers

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 :)

like image 135
recursive_acronym Avatar answered Nov 12 '22 01:11

recursive_acronym


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.

like image 40
HannesBenson Avatar answered Nov 12 '22 00:11

HannesBenson