Commit 0422c616c2198775ee93c59019b468054125a013
1 parent
85fc546d
Exists in
master
and in
19 other branches
Fixed page_view_entries for Kaminari - fixes #934
Showing
6 changed files
with
55 additions
and
2 deletions
Show diff stats
CHANGELOG.md
Gemfile
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
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 | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +en: | |
2 | + views: | |
3 | + pagination: | |
4 | + first: "« First" | |
5 | + last: "Last »" | |
6 | + previous: "‹ Prev" | |
7 | + next: "Next ›" | |
8 | + truncate: "…" | |
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} - %{last}</b> of <b>%{total}</b> in total" | ... | ... |