Sha256: 397d4332868f184d6ce63b99eb0fd0bd472cfca8f5c622b4c6826ca97a1ef743

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

describe FaradayMiddleware::ActiveSupport::ParseJson do
  let(:response) { {:a => 1, :b => 2} }
  let(:json) { ::ActiveSupport::JSON.encode(response) }

  def connection(options={})
    Faraday.new do |builder|
      builder.response :active_support_json, options
      builder.adapter :test do |stub|
        stub.get('/') do
          [200, {}, json]
        end
      end
    end
  end

  it 'should parse the response body' do
    connection.get('/').body.should == {'a'=>1, 'b'=>2}
  end

  if ::ActiveSupport::VERSION::MAJOR < 4
    it 'should delegate options given by builder' do
      connection(:symbolize_keys => true).get('/').body.should == response
    end
  end
end

describe FaradayMiddleware::ActiveSupport::EncodeJson do
  let(:request) { {:a => 1, :b => 2} }
  let(:json) { ::ActiveSupport::JSON.encode(request) }

  def connection
    Faraday.new do |builder|
      builder.request :active_support_json
      builder.adapter :test do |stub|
        stub.post('/update', json) do
          [200, {}, json]
        end
      end
    end
  end

  it 'should parse the request body' do
    resp = connection.post('/update', request)
    resp.body.should == json
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faraday_middleware-active_support_json-0.0.3 spec/faraday_middleware/active_support_json_spec.rb