Sha256: d09733aa4bd66e2a1627dbe414751bcae6abe0de20a5c85fbb8a39462a877d19

Contents?: true

Size: 880 Bytes

Versions: 12

Compression:

Stored size: 880 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::Middleware::ParseJSONBody do
  def app
    inner_app = ->(env) { [200,{},[env['rack.request.form_input']]] }
    Hyperdrive::Middleware::ParseJSONBody.new(inner_app)
  end

  before do
    @json = '{"ok":"player","nested":{"key":"value"}}'
    @headers = { 'CONTENT_TYPE' => 'application/json' }
  end

  it "parses json input" do
    post '/', @json, @headers
    last_response.body.must_equal "ok=player&nested=%7B%22key%22%3D%3E%22value%22%7D"
  end

  it "overrides values in the query string with those in the json input" do
    post '/?ok=playa', @json, @headers
    last_response.body.must_equal "ok=player&nested=%7B%22key%22%3D%3E%22value%22%7D"
  end

  it "throws an error if the json can't be parsed" do
    -> { post '/', "{ badjson }", @headers }.must_raise Hyperdrive::Errors::JSONParseError
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.24 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.23 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.22 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.21 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.20 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.19 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.18 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.17 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.16 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.15 spec/hyperdrive/middleware/parse_json_body_spec.rb
hyperdrive-0.0.14 spec/hyperdrive/middleware/parse_json_body_spec.rb