Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rack::Client::Parser's not working as expected #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rack/client/parser/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Parser
class JSON < Parser::Base

content_type 'application', 'json'
content_type 'application', 'json', 'charset=utf-8'

def encode(input)
output = StringIO.new
Expand Down Expand Up @@ -48,7 +49,7 @@ def decode(body)
end
end

Yaml = YAML
Json = JSON
end
end
end
18 changes: 18 additions & 0 deletions spec/parser/json_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'

describe Rack::Client::Parser::JSON do
it "should be returned for application/json" do
Rack::Client::Parser::Base.lookup("application/json").should == Rack::Client::Parser::JSON
end

it "should be returned for application/json;charset=utf-8" do
Rack::Client::Parser::Base.lookup("application/json;charset=utf-8").should == Rack::Client::Parser::JSON
end

sync_handler_contexts(Rack::Client::Parser) do
it 'parses json and makes it ruby' do
request { get('/json/json') }
response { body.should == {"key" => "value"} }
end
end
end
10 changes: 10 additions & 0 deletions spec/spec_apps/json.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'sinatra/base'

class Json < Sinatra::Base
get '/json' do
content_type :json
'{"key":"value"}'
end
end

run Json