Skip to content

Commit

Permalink
#1209 tested and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 31, 2024
1 parent f7fb816 commit b691c82
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion front/front_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

get '/search' do
query = params[:query] || ''
search = current_human.search(Nb::Query.new(query), 0, 10)
offset = [(params[:offset] || '0').to_i, 0].max
limit = (params[:limit] || '10').to_i
search = current_human.search(Nb::Query.new(query), offset, limit)
content_type 'application/json'
array = []
search.each do |msg|
Expand Down
1 change: 0 additions & 1 deletion netbout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
get '/inbox' do
offset = [(params[:offset] || '0').to_i, 0].max
limit = (params[:limit] || '10').to_i
raise Urror::Nb, 'Limit can\'t be larger than 100' if limit > 100
haml :inbox, locals: merged(
title: '/inbox',
q: params[:q] || '',
Expand Down
1 change: 1 addition & 0 deletions objects/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def initialize(pgsql, identity, query, offset, limit)
raise 'Query is NULL' if query.nil?
@query = query
@offset = offset
raise Urror::Nb, 'Limit can\'t be larger than 1024' if limit > 1024
@limit = limit
end

Expand Down
9 changes: 9 additions & 0 deletions test/test_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def test_search
assert(json.first['id'].positive?)
end

def test_search_with_offset
human = test_user
bout = human.bouts.start('foom')
bout.post('hey')
get('/search?offset=100')
json = JSON.parse(last_response.body)
assert(json.empty?)
end

def test_bout
human = test_user
bout = human.bouts.start('hey, друг!')
Expand Down

0 comments on commit b691c82

Please sign in to comment.