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 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/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 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