Handle invalid JSON on PUT requests

This commit is contained in:
2012-10-06 18:44:21 +02:00
parent 84e69376fd
commit acf2003487
2 changed files with 45 additions and 5 deletions

View File

@@ -173,6 +173,32 @@ describe "App with Riak backend" do
last_response.content_type.must_equal "application/json; charset=UTF-8"
end
end
context "invalid JSON" do
context "empty body" do
before do
header "Content-Type", "application/json"
put "/jimmy/documents/jason", ""
end
it "saves an empty JSON object" do
last_response.status.must_equal 200
data_bucket.get("jimmy:documents:jason").data.must_be_kind_of Hash
data_bucket.get("jimmy:documents:jason").data.must_equal({})
end
end
context "unparsable JSON" do
before do
header "Content-Type", "application/json"
put "/jimmy/documents/jason", "foo"
end
it "returns a 422" do
last_response.status.must_equal 422
end
end
end
end
describe "DELETE" do