Commit 789695b2ce6aa4c54cb457b093f6f0bededac256
1 parent
81f17cea
Exists in
staging
and in
4 other branches
Added tests for pagination
Showing
1 changed file
with
27 additions
and
0 deletions
Show diff stats
test/unit/api/search_test.rb
@@ -57,4 +57,31 @@ class SearchTest < ActiveSupport::TestCase | @@ -57,4 +57,31 @@ class SearchTest < ActiveSupport::TestCase | ||
57 | json = JSON.parse(last_response.body) | 57 | json = JSON.parse(last_response.body) |
58 | assert_equal 1, json['results'].size | 58 | assert_equal 1, json['results'].size |
59 | end | 59 | end |
60 | + | ||
61 | + should 'not return more entries than page limit' do | ||
62 | + person = fast_create(Person) | ||
63 | + ('1'..'5').each do |n| | ||
64 | + art = create_article_with_optional_category("Article #{n}", person) | ||
65 | + end | ||
66 | + | ||
67 | + get "/api/v1/search/article?query=Article&limit=3" | ||
68 | + json = JSON.parse(last_response.body) | ||
69 | + | ||
70 | + | ||
71 | + assert_equal 3, json['results'].size | ||
72 | + end | ||
73 | + | ||
74 | + should 'return entries second page' do | ||
75 | + person = fast_create(Person) | ||
76 | + ('1'..'5').each do |n| | ||
77 | + art = create_article_with_optional_category("Article #{n}", person) | ||
78 | + end | ||
79 | + | ||
80 | + get "/api/v1/search/article?query=Article&limit=3&page=2" | ||
81 | + json = JSON.parse(last_response.body) | ||
82 | + | ||
83 | + | ||
84 | + assert_equal 2, json['results'].size | ||
85 | + end | ||
86 | + | ||
60 | end | 87 | end |
61 | \ No newline at end of file | 88 | \ No newline at end of file |