From 8772b110f9e3ed0d587886c2e9002bc02b0f2b75 Mon Sep 17 00:00:00 2001 From: Dmitry Bochkarev Date: Wed, 6 Oct 2021 00:06:20 +0500 Subject: [PATCH 1/3] fix may_missing field decorator --- lib/mem_db/field/may_missing.rb | 12 ++++++++++++ spec/field/may_missing_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/mem_db/field/may_missing.rb b/lib/mem_db/field/may_missing.rb index 5fff51f..5d6c456 100644 --- a/lib/mem_db/field/may_missing.rb +++ b/lib/mem_db/field/may_missing.rb @@ -37,6 +37,18 @@ def new_matching(value) @original.new_matching(value) end end + + def field_value(obj) + if obj[field].nil? + nil + else + @original.field_value(obj) + end + end + + def prepare_query(obj) + @original.prepare_query(obj) + end end end end diff --git a/spec/field/may_missing_spec.rb b/spec/field/may_missing_spec.rb index 219923d..4bc692f 100644 --- a/spec/field/may_missing_spec.rb +++ b/spec/field/may_missing_spec.rb @@ -52,4 +52,32 @@ query: {category: "games"}, expect: false } + + context 'when decorate other field' do + let(:field) { described_class.new(MemDB::Field::Enum.new(:category).downcase) } + + it_behaves_like "field", "field is missing", { + matching: {}, + query: {category: "food"}, + expect: true + } + + it_behaves_like "field", "field is nil", { + matching: {category: nil}, + query: {category: "food"}, + expect: true + } + + it_behaves_like "field", "exact single match", { + matching: {category: "food"}, + query: {category: "food"}, + expect: true + } + + it_behaves_like "field", "exact single match by decorated value", { + matching: {category: "foOD"}, + query: {category: "FOod"}, + expect: true + } + end end From 73b46131c0f7d2b02bf7a7ef844bebf2ab2c8f63 Mon Sep 17 00:00:00 2001 From: Dmitry Bochkarev Date: Wed, 6 Oct 2021 10:32:26 +0500 Subject: [PATCH 2/3] change rubocop rules --- .rubocop.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 997388e..3b94cf3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,8 +3,10 @@ AllCops: NewCops: enable Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes + Enabled: false + +Style/QuotedSymbols: + Enabled: false Style/StringLiteralsInInterpolation: Enabled: true From d6dc7969f5489fe85df8e786df38b1d05320485d Mon Sep 17 00:00:00 2001 From: Dmitry Bochkarev Date: Tue, 12 Oct 2021 11:00:41 +0500 Subject: [PATCH 3/3] bump version --- lib/mem_db/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mem_db/version.rb b/lib/mem_db/version.rb index 4b4aea4..3b71177 100644 --- a/lib/mem_db/version.rb +++ b/lib/mem_db/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class MemDB - VERSION = "0.1.0" + VERSION = "0.1.2" end