currently i am using this endpoint to create a new article
http://localhost:3000/api/v1/post/1/articles
in my test with rspec
i am doing this
RSpec.describe 'Api::V1::Articles', type: :request do
...
describe 'POST /create' do
context "valid" do
let!(:articles_params) { {
name: "art",
post_id: @post.id
} }
it 'creates a new article' do
expect { post :"/api/v1/posts/#{post.id}/articles" , params: articles_params }.to change(Article,:count).by(1)
end
end
end
i am getting this error:
ActionController::ParameterMissing: param is missing or the value is empty: article
CodePudding user response:
The error is because :/api/v1/create
isn’t a valid symbol.
For request paths, you should provide them as strings instead, e.g.
expect { post "/api/v1/create", params: articles_params }
.to change(Article, :count).by(1)