Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mlangenberg/3529 to your computer and use it in GitHub Desktop.
Save mlangenberg/3529 to your computer and use it in GitHub Desktop.
From ee6bf8c0144a5d2d3958ea280ba0154f3bee05ee Mon Sep 17 00:00:00 2001
From: Matthijs Langenberg <mlangenberg@gmail.com>
Date: Thu, 31 Jul 2008 23:27:50 +0200
Subject: [PATCH] Rewrote the spec for unparsable JSON and added a spec for unparsable XML.
---
spec/public/request/request_spec.rb | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/spec/public/request/request_spec.rb b/spec/public/request/request_spec.rb
index a64e55f..efb4989 100644
--- a/spec/public/request/request_spec.rb
+++ b/spec/public/request/request_spec.rb
@@ -26,11 +26,6 @@ describe Merb::Request, "#method" do
end
end
end
-
- it "should not try to parse the request body as JSON on GET" do
- request = fake_request({:request_method => "GET", :content_type => "application/json"}, :req => "")
- lambda { request.params }.should_not raise_error(JSON::ParserError)
- end
it "should default to POST if the _method is not defined" do
request = fake_request({:request_method => "POST"}, :post_body => "_method=zed")
@@ -74,6 +69,12 @@ describe Merb::Request, " query and body params" do
request.params.should == {"foo" => "bar"}
end
+ it "should return an empty hash when JSON is not parsable" do
+ request = fake_request({:content_type => "application/json"}, :req => "")
+ lambda { request.params }.should_not raise_error(JSON::ParserError)
+ request.params.should == {}
+ end
+
it "should populated the inflated_object parameter if JSON params do not inflate to a hash" do
request = fake_request({:content_type => "application/json"}, :req => %{["foo", "bar"]})
request.stub!(:route_params).and_return({})
@@ -85,7 +86,13 @@ describe Merb::Request, " query and body params" do
request = fake_request({:content_type => "application/xml"}, :req => %{<foo bar="baz"><baz/></foo>})
request.stub!(:route_params).and_return({})
request.params.should == {"foo" => {"baz" => nil, "bar" => "baz"}}
- end
+ end
+
+ it "should return an empty hash when XML is not parsable" do
+ request = fake_request({:content_type => "application/xml"}, :req => '')
+ lambda { request.params }.should_not raise_error
+ request.params.should == {}
+ end
end
--
1.5.5.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment