Sha256: 4a3e9380f15d0ee6693da8ee80cef1ea2d4d8b999d5d158440e26b7f13e3ca8b

Contents?: true

Size: 910 Bytes

Versions: 3

Compression:

Stored size: 910 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::Middleware::Charset do
  def app
    inner_app = ->(env) { [200, {}, [env['hyperdrive.params']]] }
    Hyperdrive::Middleware::Charset.new(inner_app)
  end

  before do
    @env = default_rack_env(default_resource).merge('hyperdrive.params' => {})
    @env.merge!('REQUEST_METHOD' => 'POST')
    @params = { id: '1001', name: 'John Connor'.encode('ASCII-8BIT') }
  end

  it "will enforce accept-charset encoding on param values" do
    post '/', @params, @env.merge('hyperdrive.params' => @params)
    last_response.body.must_equal "{:id=>\"1001\", :name=>\"John Connor\"}"
  end

  it "will enforce a default charset if accept-charset is not present" do
    @env.delete('HTTP_ACCEPT_CHARSET')
    post '/', @params, @env.merge('hyperdrive.params' => @params)
    last_response.body.must_equal "{:id=>\"1001\", :name=>\"John Connor\"}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 spec/hyperdrive/middleware/charset_spec.rb
hyperdrive-0.0.24 spec/hyperdrive/middleware/charset_spec.rb
hyperdrive-0.0.23 spec/hyperdrive/middleware/charset_spec.rb