diff --git a/.travis.yml b/.travis.yml index bd2e1eb..be08722 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ rvm: - 2.7 script: bundle exec rake env: - - RAILS_VERSION=6.0.3.1 + - RAILS_VERSION=6.0.3.5 - RAILS_VERSION=5.2.0 services: - mysql diff --git a/Gemfile b/Gemfile index 5e12aeb..152273a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" gemspec -DEFAULT_RAILS_VERSION = '6.0.3' +DEFAULT_RAILS_VERSION = '6.0.3.5' ENV['RAILS_VERSION'] ||= DEFAULT_RAILS_VERSION if ENV['RAILS_VERSION'] == '4.2.10' diff --git a/README.md b/README.md index 9cb788f..4752e90 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,8 @@ pp kv.mdel(["foo", "bar"]) # nil ``` +Note that due to MySQL's default collation, KV keys are case-insensitive. + ### GitHub::SQL ```ruby diff --git a/lib/github/ds/version.rb b/lib/github/ds/version.rb index 32aa81f..9e9dd8c 100644 --- a/lib/github/ds/version.rb +++ b/lib/github/ds/version.rb @@ -1,5 +1,5 @@ module GitHub module DS - VERSION = "0.5.0" + VERSION = "0.5.1" end end diff --git a/lib/github/kv.rb b/lib/github/kv.rb index 9777a9a..20ff5f6 100644 --- a/lib/github/kv.rb +++ b/lib/github/kv.rb @@ -129,7 +129,8 @@ def mget(keys) SELECT `key`, value FROM #{@table_name} WHERE `key` IN :keys AND (`expires_at` IS NULL OR `expires_at` > :now) SQL - keys.map { |key| kvs[key] } + kvs.keys.each { |key| kvs[key.downcase] = kvs[key] } + keys.map { |key| kvs[key.downcase] } } end diff --git a/test/github/kv_test.rb b/test/github/kv_test.rb index 2be27ad..cf5d661 100644 --- a/test/github/kv_test.rb +++ b/test/github/kv_test.rb @@ -61,6 +61,18 @@ def test_mget_and_mset assert_equal ["2", "1"], @kv.mget(["b", "a"]).value! end + def test_get_and_set_case_insensitive + assert_nil @kv.get("foo").value! + + @kv.set "foo", "lowercase" + assert_equal "lowercase", @kv.get("foo").value! + assert_equal "lowercase", @kv.get("FOO").value! + + @kv.set "FOO", "uppercase" + assert_equal "uppercase", @kv.get("foo").value! + assert_equal "uppercase", @kv.get("FOO").value! + end + def test_get_failure ActiveRecord::Base.connection.stubs(:select_all).raises(Errno::ECONNRESET) diff --git a/test/github/sql_test.rb b/test/github/sql_test.rb index 12e72a7..2d0479e 100644 --- a/test/github/sql_test.rb +++ b/test/github/sql_test.rb @@ -11,8 +11,8 @@ class GitHub::SQLTest < Minitest::Test [DateTime.now.utc, "'1970-01-01 00:00:00'"], [Time.now.utc, "'1970-01-01 00:00:00'"], [Time.now.utc.to_date, "'1970-01-01'"], - [true, "1", {"5.2.0" => "TRUE", "6.0.3.1" => "TRUE"}], - [false, "0", {"5.2.0" => "FALSE", "6.0.3.1" => "FALSE"}], + [true, "1", {"5.2.0" => "TRUE", "6.0.3.5" => "TRUE"}], + [false, "0", {"5.2.0" => "FALSE", "6.0.3.5" => "FALSE"}], [17, "17"], [1.7, "1.7"], ["corge", "'corge'"],