Sunday, September 5, 2010

[Rails] How to use Rspec to test Comments?

Hello,
My comments are currently routed inside of my articles, so my routes
file looks like the following:

resources :articles do
resources :comments
end

I am trying to write an Rspec test that tests whether or not guests
(non-signed-in users) can comment on my articles with the following
inside of my comments controller test:

it "should deny access to 'create'" do
post :create
response.should redirect_to(signin_path)
end

I get an error when running the test:
No route matches {:controller=>"comments", :action=>"create"}


I think this is because it is trying to test a route on
localhost/comments/create, but I need the test to take place within
localhost/articles/id/comments/create

Now, I have the following variable in the before(:each) part of my test
file:
@article = Factory(:article, :user => @user, :title => "Article
Title", :content => "Article Content")

I want to test if a guest can create a comment in @article, but I am
unsure of how to do that.
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate