From 17a7d35e0cab371b560aaa0c5ea2a9959f673463 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 9 Jun 2020 15:13:04 +0200 Subject: [PATCH] Test against ruby 2.7 --- .travis.yml | 1 + lib/redis/namespace.rb | 24 +++++++++++++++++++++--- redis-namespace.gemspec | 2 +- spec/redis_spec.rb | 4 ++-- spec/spec_helper.rb | 4 ++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8bd7ec4..2358aa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ rvm: - 2.4 - 2.5 - 2.6 + - 2.7 - ruby-head - jruby-18mode - jruby-19mode diff --git a/lib/redis/namespace.rb b/lib/redis/namespace.rb index 56295fa..c7c169c 100644 --- a/lib/redis/namespace.rb +++ b/lib/redis/namespace.rb @@ -68,7 +68,8 @@ class Namespace "decrby" => [ :first ], "del" => [ :all ], "dump" => [ :first ], - "exists" => [ :first ], + "exists" => [ :all ], + "exists?" => [ :all ], "expire" => [ :first ], "expireat" => [ :first ], "eval" => [ :eval_style ], @@ -324,6 +325,7 @@ def exec def eval(*args) call_with_namespace(:eval, *args) end + ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true) ADMINISTRATIVE_COMMANDS.keys.each do |command| define_method(command) do |*args, &block| @@ -339,6 +341,7 @@ def eval(*args) end call_with_namespace(command, *args, &block) end + ruby2_keywords(command) if respond_to?(:ruby2_keywords, true) end COMMANDS.keys.each do |command| @@ -348,6 +351,7 @@ def eval(*args) define_method(command) do |*args, &block| call_with_namespace(command, *args, &block) end + ruby2_keywords(command) if respond_to?(:ruby2_keywords, true) end def method_missing(command, *args, &block) @@ -370,6 +374,7 @@ def method_missing(command, *args, &block) super end end + ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true) def inspect "<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\ @@ -405,6 +410,7 @@ def call_with_namespace(command, *args, &block) case before when :first args[0] = add_namespace(args[0]) if args[0] + args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash) when :all args = add_namespace(args) when :exclude_first @@ -417,7 +423,7 @@ def call_with_namespace(command, *args, &block) args.push(last) if last when :exclude_options if args.last.is_a?(Hash) - last = args.pop + last = ruby2_keywords_hash(args.pop) args = add_namespace(args) args.push(last) else @@ -437,6 +443,7 @@ def call_with_namespace(command, *args, &block) args[1][:get].each_index do |i| args[1][:get][i] = add_namespace(args[1][:get][i]) unless args[1][:get][i] == "#" end + args[1] = ruby2_keywords_hash(args[1]) end when :eval_style # redis.eval() and evalsha() can either take the form: @@ -457,7 +464,7 @@ def call_with_namespace(command, *args, &block) when :scan_style options = (args.last.kind_of?(Hash) ? args.pop : {}) options[:match] = add_namespace(options.fetch(:match, '*')) - args << options + args << ruby2_keywords_hash(options) if block original_block = block @@ -483,9 +490,20 @@ def call_with_namespace(command, *args, &block) result end + ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true) private + if Hash.respond_to?(:ruby2_keywords_hash) + def ruby2_keywords_hash(kwargs) + Hash.ruby2_keywords_hash(kwargs) + end + else + def ruby2_keywords_hash(kwargs) + kwargs + end + end + # Avoid modifying the caller's (pass-by-reference) arguments. def clone_args(arg) if arg.is_a?(Array) diff --git a/redis-namespace.gemspec b/redis-namespace.gemspec index ba64d82..bfbbde2 100644 --- a/redis-namespace.gemspec +++ b/redis-namespace.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.add_dependency "redis", ">= 3.0.4" - s.add_development_dependency "rake", "~> 10.1" + s.add_development_dependency "rake" s.add_development_dependency "rspec", "~> 3.7" s.add_development_dependency "rspec-its" diff --git a/spec/redis_spec.rb b/spec/redis_spec.rb index 4278692..bfcb426 100644 --- a/spec/redis_spec.rb +++ b/spec/redis_spec.rb @@ -140,7 +140,7 @@ it 'should be able to use a namespace with setbit' do @namespaced.setbit('virgin_key', 1, 1) - expect(@namespaced.exists('virgin_key')).to be true + expect(@namespaced.exists?('virgin_key')).to be true expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1)) end @@ -239,7 +239,7 @@ @namespaced.zadd('sort2', 2, 2) @namespaced.zadd('sort2', 3, 3) @namespaced.zadd('sort2', 4, 4) - @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1]) + @namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1]) expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 )) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 81cbf3a..615db82 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,6 +12,10 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'redis/namespace' +if Redis.respond_to?(:exists_returns_integer=) + Redis.exists_returns_integer = true +end + module Helper def capture_stderr(io = nil) require 'stringio'