Sha256: 3109add9f64b349c6db2e30452b9aaa2835e0a54a58aa2ff6b9a4ec6152c07f3

Contents?: true

Size: 934 Bytes

Versions: 8

Compression:

Stored size: 934 Bytes

Contents

require 'rails_helper'

describe LHC::Request do
  context 'encode body' do
    let(:encoded_data) { data.to_json }

    before do
      stub_request(:post, "http://datastore/q")
        .with(body: encoded_data)
        .to_return(status: 200)
    end

    context 'hash' do
      let(:data) { { name: 'Steve' } }

      it 'encodes the request body to the given format' do
        LHC.post('http://datastore/q', body: data)
      end

      it 'does not encode the request body if it is already a string' do
        LHC.post('http://datastore/q', body: encoded_data)
      end
    end

    context 'array' do
      let(:data) { [{ name: 'Steve' }] }

      it 'encodes the request body to the given format' do
        LHC.post('http://datastore/q', body: data)
      end

      it 'does not encode the request body if it is already a string' do
        LHC.post('http://datastore/q', body: encoded_data)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lhc-10.1.2 spec/request/body_spec.rb
lhc-10.1.1 spec/request/body_spec.rb
lhc-10.1.0 spec/request/body_spec.rb
lhc-10.0.2 spec/request/body_spec.rb
lhc-9.4.4 spec/request/body_spec.rb
lhc-10.0.1 spec/request/body_spec.rb
lhc-10.0.0 spec/request/body_spec.rb
lhc-9.4.3 spec/request/body_spec.rb