Forum: Ruby on Rails How can I test my controller via rspec for something other than response.should be_success?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
08ffe40f63ae25ae792b1c2c61498168?d=identicon&s=25 Chris P. (chris_p)
on 2014-06-09 20:58
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 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)

    context '#index' do
      it "should have a successful response on get index" do
        get :index, format: :json
        response.should be_success


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

however, for a nested resource like 'comment' which is nested under
post... the above would throw the following...

    Failure/Error: post :create, params
       No route matches

and if I tried

          it "should get a success response on post create" do
        post :create, post_id:, params #@post is defined and
created above
        response.should be_success

I get this odd error...

    syntax error, unexpected '\n', expecting => (SyntaxError)
dasibre (Guest)
on 2014-06-10 18:56
(Received via mailing list)
This topic is locked and can not be replied to.