Sha256: ceca0247f924e8ab42d84db51c2fdfbd19f32f4f601ae97599a0c5f819c00594

Contents?: true

Size: 1.44 KB

Versions: 11

Compression:

Stored size: 1.44 KB

Contents

require 'rest-core/test'

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

  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'}
    env    = {RC::REQUEST_PAYLOAD => format}

    app.call(env){ |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)
    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

11 entries across 11 versions & 1 rubygems

Version Path
rest-core-3.5.4 test/test_default_payload.rb
rest-core-3.5.3 test/test_default_payload.rb
rest-core-3.5.2 test/test_default_payload.rb
rest-core-3.5.1 test/test_default_payload.rb
rest-core-3.5.0 test/test_default_payload.rb
rest-core-3.4.1 test/test_default_payload.rb
rest-core-3.4.0 test/test_default_payload.rb
rest-core-3.3.3 test/test_default_payload.rb
rest-core-3.3.2 test/test_default_payload.rb
rest-core-3.3.1 test/test_default_payload.rb
rest-core-3.3.0 test/test_default_payload.rb