Fix handling of content-types that also contain the encoding
This commit is contained in:
parent
d88ad2eb20
commit
d4d02e3e77
@ -36,7 +36,7 @@ module RemoteStorage
|
||||
object = data_bucket.get("#{user}:#{category}:#{key}")
|
||||
headers["Content-Type"] = object.content_type
|
||||
headers["Last-Modified"] = object.last_modified.to_s(:rfc822)
|
||||
case object.content_type
|
||||
case object.content_type[/^[^;\s]+/]
|
||||
when "application/json"
|
||||
return object.data.to_json
|
||||
else
|
||||
@ -62,7 +62,7 @@ module RemoteStorage
|
||||
def put_data(user, category, key, data, content_type=nil)
|
||||
object = data_bucket.new("#{user}:#{category}:#{key}")
|
||||
object.content_type = content_type || "text/plain; charset=utf-8"
|
||||
data = JSON.parse(data) if content_type == "application/json"
|
||||
data = JSON.parse(data) if content_type[/^[^;\s]+/] == "application/json"
|
||||
if serializer_for(object.content_type)
|
||||
object.data = data
|
||||
else
|
||||
|
@ -148,6 +148,31 @@ describe "App with Riak backend" do
|
||||
last_response.content_type.must_equal "text/magic"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with content type containing the encoding" do
|
||||
before do
|
||||
header "Content-Type", "application/json; charset=UTF-8"
|
||||
put "/jimmy/documents/jason", '{"foo": "bar", "unhosted": 1}'
|
||||
end
|
||||
|
||||
it "saves the value (as JSON)" 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({"foo" => "bar", "unhosted" => 1})
|
||||
end
|
||||
|
||||
it "uses the requested content type" do
|
||||
data_bucket.get("jimmy:documents:jason").content_type.must_equal "application/json; charset=UTF-8"
|
||||
end
|
||||
|
||||
it "delivers the data correctly" do
|
||||
header "Authorization", "Bearer 123"
|
||||
get "/jimmy/documents/jason"
|
||||
|
||||
last_response.body.must_equal '{"foo":"bar","unhosted":1}'
|
||||
last_response.content_type.must_equal "application/json; charset=UTF-8"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user