Chris P.
2014-Jun-09 18:58 UTC
How can I test my controller via rspec for something other than response.should be_success?
1) Right now this is just testing a successful response. However, since
I've gone and created a Post via FactoryGirl... how can I test the
@post.id equals one of the id's being returned by the get: index json?
describe Api::V1::PostsController do
context 'Post' do
before(:each) do
@post = FactoryGirl.create(:post)
end
context '#index' do
it "should have a successful response on get index" do
get :index, format: :json
response.should be_success
end
end
EDIT:
2) How can I use "post :create" when my route is nested.
For example... this works great as an rspec controller post :create with
a top level resource, such as post
it "should get a success response on post create" do
post :create, params
response.should be_success
end
however, for a nested resource like 'comment' which is nested under
post... the above would throw the following...
Failure/Error: post :create, params
ActionController::UrlGenerationError:
No route matches
and if I tried
it "should get a success response on post create" do
post :create, post_id: @post.id, params #@post is defined and
created above
response.should be_success
end
I get this odd error...
syntax error, unexpected '\n', expecting => (SyntaxError)
--
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 unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/1362a2e750554081fd57048567852e68%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
