Skip to content

Commit

Permalink
yegor256#1211 better test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 31, 2024
1 parent 3ddf7ce commit 4d2d0b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
31 changes: 16 additions & 15 deletions objects/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,30 @@ def to_sql
end

def to_prabsent(present)
head = if @prefix == '#'
"tag.name='#{@name}'"
elsif @prefix == '$'
"flag.name='#{@name}'"
else
raise Nb::Urror, "Can't use prabsent on '#{@name}' attribute"
end
tail = if present
if @prefix == '#'
'tag.bout IS NOT NULL'
if present
head = if @prefix == '#'
"tag.name='#{@name}'"
elsif @prefix == '$'
'flag.message IS NOT NULL'
"flag.name='#{@name}'"
else
raise Nb::Urror, "Can't use prabsent on '#{@name}' attribute"
end
elsif @prefix == '#'
"(SELECT COUNT(*) FROM flag AS f WHERE f.message=message.id AND name='#{@name}') = 0"
tail = if @prefix == '#'
'tag.bout IS NOT NULL'
elsif @prefix == '$'
"(SELECT COUNT(*) FROM tag AS t WHERE t.bout=bout.id AND t.name='#{@name}') = 0"
'flag.message IS NOT NULL'
else
raise Nb::Urror, "Can't use prabsent on '#{@name}' attribute"
end
return "(#{head} AND #{tail})"
end
if @prefix == '#'
"(SELECT COUNT(*) FROM tag AS t WHERE t.bout=bout.id AND t.name='#{@name}') = 0"
elsif @prefix == '$'
"(SELECT COUNT(*) FROM flag AS f WHERE f.message=message.id AND name='#{@name}') = 0"
else
raise Nb::Urror, "Can't use prabsent on '#{@name}' attribute"
end
"(#{head} AND #{tail})"
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def test_search_by_absence
human = Nb::Humans.new(test_pgsql).take(test_name).create
bouts = human.bouts
bout = bouts.start(test_name)
msg = bout.post(test_name)
msg.flags.attach('one')
bout.post(test_name).flags.attach('one')
bout.post(test_name).flags.attach('one')
bout.post(test_name)
assert_equal(2, human.search(Nb::Query.new(''), 0, 10).to_a.size)
assert_equal(3, human.search(Nb::Query.new(''), 0, 10).to_a.size)
assert_equal(1, human.search(Nb::Query.new('($one-)'), 0, 10).to_a.size)
end
end

0 comments on commit 4d2d0b4

Please sign in to comment.