Skip to content

Commit c1652e3

Browse files
committed
Fix handling snake_case form params
1 parent 3f3f7a8 commit c1652e3

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

lib/line/bot/v2/utils.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ def self.deep_to_hash(object)
2121
if object.is_a?(Array)
2222
object.map { |item| deep_to_hash(item) }
2323
elsif object.is_a?(Hash)
24-
object.
25-
transform_keys { |k| camelize(k) }.
26-
transform_values { |v| deep_to_hash(v) }
24+
object.transform_keys(&:to_sym).transform_values { |v| deep_to_hash(v) }
2725
elsif object.instance_variables.empty?
2826
object
2927
else
3028
object.instance_variables.each_with_object({}) do |var, hash|
3129
value = object.instance_variable_get(var)
32-
key = camelize(var.to_s.delete('@')).to_sym
30+
key = var.to_s.delete('@').to_sym
3331
hash[key] = deep_to_hash(value)
3432
end
3533
end

spec/line/bot/v2/misc_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
it "doesn't require bearer token" do
232232
stub_request(:post, "https://api.line.me/v2/oauth/accessToken")
233233
.with(
234-
body: { "clientId" => "test-client-id", "clientSecret" => "test-client-secret", "grantType" => "client_credentials" }
234+
body: { client_id: "test-client-id", client_secret: "test-client-secret", grant_type: "client_credentials" }
235235
)
236236
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
237237

spec/line/bot/v2/utils_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def initialize(name)
7171
end
7272

7373
describe '.deep_to_hash' do
74-
it 'converts an object with instance variables to a hash with camelCase keys' do
74+
it 'converts an object with instance variables to a hash' do
7575
input = TestObject.new('John', 'Doe')
76-
expected_output = { firstName: 'John', lastName: 'Doe' }
76+
expected_output = { first_name: 'John', last_name: 'Doe' }
7777
expect(Line::Bot::V2::Utils.deep_to_hash(input)).to eq(expected_output)
7878
end
7979

0 commit comments

Comments
 (0)