Sha256: d2942952e2800181a14995b6c7fcac6a01c1d53737814f5527008a7275766126

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 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

  it 'should delegate options given by builder' do
    connection(:symbolize_keys => true).get('/').body.should == response
  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

2 entries across 2 versions & 1 rubygems

Version Path
faraday_middleware-active_support_json-0.0.2 spec/faraday_middleware/active_support_json_spec.rb
faraday_middleware-active_support_json-0.0.1 spec/faraday_middleware/active_support_json_spec.rb