Skip to content

Commit

Permalink
Merge pull request #3 from wallarm/fix-may-missing-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBochkarev authored Oct 12, 2021
2 parents 1413f1d + d6dc796 commit d67a911
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ AllCops:
NewCops: enable

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Enabled: false

Style/QuotedSymbols:
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: true
Expand Down
12 changes: 12 additions & 0 deletions lib/mem_db/field/may_missing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/mem_db/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class MemDB
VERSION = "0.1.0"
VERSION = "0.1.2"
end
28 changes: 28 additions & 0 deletions spec/field/may_missing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d67a911

Please sign in to comment.