Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 7, 2024
1 parent 9c81a2b commit 3e5d4d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fbe/overwrite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def Fbe.overwrite(fact, property, value, fb: Fbe.fb)
fact.all_properties.each do |prop|
before[prop.to_s] = fact[prop]
end
id = fact['_id'].first
id = fact['_id']&.first
raise 'There is no _id in the fact, cannot use Fbe.overwrite' if id.nil?
raise "No facts by _id = #{id}" if fb.query("(eq _id #{id})").delete!.zero?
n = fb.insert
Expand Down
8 changes: 8 additions & 0 deletions test/fbe/test_overwrite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def test_simple_insert
assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
end

def test_without_id
fb = Factbase.new
f = fb.insert
assert_raises do
Fbe.overwrite(f, :foo, 42, fb:)
end
end

def test_safe_insert
fb = Factbase.new
f1 = fb.insert
Expand Down

0 comments on commit 3e5d4d6

Please sign in to comment.