Skip to content

Commit cfcc630

Browse files
committed
🐛 Fix handle non-symbol keys for old Ruby
1 parent c4eebc6 commit cfcc630

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

.rubocop_gradual.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
[130, 3, 52, "Gemspec/DependencyVersion: Dependency version specification is required.", 3163430777],
3232
[131, 3, 48, "Gemspec/DependencyVersion: Dependency version specification is required.", 425065368]
3333
],
34-
"spec/oauth2/access_token_spec.rb:759866110": [
34+
"spec/oauth2/access_token_spec.rb:388877639": [
3535
[3, 1, 34, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/access_token*_spec.rb`.", 1972107547],
3636
[594, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
3737
[664, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],

lib/oauth2/access_token.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def refresh(params = {}, access_token_opts = {})
188188
# @return [Hash] a hash of AccessToken property values
189189
def to_hash
190190
hsh = {
191-
**params,
192191
access_token: token,
193192
refresh_token: refresh_token,
194193
expires_at: expires_at,
@@ -197,7 +196,13 @@ def to_hash
197196
param_name: options[:param_name],
198197
}
199198
hsh[:token_name] = options[:token_name] if options.key?(:token_name)
200-
hsh
199+
# TODO: Switch when dropping Ruby < 2.5 support
200+
# params.transform_keys(&:to_sym) # Ruby 2.5 only
201+
# Old Ruby transform_keys alternative:
202+
sheesh = @params.each_with_object({}) { |(k, v), memo|
203+
memo[k.to_sym] = v
204+
}
205+
sheesh.merge(hsh)
201206
end
202207

203208
# Make a request with the Access Token

spec/oauth2/access_token_spec.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828

2929
let(:hash) do
3030
{
31-
:access_token => token,
32-
:id_token => "confusing bug here",
33-
:refresh_token => "foobar",
34-
:expires_at => Time.now.to_i + 200,
35-
"foo" => "bar",
36-
:header_format => "Bearer %",
37-
:mode => :header,
38-
:param_name => "access_token",
31+
access_token: token,
32+
id_token: "confusing bug here",
33+
refresh_token: "foobar",
34+
expires_at: Time.now.to_i + 200,
35+
foo: "bar",
36+
header_format: "Bearer %",
37+
mode: :header,
38+
param_name: "access_token",
3939
}
4040
end
4141

@@ -749,13 +749,13 @@ def self.contains_token?(hash)
749749
describe "#to_hash" do
750750
it "return a hash equal to the hash used to initialize access token" do
751751
hash = {
752-
:access_token => token,
753-
:refresh_token => "foobar",
754-
:expires_at => Time.now.to_i + 200,
755-
:header_format => "Bearer %",
756-
:mode => :header,
757-
:param_name => "access_token",
758-
"foo" => "bar",
752+
access_token: token,
753+
refresh_token: "foobar",
754+
expires_at: Time.now.to_i + 200,
755+
header_format: "Bearer %",
756+
mode: :header,
757+
param_name: "access_token",
758+
foo: "bar",
759759
}
760760
access_token = described_class.from_hash(client, hash.clone)
761761
expect(access_token.to_hash).to eq(hash)
@@ -764,14 +764,14 @@ def self.contains_token?(hash)
764764
context "with token_name" do
765765
it "return a hash equal to the hash used to initialize access token" do
766766
hash = {
767-
:access_token => "",
768-
:refresh_token => "foobar",
769-
:expires_at => Time.now.to_i + 200,
770-
:header_format => "Bearer %",
771-
:mode => :header,
772-
:param_name => "access_token",
773-
:token_name => "banana_face",
774-
"foo" => "bar",
767+
access_token: "",
768+
refresh_token: "foobar",
769+
expires_at: Time.now.to_i + 200,
770+
header_format: "Bearer %",
771+
mode: :header,
772+
param_name: "access_token",
773+
token_name: "banana_face",
774+
foo: "bar",
775775
}
776776
access_token = described_class.from_hash(client, hash.clone)
777777
expect(access_token.to_hash).to eq(hash)

0 commit comments

Comments
 (0)