Commit ee3bec9676d1959fe3b97df27da1e69baffd7e8a
1 parent
d7e3310e
Exists in
relation
Test first [skip ci]
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
README.md
@@ -670,7 +670,7 @@ First, add a route and controller action. | @@ -670,7 +670,7 @@ First, add a route and controller action. | ||
670 | class MoviesController < ApplicationController | 670 | class MoviesController < ApplicationController |
671 | def autocomplete | 671 | def autocomplete |
672 | movies = Movie.search(params[:query]).fields("title^5", "director") | 672 | movies = Movie.search(params[:query]).fields("title^5", "director") |
673 | - .match(:word_start).limit(10).load(false).misspellings(below: 5) | 673 | + .match(:word_start).load(false).misspellings(below: 5).first(10) |
674 | 674 | ||
675 | render json: movies.map(&:title) | 675 | render json: movies.map(&:title) |
676 | end | 676 | end |
test/relation_test.rb
@@ -52,6 +52,14 @@ class RelationTest < Minitest::Test | @@ -52,6 +52,14 @@ class RelationTest < Minitest::Test | ||
52 | assert Product.search.pluck | 52 | assert Product.search.pluck |
53 | end | 53 | end |
54 | 54 | ||
55 | + def test_first | ||
56 | + store_names ["Blue", "Red"] | ||
57 | + assert_kind_of Product, Product.first | ||
58 | + assert_kind_of Product, Product.search.first if defined?(ActiveRecord) | ||
59 | + assert_equal 1, Product.first(1).size | ||
60 | + assert_equal 1, Product.search.first(1).size if defined?(ActiveRecord) | ||
61 | + end | ||
62 | + | ||
55 | def test_take | 63 | def test_take |
56 | store_names ["Blue", "Red"] | 64 | store_names ["Blue", "Red"] |
57 | assert_kind_of Product, Product.take | 65 | assert_kind_of Product, Product.take |