From 2bcdfc23c730751ab7253c29adc5817e98f770b8 Mon Sep 17 00:00:00 2001 From: Tyler Rick Date: Thu, 9 Apr 2020 17:58:18 -0700 Subject: [PATCH] Allow strings or symbols as option keys Also use inspect if there is an error so that you can see whether the invalid key was a string or a symbol. It was confusing to pass {'author' => 'Name'} and get the error "Invalid param: author" --- lib/akismet/client.rb | 4 ++-- test/client_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/akismet/client.rb b/lib/akismet/client.rb index 511619b..afe08f3 100644 --- a/lib/akismet/client.rb +++ b/lib/akismet/client.rb @@ -286,14 +286,14 @@ def invoke_comment_method(method_name, user_ip, user_agent, params = {}) for key in env.keys if PARAM_TO_API_PARAM.value?(key.to_sym) - raise ArgumentError, "Environment variable '#{ key }' conflicts with built-in API parameter" + raise ArgumentError, "Environment variable #{ key.inspect } conflicts with built-in API parameter" end end params = params.each_with_object({}) do |(name, value), api_params| next if name == :env - api_name = PARAM_TO_API_PARAM[name] || raise(ArgumentError, "Invalid param: #{ name }") + api_name = PARAM_TO_API_PARAM[name.to_sym] || raise(ArgumentError, "Invalid param: #{ name.inspect }") api_params[api_name] = value end diff --git a/test/client_test.rb b/test/client_test.rb index e830914..ff7c640 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -160,4 +160,11 @@ def test_invalid_param_raises @client.check 'ip', 'ua', invalid_param: 'invalid' end end + + def test_params_can_be_symbols_or_keys + @client.check 'ip', 'ua', { author: 'Name' } + @client.check 'ip', 'ua', {'author' => 'Name'} + @client.check 'ip', 'ua', {env: { a: 1, b: 1 }} + @client.check 'ip', 'ua', {env: {'a' => 1, 'b' => 1}} + end end