mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
parent
b8bbfb1ce6
commit
1ba8e5f8fd
3 changed files with 35 additions and 7 deletions
|
@ -29,6 +29,9 @@ module Kaminari
|
||||||
c = except(:offset, :limit, :order)
|
c = except(:offset, :limit, :order)
|
||||||
# Remove includes only if they are irrelevant
|
# Remove includes only if they are irrelevant
|
||||||
c = c.except(:includes) unless references_eager_loaded_tables?
|
c = c.except(:includes) unless references_eager_loaded_tables?
|
||||||
|
|
||||||
|
c = c.limit(max_pages * limit_value) if max_pages && max_pages.respond_to?(:*)
|
||||||
|
|
||||||
# Handle grouping with a subquery
|
# Handle grouping with a subquery
|
||||||
@total_count = if c.group_values.any?
|
@total_count = if c.group_values.any?
|
||||||
c.model.from(c.except(:select).select("1")).count
|
c.model.from(c.except(:select).select("1")).count
|
||||||
|
|
|
@ -274,7 +274,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
||||||
User.max_pages 4
|
User.max_pages 4
|
||||||
users = User.page(4).per(10)
|
users = User.page(4).per(10)
|
||||||
|
|
||||||
assert_equal 'Displaying users <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(users)
|
assert_equal 'Displaying users <b>31 - 40</b> of <b>40</b> in total', view.page_entries_info(users)
|
||||||
ensure
|
ensure
|
||||||
User.max_pages nil
|
User.max_pages nil
|
||||||
end
|
end
|
||||||
|
@ -344,9 +344,8 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'the last page with default entry name' do
|
test 'the last page with default entry name' do
|
||||||
User.max_pages 4
|
users = User.page(5).per(10)
|
||||||
users = User.page(4).per(10)
|
assert_equal 'Displaying Benutzer <b>41 - 50</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'Benutzer')
|
||||||
assert_equal 'Displaying Benutzer <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'Benutzer')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -393,9 +392,8 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'the last page with default entry name' do
|
test 'the last page with default entry name' do
|
||||||
User.max_pages 4
|
users = User.page(5).per(10)
|
||||||
users = User.page(4).per(10)
|
assert_equal 'Displaying utilisateurs <b>41 - 50</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'utilisateur')
|
||||||
assert_equal 'Displaying utilisateurs <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'utilisateur')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,33 @@ if defined? ActiveRecord
|
||||||
test 'calculating total_count with GROUP BY ... HAVING clause' do
|
test 'calculating total_count with GROUP BY ... HAVING clause' do
|
||||||
assert_equal 2, Authorship.group(:user_id).having("COUNT(book_id) >= 3").page(1).total_count
|
assert_equal 2, Authorship.group(:user_id).having("COUNT(book_id) >= 3").page(1).total_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'total_count with max_pages does not add LIMIT' do
|
||||||
|
begin
|
||||||
|
subscriber = ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, __, ___, ____, payload|
|
||||||
|
assert_not_match /LIMIT/, payload[:sql]
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 7, User.page.total_count
|
||||||
|
ensure
|
||||||
|
ActiveSupport::Notifications.unsubscribe subscriber
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'total_count with max_pages adds "LIMIT (max_pages * per_page)" to the count query' do
|
||||||
|
begin
|
||||||
|
subscriber = ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, __, ___, ____, payload|
|
||||||
|
assert_match /LIMIT/, payload[:sql]
|
||||||
|
end
|
||||||
|
|
||||||
|
User.max_pages 10
|
||||||
|
|
||||||
|
assert_equal 7, User.page.total_count
|
||||||
|
ensure
|
||||||
|
User.max_pages nil
|
||||||
|
ActiveSupport::Notifications.unsubscribe subscriber
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue