Sha256: 90b4b77168ced1246e8b7248936f346e67dd0ee11b830eb627aa99a34b51239e

Contents?: true

Size: 1.13 KB

Versions: 117

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'rack/utils'

RSpec.describe Faraday::FlatParamsEncoder do
  it_behaves_like 'a params encoder'

  it 'decodes arrays' do
    query = 'a=one&a=two&a=three'
    expected = { 'a' => %w[one two three] }
    expect(subject.decode(query)).to eq(expected)
  end

  it 'decodes boolean values' do
    query = 'a=true&b=false'
    expected = { 'a' => 'true', 'b' => 'false' }
    expect(subject.decode(query)).to eq(expected)
  end

  it 'encodes boolean values' do
    params = { a: true, b: false }
    expect(subject.encode(params)).to eq('a=true&b=false')
  end

  it 'encodes boolean values in array' do
    params = { a: [true, false] }
    expect(subject.encode(params)).to eq('a=true&a=false')
  end

  it 'encodes empty array in hash' do
    params = { a: [] }
    expect(subject.encode(params)).to eq('a=')
  end

  it 'encodes unsorted when asked' do
    params = { b: false, a: true }
    expect(subject.encode(params)).to eq('a=true&b=false')
    Faraday::FlatParamsEncoder.sort_params = false
    expect(subject.encode(params)).to eq('b=false&a=true')
    Faraday::FlatParamsEncoder.sort_params = true
  end
end

Version data entries

117 entries across 105 versions & 12 rubygems

Version Path
faraday-1.7.2 spec/faraday/params_encoders/flat_spec.rb
faraday-1.7.1 spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/faraday-1.7.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/spec/faraday/params_encoders/flat_spec.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/spec/faraday/params_encoders/flat_spec.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/spec/faraday/params_encoders/flat_spec.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/spec/faraday/params_encoders/flat_spec.rb
faraday-1.7.0 spec/faraday/params_encoders/flat_spec.rb
faraday-1.6.0 spec/faraday/params_encoders/flat_spec.rb
faraday-1.5.1 spec/faraday/params_encoders/flat_spec.rb
faraday-1.5.0 spec/faraday/params_encoders/flat_spec.rb
faraday-1.4.3 spec/faraday/params_encoders/flat_spec.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.1.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/params_encoders/flat_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/faraday-1.4.2/spec/faraday/params_encoders/flat_spec.rb