Skip to content

Commit

Permalink
Chore: RuboCop Style/MultipleComparison (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drenmi authored and iMacTia committed Mar 11, 2019
1 parent 224dd98 commit 8869836
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Expand Up @@ -47,8 +47,3 @@ Style/Documentation:
- 'lib/faraday/response/logger.rb'
- 'lib/faraday/response/raise_error.rb'
- 'lib/faraday/utils.rb'

# Offense count: 1
Style/MultipleComparison:
Exclude:
- 'lib/faraday/encoders/flat_params_encoder.rb'
1 change: 0 additions & 1 deletion lib/faraday/encoders/flat_params_encoder.rb
Expand Up @@ -29,7 +29,6 @@ def self.encode(params)
buffer = +''
params.each do |key, value|
encoded_key = escape(key)
value = value.to_s if value == true || value == false
if value.nil?
buffer << "#{encoded_key}&"
elsif value.is_a?(Array)
Expand Down
16 changes: 16 additions & 0 deletions spec/faraday/params_encoders/flat_spec.rb
Expand Up @@ -10,4 +10,20 @@
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
end
10 changes: 10 additions & 0 deletions spec/faraday/params_encoders/nested_spec.rb
Expand Up @@ -84,6 +84,16 @@
expect(result).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%5B%5D=true&a%5B%5D=false')
end

shared_examples 'a wrong decoding' do
it do
expect { subject.decode(query) }.to raise_error(TypeError) do |e|
Expand Down

0 comments on commit 8869836

Please sign in to comment.