I'm trying to learn rails 4.1
from rails 4
in action book, I've got to chapter 13, in this chapter defined API for JSON and XML
.
It defined a controller like this :
class Api::V1::ProjectsController < Api::V1::BaseController
def index
respond_with(Project.for(current_user).all)
end
def create
project = Project.new project_params
if project.save
respond_with(project, :location => api_v1_project_path(project))
else
respond_with(errors: project.errors.messages)
end
end
private
def project_params
params.require(:project).permit(:name)
end
end
And a rspec test like this :
it "unsuccessful JSON" do
post "#{url}.json", :token => token, :project => {}
expect(last_response.status).to eql(422)
errors = {"errors" => { "name" => ["can't be blank"]}}.to_json
expect(last_response.body).to eql(errors)
end
when I run the test, I get these results :
ActionController::ParameterMissing: param is missing or the value is empty: project
I know, it's because of strong parameters.