зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-07 19:35:52 +03:00
Encode arrays as json in requests
Этот коммит содержится в:
@@ -34,8 +34,9 @@ module Telegram
|
|||||||
|
|
||||||
# Encodes nested hashes as json.
|
# Encodes nested hashes as json.
|
||||||
def prepare_body(body)
|
def prepare_body(body)
|
||||||
|
body = body.dup
|
||||||
body.each do |k, val|
|
body.each do |k, val|
|
||||||
body[k] = val.to_json if val.is_a?(Hash)
|
body[k] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ RSpec.describe Telegram::Bot::Client do
|
|||||||
subject { described_class.prepare_body(input) }
|
subject { described_class.prepare_body(input) }
|
||||||
|
|
||||||
context 'when plain hash is given' do
|
context 'when plain hash is given' do
|
||||||
let(:input) { {a: 1, b: '2', c: [1, 2]} }
|
let(:input) { {a: 1, b: '2', c: nil} }
|
||||||
it { should eq input }
|
it { should eq input }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ RSpec.describe Telegram::Bot::Client do
|
|||||||
|
|
||||||
it 'encodes nested hashes to json' do
|
it 'encodes nested hashes to json' do
|
||||||
expected = input.dup
|
expected = input.dup
|
||||||
%i(d e).each { |x| expected[x] = expected[x].to_json }
|
%i(c d e).each { |x| expected[x] = expected[x].to_json }
|
||||||
should eq expected
|
should eq expected
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user