Sha256: 977eb55f13baf19392dffa6138705e0d1c1bf54190e9ab4987b291b0a3a16234

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

require 'rest-core/test'

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

  before do
    app.instance_eval{@payload = {}}
  end

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

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

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

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

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

  would 'also merge the very default payload' do
    a = RC::DefaultPayload.new(RC::Dry.new, 'a' => 'b')
    a.call('payload' => {'b' => 'c'},
           RC::REQUEST_PAYLOAD => {'c' => 'd'}) do |r|
      r[RC::REQUEST_PAYLOAD].should.eq 'a' => 'b', 'b' => 'c', 'c' => 'd'
    end
  end

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

    u.payload = 'default'
    u.request_full( e, 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( e, u.dry)[RC::REQUEST_PAYLOAD].should.eq('payload')
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rest-core-3.6.0 test/test_default_payload.rb
rest-core-3.5.92 test/test_default_payload.rb
rest-core-3.5.91 test/test_default_payload.rb
rest-core-3.5.9 test/test_default_payload.rb
rest-core-3.5.8 test/test_default_payload.rb
rest-core-3.5.7 test/test_default_payload.rb
rest-core-3.5.6 test/test_default_payload.rb
rest-core-3.5.5 test/test_default_payload.rb