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


  1. 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)

See this blog

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs