Sha256: 7d012ce447579de5fc0f2a0ebe4ecc46ab71d73535b7a2d9bba5326bec2ab28a

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require 'rest-core/test'

describe RC::DefaultPayload do
  app = RC::DefaultPayload.new(RC::Dry.new, {})

  should 'do nothing' do
    app.call({}){ |r| r[RC::REQUEST_PAYLOAD].should.eq({}) }
  end

  should 'merge payload' do
    app.instance_eval{@payload = {'pay' => 'load'}}

    app.call({}){ |r| r.should.eq({RC::REQUEST_PAYLOAD =>
      {'pay' => 'load'}}) }

    format = {'format' => 'json'}
    env    = {RC::REQUEST_PAYLOAD => format}

    app.call(env){ |r| r.should.eq({RC::REQUEST_PAYLOAD =>
      {'pay' => 'load'}.merge(format)})}
  end

  should 'accept non-hash payload' do
    u = RC::Universal.new(:log_method => false)
    env = {RC::REQUEST_PAYLOAD => 'payload'}
    u.request_full(env, u.dry)[RC::REQUEST_PAYLOAD].should.eq('payload')

    u.payload = 'default'
    u.request_full(env, u.dry)[RC::REQUEST_PAYLOAD].should.eq('payload')
    u.request_full({} , u.dry)[RC::REQUEST_PAYLOAD].should.eq('default')

    u = RC::Builder.client{use RC::DefaultPayload, 'maylord'}.new
    u.request_full({} , u.dry)[RC::REQUEST_PAYLOAD].should.eq('maylord')
    u.request_full(env, u.dry)[RC::REQUEST_PAYLOAD].should.eq('payload')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-2.0.4 test/test_payload.rb
rest-core-2.0.3 test/test_payload.rb
rest-core-2.0.2 test/test_payload.rb
rest-core-2.0.1 test/test_payload.rb
rest-core-2.0.0 test/test_payload.rb