Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/fbe/tombstone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def initialize(fb: Fbe.fb, fid: '_id')
def issues(where, repo)
raise(Fbe::Error, 'The type of "where" is not String') unless where.is_a?(String)
raise(Fbe::Error, 'The type of "repo" is not Integer') unless repo.is_a?(Integer)
f = @fb.query(
"(and (eq where '#{where}') (eq what 'tombstone') (eq repository #{repo}) (exists issues))"
).each.first
return [] if f.nil?
f['issues'].flat_map do |ii|
buried(where, repo).flat_map do |ii|
a, b = ii.split('-').map { |i| Integer(i, 10) }
b = a if b.nil?
(a..b).to_a
Expand Down Expand Up @@ -92,13 +88,11 @@ def has?(where, repo, issue)
raise(Fbe::Error, 'The type of "issue" is neither Integer nor Array')
end
issue = numbers(issue)
f = @fb.query(
"(and (eq where '#{where}') (eq what 'tombstone') (eq repository #{repo}) (exists issues))"
).each.first
return false if f.nil?
ranges = buried(where, repo)
return false if ranges.empty?
return false if issue.empty?
issue.all? do |i|
f['issues'].any? do |ii|
ranges.any? do |ii|
a, b = ii.split('-').map { |i| Integer(i, 10) }
b.nil? ? a == i : (a..b).cover?(i)
end
Expand All @@ -107,6 +101,12 @@ def has?(where, repo, issue)

private

def buried(where, repo)
@fb.query(
"(and (eq where '#{where}') (eq what 'tombstone') (eq repository #{repo}) (exists issues))"
).each.flat_map { |f| f['issues'] }
end

def numbers(issue)
list = issue.is_a?(Array) ? issue : [issue]
list.each do |i|
Expand Down
16 changes: 16 additions & 0 deletions test/fbe/test_tombstone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,20 @@ def test_dont_touch_factbase_when_member_is_invalid
end
assert_equal(0, fb.size, "factbase is touched by member #{member.inspect}, seed is #{seed}")
end

def test_reads_all_tombstone_facts_of_repository
fb = Factbase.new
%w[5 9].each do |i|
f = fb.insert
f.what = 'tombstone'
f.where = 'github'
f.repository = 7
f.issues = i
end
ts = Fbe::Tombstone.new(fb:)
assert(ts.has?('github', 7, 5), 'The first tombstone fact must be read')
assert(ts.has?('github', 7, 9), 'The second tombstone fact must be read')
assert(ts.has?('github', 7, [5, 9]), 'Both tombstone facts must be read together')
assert_equal([5, 9], ts.issues('github', 7).sort)
end
end
Loading