Commit 0422c616c2198775ee93c59019b468054125a013

Authored by Andrew Kane
1 parent 85fc546d

Fixed page_view_entries for Kaminari - fixes #934

CHANGELOG.md
1 1 ## 2.3.1 [unreleased]
2 2  
3 3 - Added support for passing fields to `suggest` option
  4 +- Fixed `page_view_entries` for Kaminari
4 5  
5 6 ## 2.3.0
6 7  
... ...
Gemfile
... ... @@ -10,3 +10,7 @@ gem "typhoeus"
10 10 gem "activejob"
11 11 gem "redis"
12 12 gem "connection_pool"
  13 +
  14 +# kaminari
  15 +gem "actionpack"
  16 +gem "kaminari"
... ...
lib/searchkick/results.rb
... ... @@ -127,8 +127,14 @@ module Searchkick
127 127 klass.model_name
128 128 end
129 129  
130   - def entry_name
131   - model_name.human.downcase
  130 + def entry_name(options = {})
  131 + if options.empty?
  132 + # backward compatibility
  133 + model_name.human.downcase
  134 + else
  135 + default = options[:count] == 1 ? model_name.human : model_name.human.pluralize
  136 + model_name.human(options.reverse_merge(default: default))
  137 + end
132 138 end
133 139  
134 140 def total_count
... ...
test/gemfiles/mongoid6.gemfile
... ... @@ -6,3 +6,7 @@ gemspec path: "../../"
6 6 gem "mongoid", "~> 6.0.0"
7 7 gem "activejob"
8 8 gem "redis"
  9 +
  10 +# kaminari
  11 +gem "actionpack"
  12 +gem "kaminari"
... ...
test/pagination_test.rb
... ... @@ -50,4 +50,21 @@ class PaginationTest < Minitest::Test
50 50 assert_equal 1, products.current_page
51 51 assert products.first_page?
52 52 end
  53 +
  54 + def test_kaminari
  55 + skip unless defined?(Kaminari)
  56 +
  57 + require "action_view"
  58 +
  59 + I18n.load_path = Dir["test/support/kaminari.yml"]
  60 + I18n.backend.load_translations
  61 +
  62 + view = ActionView::Base.new
  63 +
  64 + store_names ["Product A"]
  65 + assert_equal "Displaying <b>1</b> product", view.page_entries_info(Product.search("product"))
  66 +
  67 + store_names ["Product B"]
  68 + assert_equal "Displaying <b>all 2</b> products", view.page_entries_info(Product.search("product"))
  69 + end
53 70 end
... ...
test/support/kaminari.yml 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +en:
  2 + views:
  3 + pagination:
  4 + first: "&laquo; First"
  5 + last: "Last &raquo;"
  6 + previous: "&lsaquo; Prev"
  7 + next: "Next &rsaquo;"
  8 + truncate: "&hellip;"
  9 + helpers:
  10 + page_entries_info:
  11 + entry:
  12 + zero: "entries"
  13 + one: "entry"
  14 + other: "entries"
  15 + one_page:
  16 + display_entries:
  17 + zero: "No %{entry_name} found"
  18 + one: "Displaying <b>1</b> %{entry_name}"
  19 + other: "Displaying <b>all %{count}</b> %{entry_name}"
  20 + more_pages:
  21 + display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
... ...