Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: RuboCop Style/MultipleComparison #923

Merged
merged 4 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
iMacTia marked this conversation as resolved.
Show resolved Hide resolved
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