ruby on rails - How can I do a "post :create" in RSpec when my route is nested? -
1) how can use "post :create" when route nested.
for example... works great rspec controller post :create top level resource, such post
"should success response on post create" post :create, params response.should be_success end
however, nested resource 'comment' nested under post... above throw following...
failure/error: post :create, params actioncontroller::urlgenerationerror: no route matches
and if tried
"should success response on post create" post :create, post_id: @post.id, params #@post defined , created above response.should be_success end
i odd error...
syntax error, unexpected '\n', expecting => (syntaxerror)
2) also, right code below testing successful response. however, since i've gone , created post via factorygirl... how can test @post.id equals 1 of id's being returned get: index json?
describe api::v1::postscontroller context 'post' before(:each) @post = factorygirl.create(:post) end context '#index' "should have successful response on index" :index, format: :json response.should be_success end end
when pass hash without braces ({}) has last argument method. syntax error because start doing pass "normal" argument afterwards. instead need like
post :create, params.merge(post_id: @post.id)
in terms of testing response, data generated stored in response.body
. load json , verify format in anyway wanted
Comments
Post a Comment