diff --git a/lib/couchbase/json_transcoder.rb b/lib/couchbase/json_transcoder.rb index 53796662..bed7f27d 100644 --- a/lib/couchbase/json_transcoder.rb +++ b/lib/couchbase/json_transcoder.rb @@ -35,7 +35,7 @@ def decode(blob, flags) format = TranscoderFlags.decode(flags).format raise Error::DecodingFailure, "Unable to decode #{format} with the JsonTranscoder" unless format == :json || format.nil? - JSON.parse(blob) unless blob&.empty? + JSON.parse(blob) unless blob && blob.empty? end end end diff --git a/lib/couchbase/options.rb b/lib/couchbase/options.rb index 1e64c2d5..8ba96625 100644 --- a/lib/couchbase/options.rb +++ b/lib/couchbase/options.rb @@ -107,7 +107,7 @@ def project(*paths) # @api private # @return [Boolean] def need_projected_get? - @with_expiry || !@projections&.empty? + @with_expiry || (!@projections.nil? && !@projections.empty?) end # @api private @@ -116,7 +116,7 @@ def to_backend timeout: Utils::Time.extract_duration(@timeout), } options.update(with_expiry: true) if @with_expiry - unless @projections&.empty? + unless @projections.nil? || @projections.empty? options.update({ projections: @projections, preserve_array_indexes: @preserve_array_indexes, diff --git a/test/active_support/cache_store_test.rb b/test/active_support/cache_store_test.rb index 4ccfc886..ef1d82f5 100644 --- a/test/active_support/cache_store_test.rb +++ b/test/active_support/cache_store_test.rb @@ -17,12 +17,14 @@ require_relative "../test_helper" require "active_support" +require "logger" module Couchbase class CacheStoreTest < Minitest::Test include TestUtilities def setup + ActiveSupport::Cache::Store.logger = Logger.new($stderr) @cache = ActiveSupport::Cache.lookup_store(:couchbase_store, { connection_string: env.connection_string, username: env.username, diff --git a/test/active_support/caching_test.rb b/test/active_support/caching_test.rb index 4621b90d..32639e08 100644 --- a/test/active_support/caching_test.rb +++ b/test/active_support/caching_test.rb @@ -31,6 +31,7 @@ class CachingTest < ActiveSupport::TestCase include TestUtilities def lookup_store(options = {}) + ActiveSupport::Cache::Store.logger = Logger.new($stderr) ActiveSupport::Cache.lookup_store(:couchbase_store, { connection_string: env.connection_string, username: env.username, diff --git a/test/json_transcoder_test.rb b/test/json_transcoder_test.rb index d4a8703e..a5588929 100644 --- a/test/json_transcoder_test.rb +++ b/test/json_transcoder_test.rb @@ -58,6 +58,14 @@ def test_encode_binary_fails assert_raises(Couchbase::Error::EncodingFailure) { @transcoder.encode(document) } end + def test_encode_nil + document = nil + encoded, flag = @transcoder.encode(document) + + assert_equal "null", encoded + assert_equal 2, flag >> 24 + end + def test_decode_hash blob = "{\"foo\":10,\"bar\":\"baz\"}" flag = Couchbase::TranscoderFlags.new(format: :json).encode @@ -88,5 +96,13 @@ def test_decode_invalid_flag assert_raises(Couchbase::Error::DecodingFailure) { @transcoder.decode(blob, flag) } end + + def test_decode_nil + blob = "null" + flag = Couchbase::TranscoderFlags.new(format: :json).encode + decoded = @transcoder.decode(blob, flag) + + assert_nil decoded + end end end