Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/couchbase/json_transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/couchbase/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/active_support/cache_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/active_support/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions test/json_transcoder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading