Skip to content

Commit

Permalink
#65 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 12, 2024
1 parent c6ff23d commit 1cdd5c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GEM
erubi (1.13.0)
ethon (0.16.0)
ffi (>= 1.15.0)
factbase (0.3.0)
factbase (0.4.0)
backtrace (> 0)
decoor (> 0)
json (~> 2.7)
Expand Down
5 changes: 3 additions & 2 deletions lib/fbe/fb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
uid: '_id'
)
fbe =
Factbase::Pre.new(fbe) do |f|
max = fbe.query('(eq _id (max _id))').each.to_a.first
Factbase::Pre.new(fbe) do |f, fbt|
max = fbt.query('(eq _id (max _id))').each.to_a.first
f._id = (max.nil? ? 0 : max._id) + 1
f._time = Time.now
f._version = "#{Factbase::VERSION}/#{Judges::VERSION}/#{options.action_version}"
f._job = options.job_id unless options.job_id.nil?
end
Factbase::Looged.new(fbe, loog)
end
Expand Down
27 changes: 27 additions & 0 deletions test/fbe/test_fb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,31 @@ def test_simple
stdout = $loog.to_s
assert(stdout.include?('Inserted new fact #1'), stdout)
end

def test_increment_id_in_transaction
$fb = Factbase.new
$global = {}
$options = Judges::Options.new
$loog = Loog::Buffer.new
Fbe.fb.txn do |fbt|
fbt.insert
fbt.insert
end
arr = Fbe.fb.query('(always)').each.to_a
assert_equal(1, arr[0]._id)
assert_equal(2, arr[1]._id)
end

def test_adds_meta_properties
$fb = Factbase.new
$global = {}
$options = Judges::Options.new('JOB_ID' => 42)
$loog = Loog::Buffer.new
Fbe.fb.insert
f = Fbe.fb.query('(always)').each.to_a.first
assert(!f._id.nil?)
assert(!f._time.nil?)
assert(!f._version.nil?)
assert(!f._job.nil?)
end
end

0 comments on commit 1cdd5c2

Please sign in to comment.