Sha256: 57878409ef9a5ea17c1db2f7bab78823a468f6df3444d5fbe51c5d18019627f5

Contents?: true

Size: 913 Bytes

Versions: 4

Compression:

Stored size: 913 Bytes

Contents

require 'rest-core/test'

describe RC::JsonRequest do
  app = RC::JsonRequest.new(RC::Dry.new, true)
  env = {RC::REQUEST_HEADERS => {}}
  request_params = {
    'key' => 'value',
    'array' => [1, 2, 3],
    'nested' => {'k' => 'v', 'a' => [4, 5, 6]}
  }

  would 'encode payload as json' do
    e = env.merge(RC::REQUEST_METHOD  => :post,
                  RC::REQUEST_PAYLOAD => request_params)

    app.call(e){ |res|
      res.should.eq(
        RC::REQUEST_METHOD  => :post,
        RC::REQUEST_HEADERS => {'Content-Type' => 'application/json'},
        RC::REQUEST_PAYLOAD => RC::Json.encode(request_params))}
  end

  would 'do nothing if payload is empty' do
    e = env.merge(RC::REQUEST_PAYLOAD => {})
    app.call(e){ |res| res.should.eq e }
  end

  would 'do nothing if json_request is false' do
    a = RC::JsonRequest.new(RC::Dry.new, false)
    a.call(env){ |res| res.should.eq env }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-core-3.3.3 test/test_json_request.rb
rest-core-3.3.2 test/test_json_request.rb
rest-core-3.3.1 test/test_json_request.rb
rest-core-3.3.0 test/test_json_request.rb