mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
#️⃣ 🚀 🔞
This commit is contained in:
parent
f33e2566a6
commit
721654ca75
19 changed files with 152 additions and 152 deletions
2
Rakefile
2
Rakefile
|
@ -12,7 +12,7 @@ Rake::TestTask.new do |t|
|
|||
t.verbose = true
|
||||
end
|
||||
|
||||
task :default => "test:all"
|
||||
task default: "test:all"
|
||||
|
||||
namespace :test do
|
||||
mappers = %w(
|
||||
|
|
|
@ -24,7 +24,7 @@ module Kaminari
|
|||
options[:total_pages] ||= scope.total_pages
|
||||
|
||||
paginator_class = options[:paginator_class] || Kaminari::Helpers::Paginator
|
||||
paginator = paginator_class.new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
|
||||
paginator = paginator_class.new(self, options.reverse_merge(current_page: scope.current_page, per_page: scope.limit_value, remote: false))
|
||||
paginator.to_s
|
||||
end
|
||||
|
||||
|
@ -48,7 +48,7 @@ module Kaminari
|
|||
def link_to_previous_page(scope, name, options = {})
|
||||
prev_page = path_to_prev_page(scope, options)
|
||||
|
||||
link_to_if prev_page, name, prev_page, options.except(:params, :param_name).reverse_merge(:rel => 'prev') do
|
||||
link_to_if prev_page, name, prev_page, options.except(:params, :param_name).reverse_merge(rel: 'prev') do
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ module Kaminari
|
|||
def link_to_next_page(scope, name, options = {})
|
||||
next_page = path_to_next_page(scope, options)
|
||||
|
||||
link_to_if next_page, name, next_page, options.except(:params, :param_name).reverse_merge(:rel => 'next') do
|
||||
link_to_if next_page, name, next_page, options.except(:params, :param_name).reverse_merge(rel: 'next') do
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
@ -98,15 +98,15 @@ module Kaminari
|
|||
entry_name = if options[:entry_name]
|
||||
options[:entry_name].pluralize(collection.size)
|
||||
else
|
||||
collection.entry_name(:count => collection.size).downcase
|
||||
collection.entry_name(count: collection.size).downcase
|
||||
end
|
||||
|
||||
if collection.total_pages < 2
|
||||
t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
|
||||
t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count)
|
||||
else
|
||||
first = collection.offset_value + 1
|
||||
last = (sum = collection.offset_value + collection.limit_value) > collection.total_count ? collection.total_count : sum
|
||||
t('helpers.page_entries_info.more_pages.display_entries', :entry_name => entry_name, :first => first, :last => last, :total => collection.total_count)
|
||||
t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: first, last: last, total: collection.total_count)
|
||||
end.html_safe
|
||||
end
|
||||
|
||||
|
@ -133,8 +133,8 @@ module Kaminari
|
|||
prev_page = path_to_prev_page(scope, options)
|
||||
|
||||
output = String.new
|
||||
output << tag(:link, :rel => "next", :href => next_page) if next_page
|
||||
output << tag(:link, :rel => "prev", :href => prev_page) if prev_page
|
||||
output << tag(:link, rel: "next", href: next_page) if next_page
|
||||
output << tag(:link, rel: "prev", href: prev_page) if prev_page
|
||||
output.html_safe
|
||||
end
|
||||
|
||||
|
@ -149,7 +149,7 @@ module Kaminari
|
|||
# It will return `nil` if there is no next page.
|
||||
def path_to_next_page(scope, options = {})
|
||||
return if scope.next_page.blank?
|
||||
Kaminari::Helpers::NextPage.new(self, options.reverse_merge(:current_page => scope.current_page)).url
|
||||
Kaminari::Helpers::NextPage.new(self, options.reverse_merge(current_page: scope.current_page)).url
|
||||
end
|
||||
|
||||
# A helper that calculates the path to the previous page.
|
||||
|
@ -163,7 +163,7 @@ module Kaminari
|
|||
# It will return `nil` if there is no previous page.
|
||||
def path_to_prev_page(scope, options = {})
|
||||
return if scope.prev_page.blank?
|
||||
Kaminari::Helpers::PrevPage.new(self, options.reverse_merge(:current_page => scope.current_page)).url
|
||||
Kaminari::Helpers::PrevPage.new(self, options.reverse_merge(current_page: scope.current_page)).url
|
||||
end
|
||||
|
||||
module PaginatorExtension
|
||||
|
@ -196,12 +196,12 @@ module Kaminari
|
|||
end
|
||||
|
||||
subscriber.render_without_logging = true
|
||||
ret = super @window_options.merge :paginator => self
|
||||
ret = super @window_options.merge paginator: self
|
||||
subscriber.render_without_logging = false
|
||||
|
||||
ret
|
||||
else
|
||||
super @window_options.merge :paginator => self
|
||||
super @window_options.merge paginator: self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
module Kaminari
|
||||
module ActiveRecordRelationMethods
|
||||
def entry_name(options = {})
|
||||
model_name.human(options.reverse_merge(:default => model_name.human.pluralize(options[:count])))
|
||||
model_name.human(options.reverse_merge(default: model_name.human.pluralize(options[:count])))
|
||||
end
|
||||
|
||||
def reset #:nodoc:
|
||||
|
|
|
@ -4,8 +4,8 @@ module Kaminari
|
|||
class ViewsGenerator < Rails::Generators::NamedBase
|
||||
source_root File.expand_path('../../../../app/views/kaminari', __FILE__)
|
||||
|
||||
class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb", "haml", and "slim".'
|
||||
class_option :views_prefix, :type => :string, :desc => 'Prefix for path to put views in.'
|
||||
class_option :template_engine, type: :string, aliases: '-e', desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".'
|
||||
class_option :views_prefix, type: :string, desc: 'Prefix for path to put views in.'
|
||||
|
||||
def self.banner #:nodoc:
|
||||
<<-BANNER.chomp
|
||||
|
|
|
@ -64,7 +64,7 @@ module Kaminari
|
|||
private :relevant_pages
|
||||
|
||||
def page_tag(page)
|
||||
@last = Page.new @template, @options.merge(:page => page)
|
||||
@last = Page.new @template, @options.merge(page: page)
|
||||
end
|
||||
|
||||
%w[first_page prev_page next_page last_page gap].each do |tag|
|
||||
|
@ -76,7 +76,7 @@ module Kaminari
|
|||
end
|
||||
|
||||
def to_s #:nodoc:
|
||||
super @window_options.merge :paginator => self
|
||||
super @window_options.merge paginator: self
|
||||
end
|
||||
|
||||
# delegates view helper methods to @template
|
||||
|
|
|
@ -27,11 +27,11 @@ module Kaminari
|
|||
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
formats = (@template.respond_to?(:formats) ? @template.formats : Array(@template.params[:format])) + [:html]
|
||||
@template.render :partial => partial_path, :locals => @options.merge(locals), :formats => formats
|
||||
@template.render partial: partial_path, locals: @options.merge(locals), formats: formats
|
||||
end
|
||||
|
||||
def page_url_for(page)
|
||||
@template.url_for params_for(page).merge(:only_path => true)
|
||||
@template.url_for params_for(page).merge(only_path: true)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -76,7 +76,7 @@ module Kaminari
|
|||
page_url_for page
|
||||
end
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
super locals.merge(:url => url)
|
||||
super locals.merge(url: url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +88,7 @@ module Kaminari
|
|||
@options[:page]
|
||||
end
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
super locals.merge(:page => page)
|
||||
super locals.merge(page: page)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ module Kaminari
|
|||
end
|
||||
|
||||
def entry_name(options = {})
|
||||
I18n.t('helpers.page_entries_info.entry', options.reverse_merge(:default => ENTRY.pluralize(options[:count])))
|
||||
I18n.t('helpers.page_entries_info.entry', options.reverse_merge(default: ENTRY.pluralize(options[:count])))
|
||||
end
|
||||
|
||||
# items at the specified "page"
|
||||
|
@ -45,7 +45,7 @@ module Kaminari
|
|||
|
||||
# returns another chunk of the original array
|
||||
def limit(num)
|
||||
self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count, :padding => @_padding
|
||||
self.class.new @_original_array, limit: num, offset: @_offset_value, total_count: @_total_count, padding: @_padding
|
||||
end
|
||||
|
||||
# total item numbers of the original array
|
||||
|
@ -55,7 +55,7 @@ module Kaminari
|
|||
|
||||
# returns another chunk of the original array
|
||||
def offset(num)
|
||||
self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count, :padding => @_padding
|
||||
self.class.new @_original_array, limit: @_limit_value, offset: num, total_count: @_total_count, padding: @_padding
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# database
|
||||
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
||||
ActiveRecord::Base.configurations = {'test' => {adapter: 'sqlite3', database: ':memory:'}}
|
||||
ActiveRecord::Base.establish_connection :test
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
class User < ActiveRecord::Base
|
||||
has_many :authorships
|
||||
has_many :readerships
|
||||
has_many :books_authored, :through => :authorships, :source => :book
|
||||
has_many :books_read, :through => :readerships, :source => :book
|
||||
has_many :addresses, :class_name => 'User::Address'
|
||||
has_many :books_authored, through: :authorships, source: :book
|
||||
has_many :books_read, through: :readerships, source: :book
|
||||
has_many :addresses, class_name: 'User::Address'
|
||||
|
||||
def readers
|
||||
User.joins(:books_read => :authors).where(:authors_books => {:id => self})
|
||||
User.joins(books_read: :authors).where(authors_books: {id: self})
|
||||
end
|
||||
|
||||
scope :by_name, -> { order(:name) }
|
||||
|
@ -32,8 +32,8 @@ end
|
|||
class Book < ActiveRecord::Base
|
||||
has_many :authorships
|
||||
has_many :readerships
|
||||
has_many :authors, :through => :authorships, :source => :user
|
||||
has_many :readers, :through => :readerships, :source => :user
|
||||
has_many :authors, through: :authorships, source: :user
|
||||
has_many :readers, through: :readerships, source: :user
|
||||
end
|
||||
# a model that is a descendant of AR::Base but doesn't directly inherit AR::Base
|
||||
class Admin < User
|
||||
|
|
|
@ -7,7 +7,7 @@ require 'fake_app/active_record/config' if defined? ActiveRecord
|
|||
# config
|
||||
app = Class.new(Rails::Application)
|
||||
app.config.secret_key_base = app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
|
||||
app.config.session_store :cookie_store, :key => '_myapp_session'
|
||||
app.config.session_store :cookie_store, key: '_myapp_session'
|
||||
app.config.active_support.deprecation = :log
|
||||
app.config.eager_load = false
|
||||
# Rails.root
|
||||
|
@ -18,10 +18,10 @@ app.initialize!
|
|||
# routes
|
||||
app.routes.draw do
|
||||
resources :users do
|
||||
get 'index_text(.:format)', :action => :index_text, :on => :collection
|
||||
get 'index_text(.:format)', action: :index_text, on: :collection
|
||||
end
|
||||
resources :addresses do
|
||||
get 'page/:page', :action => :index, :on => :collection
|
||||
get 'page/:page', action: :index, on: :collection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ class ApplicationController < ActionController::Base; end
|
|||
class UsersController < ApplicationController
|
||||
def index
|
||||
@users = User.page params[:page]
|
||||
render :inline => <<-ERB
|
||||
render inline: <<-ERB
|
||||
<%= @users.map(&:name).join("\n") %>
|
||||
<%= paginate @users %>
|
||||
ERB
|
||||
|
@ -48,7 +48,7 @@ if defined? ActiveRecord
|
|||
class AddressesController < ApplicationController
|
||||
def index
|
||||
@addresses = User::Address.page params[:page]
|
||||
render :inline => <<-ERB
|
||||
render inline: <<-ERB
|
||||
<%= @addresses.map(&:street).join("\n") %>
|
||||
<%= paginate @addresses %>
|
||||
ERB
|
||||
|
|
|
@ -11,17 +11,17 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
sub_test_case '#paginate' do
|
||||
setup do
|
||||
50.times {|i| User.create! :name => "user#{i}"}
|
||||
50.times {|i| User.create! name: "user#{i}"}
|
||||
@users = User.page(1)
|
||||
end
|
||||
|
||||
test 'returns a String' do
|
||||
assert_kind_of String, view.paginate(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_kind_of String, view.paginate(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'escaping the pagination for javascript' do
|
||||
assert_nothing_raised do
|
||||
escape_javascript(view.paginate @users, :params => {:controller => 'users', :action => 'index'})
|
||||
escape_javascript(view.paginate @users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,7 +29,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
begin
|
||||
controller.append_view_path File.join(Gem.loaded_specs['kaminari-core'].gem_dir, 'test/fake_app/views')
|
||||
|
||||
html = view.paginate @users, :theme => 'bootstrap', :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.paginate @users, theme: 'bootstrap', params: {controller: 'users', action: 'index'}
|
||||
assert_match(/bootstrap-paginator/, html)
|
||||
assert_match(/bootstrap-page-link/, html)
|
||||
ensure
|
||||
|
@ -41,7 +41,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
begin
|
||||
controller.append_view_path File.join(Gem.loaded_specs['kaminari-core'].gem_dir, 'test/fake_app/views')
|
||||
|
||||
assert_equal " <b>1</b>\n", view.paginate(@users, :views_prefix => 'alternative/', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal " <b>1</b>\n", view.paginate(@users, views_prefix: 'alternative/', params: {controller: 'users', action: 'index'})
|
||||
ensure
|
||||
controller.view_paths.pop
|
||||
end
|
||||
|
@ -54,17 +54,17 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
end
|
||||
|
||||
assert_equal 'CUSTOM PAGINATION', view.paginate(@users, :paginator_class => custom_paginator, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'CUSTOM PAGINATION', view.paginate(@users, paginator_class: custom_paginator, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'total_pages: 3' do
|
||||
assert_match(/<a href="\/users\?page=3">Last/, view.paginate(@users, :total_pages => 3, :params => {:controller => 'users', :action => 'index'}))
|
||||
assert_match(/<a href="\/users\?page=3">Last/, view.paginate(@users, total_pages: 3, params: {controller: 'users', action: 'index'}))
|
||||
end
|
||||
|
||||
test "page: 20 (out of range)" do
|
||||
users = User.page(20)
|
||||
|
||||
html = view.paginate users, :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.paginate users, params: {controller: 'users', action: 'index'}
|
||||
assert_not_match(/Last/, html)
|
||||
assert_not_match(/Next/, html)
|
||||
end
|
||||
|
@ -72,7 +72,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
sub_test_case '#link_to_previous_page' do
|
||||
setup do
|
||||
60.times {|i| User.create! :name => "user#{i}"}
|
||||
60.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
sub_test_case 'having previous pages' do
|
||||
|
@ -81,38 +81,38 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'the default behaviour' do
|
||||
html = view.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.link_to_previous_page @users, 'Previous', params: {controller: 'users', action: 'index'}
|
||||
assert_match(/page=2/, html)
|
||||
assert_match(/rel="prev"/, html)
|
||||
end
|
||||
|
||||
test 'overriding rel=' do
|
||||
assert_match(/rel="external"/, view.link_to_previous_page(@users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'}))
|
||||
assert_match(/rel="external"/, view.link_to_previous_page(@users, 'Previous', rel: 'external', params: {controller: 'users', action: 'index'}))
|
||||
end
|
||||
|
||||
test 'with params' do
|
||||
params[:status] = 'active'
|
||||
|
||||
assert_match(/status=active/, view.link_to_previous_page(@users, 'Previous', :params => {:controller => 'users', :action => 'index'}))
|
||||
assert_match(/status=active/, view.link_to_previous_page(@users, 'Previous', params: {controller: 'users', action: 'index'}))
|
||||
end
|
||||
end
|
||||
|
||||
test 'the first page' do
|
||||
users = User.page(1)
|
||||
|
||||
assert_nil view.link_to_previous_page(users, 'Previous', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.link_to_previous_page(users, 'Previous', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'out of range' do
|
||||
users = User.page(5)
|
||||
|
||||
assert_nil view.link_to_next_page(users, 'More', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.link_to_next_page(users, 'More', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case '#link_to_next_page' do
|
||||
setup do
|
||||
50.times {|i| User.create! :name => "user#{i}"}
|
||||
50.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
sub_test_case 'having more page' do
|
||||
|
@ -121,32 +121,32 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'the default behaviour' do
|
||||
html = view.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.link_to_next_page @users, 'More', params: {controller: 'users', action: 'index'}
|
||||
assert_match(/page=2/, html)
|
||||
assert_match(/rel="next"/, html)
|
||||
end
|
||||
|
||||
test 'overriding rel=' do
|
||||
assert_match(/rel="external"/, view.link_to_next_page(@users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'}))
|
||||
assert_match(/rel="external"/, view.link_to_next_page(@users, 'More', rel: 'external', params: {controller: 'users', action: 'index'}))
|
||||
end
|
||||
|
||||
test 'with params' do
|
||||
params[:status] = 'active'
|
||||
|
||||
assert_match(/status=active/, view.link_to_next_page(@users, 'More', :params => {:controller => 'users', :action => 'index'}))
|
||||
assert_match(/status=active/, view.link_to_next_page(@users, 'More', params: {controller: 'users', action: 'index'}))
|
||||
end
|
||||
end
|
||||
|
||||
test 'the last page' do
|
||||
users = User.page(2)
|
||||
|
||||
assert_nil view.link_to_next_page(users, 'More', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.link_to_next_page(users, 'More', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'out of range' do
|
||||
users = User.page(5)
|
||||
|
||||
assert_nil view.link_to_next_page(users, 'More', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.link_to_next_page(users, 'More', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -158,47 +158,47 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
sub_test_case 'having no entries' do
|
||||
test 'with default entry name' do
|
||||
assert_equal 'No users found', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'No users found', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "member"' do
|
||||
assert_equal 'No members found', view.page_entries_info(@users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'No members found', view.page_entries_info(@users, entry_name: 'member', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case 'having 1 entry' do
|
||||
setup do
|
||||
User.create! :name => 'user1'
|
||||
User.create! name: 'user1'
|
||||
@users = User.page(1).per(25)
|
||||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying <b>1</b> user', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying <b>1</b> user', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "member"' do
|
||||
assert_equal 'Displaying <b>1</b> member', view.page_entries_info(@users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying <b>1</b> member', view.page_entries_info(@users, entry_name: 'member', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case 'having more than 1 but less than a page of entries' do
|
||||
setup do
|
||||
10.times {|i| User.create! :name => "user#{i}"}
|
||||
10.times {|i| User.create! name: "user#{i}"}
|
||||
@users = User.page(1).per(25)
|
||||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying <b>all 10</b> users', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying <b>all 10</b> users', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "member"' do
|
||||
assert_equal 'Displaying <b>all 10</b> members', view.page_entries_info(@users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying <b>all 10</b> members', view.page_entries_info(@users, entry_name: 'member', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case 'having more than one page of entries' do
|
||||
setup do
|
||||
50.times {|i| User.create! :name => "user#{i}"}
|
||||
50.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
sub_test_case 'the first page' do
|
||||
|
@ -207,11 +207,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying users <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying users <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "member"' do
|
||||
assert_equal 'Displaying members <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying members <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, entry_name: 'member', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -221,11 +221,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying users <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying users <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "member"' do
|
||||
assert_equal 'Displaying members <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying members <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@users, entry_name: 'member', params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -239,7 +239,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying users <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying users <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -247,16 +247,16 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
sub_test_case 'I18n' do
|
||||
setup do
|
||||
50.times {|i| User.create! :name => "user#{i}"}
|
||||
50.times {|i| User.create! name: "user#{i}"}
|
||||
@users = User.page(1).per(25)
|
||||
I18n.backend.store_translations(:en, User.i18n_scope => { :models => { :user => { :one => "person", :other => "people" } } })
|
||||
I18n.backend.store_translations(:en, User.i18n_scope => { models: { user: { one: "person", other: "people" } } })
|
||||
end
|
||||
teardown do
|
||||
I18n.backend.reload!
|
||||
end
|
||||
|
||||
test 'page_entries_info translates entry' do
|
||||
assert_equal 'Displaying people <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal 'Displaying people <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -266,7 +266,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'having no entries' do
|
||||
assert_equal 'No addresses found', view.page_entries_info(@addresses, :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'No addresses found', view.page_entries_info(@addresses, params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
|
||||
sub_test_case 'having 1 entry' do
|
||||
|
@ -276,11 +276,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying <b>1</b> address', view.page_entries_info(@addresses, :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying <b>1</b> address', view.page_entries_info(@addresses, params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "place"' do
|
||||
assert_equal 'Displaying <b>1</b> place', view.page_entries_info(@addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying <b>1</b> place', view.page_entries_info(@addresses, entry_name: 'place', params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -291,11 +291,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying <b>all 10</b> addresses', view.page_entries_info(@addresses, :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying <b>all 10</b> addresses', view.page_entries_info(@addresses, params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "place"' do
|
||||
assert_equal 'Displaying <b>all 10</b> places', view.page_entries_info(@addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying <b>all 10</b> places', view.page_entries_info(@addresses, entry_name: 'place', params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -310,11 +310,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying addresses <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@addresses, :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying addresses <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@addresses, params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "place"' do
|
||||
assert_equal 'Displaying places <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying places <b>1 - 25</b> of <b>50</b> in total', view.page_entries_info(@addresses, entry_name: 'place', params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -324,11 +324,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
end
|
||||
|
||||
test 'with default entry name' do
|
||||
assert_equal 'Displaying addresses <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@addresses, :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying addresses <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@addresses, params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
|
||||
test 'setting the entry name option to "place"' do
|
||||
assert_equal 'Displaying places <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'})
|
||||
assert_equal 'Displaying places <b>26 - 50</b> of <b>50</b> in total', view.page_entries_info(@addresses, entry_name: 'place', params: {controller: 'addresses', action: 'index'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -343,13 +343,13 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
sub_test_case '#rel_next_prev_link_tags' do
|
||||
setup do
|
||||
31.times {|i| User.create! :name => "user#{i}"}
|
||||
31.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
|
||||
test 'the first page' do
|
||||
users = User.page(1).per(10)
|
||||
html = view.rel_next_prev_link_tags users, :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.rel_next_prev_link_tags users, params: {controller: 'users', action: 'index'}
|
||||
|
||||
assert_not_match(/rel="prev"/, html)
|
||||
assert_match(/rel="next"/, html)
|
||||
|
@ -358,7 +358,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
test 'the second page' do
|
||||
users = User.page(2).per(10)
|
||||
html = view.rel_next_prev_link_tags users, :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.rel_next_prev_link_tags users, params: {controller: 'users', action: 'index'}
|
||||
|
||||
assert_match(/rel="prev"/, html)
|
||||
assert_not_match(/\?page=1/, html)
|
||||
|
@ -368,7 +368,7 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
test 'the last page' do
|
||||
users = User.page(4).per(10)
|
||||
html = view.rel_next_prev_link_tags users, :params => {:controller => 'users', :action => 'index'}
|
||||
html = view.rel_next_prev_link_tags users, params: {controller: 'users', action: 'index'}
|
||||
|
||||
assert_match(/rel="prev"/, html)
|
||||
assert_match(/\?page=3"/, html)
|
||||
|
@ -378,38 +378,38 @@ if defined?(::Rails::Railtie) && defined?(::ActionView)
|
|||
|
||||
sub_test_case '#path_to_next_page' do
|
||||
setup do
|
||||
2.times {|i| User.create! :name => "user#{i}"}
|
||||
2.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
test 'the first page' do
|
||||
users = User.page(1).per(1)
|
||||
assert_equal '/users?page=2', view.path_to_next_page(users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal '/users?page=2', view.path_to_next_page(users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'the last page' do
|
||||
users = User.page(2).per(1)
|
||||
assert_nil view.path_to_next_page(users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.path_to_next_page(users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case '#path_to_prev_page' do
|
||||
setup do
|
||||
3.times {|i| User.create! :name => "user#{i}"}
|
||||
3.times {|i| User.create! name: "user#{i}"}
|
||||
end
|
||||
|
||||
test 'the first page' do
|
||||
users = User.page(1).per(1)
|
||||
assert_nil view.path_to_prev_page(users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_nil view.path_to_prev_page(users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'the second page' do
|
||||
users = User.page(2).per(1)
|
||||
assert_equal '/users', view.path_to_prev_page(users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal '/users', view.path_to_prev_page(users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
|
||||
test 'the last page' do
|
||||
users = User.page(3).per(1)
|
||||
assert_equal'/users?page=2', view.path_to_prev_page(users, :params => {:controller => 'users', :action => 'index'})
|
||||
assert_equal'/users?page=2', view.path_to_prev_page(users, params: {controller: 'users', action: 'index'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,13 +17,13 @@ class PaginatorHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'view helper methods delegated to template' do
|
||||
paginator = Paginator.new(template, :params => {})
|
||||
paginator = Paginator.new(template, params: {})
|
||||
assert_equal "<a href='#'>link</a>", paginator.link_to('link', '#')
|
||||
end
|
||||
|
||||
sub_test_case '#params' do
|
||||
setup do
|
||||
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
||||
@paginator = Paginator.new(template, params: {controller: 'foo', action: 'bar'})
|
||||
end
|
||||
|
||||
test 'when params has no form params' do
|
||||
|
@ -32,7 +32,7 @@ class PaginatorHelperTest < ActiveSupport::TestCase
|
|||
|
||||
test 'when params has form params' do
|
||||
stub(template).params do
|
||||
{:authenticity_token => 'token', :commit => 'submit', :utf8 => 'true', :_method => 'patch'}
|
||||
{authenticity_token: 'token', commit: 'submit', utf8: 'true', _method: 'patch'}
|
||||
end
|
||||
|
||||
assert_equal({'controller' => 'foo', 'action' => 'bar'}, @paginator.page_tag(template).instance_variable_get('@params'))
|
||||
|
@ -40,7 +40,7 @@ class PaginatorHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test '#param_name' do
|
||||
paginator = Paginator.new(template, :param_name => :pagina)
|
||||
paginator = Paginator.new(template, param_name: :pagina)
|
||||
assert_equal :pagina, paginator.page_tag(template).instance_variable_get('@param_name')
|
||||
end
|
||||
|
||||
|
|
|
@ -53,17 +53,17 @@ if defined?(::Rails::Railtie) && defined?(ActionView)
|
|||
|
||||
sub_test_case "with param_name = 'user[page]' option" do
|
||||
setup do
|
||||
self.params[:user] = {:page => '3', :scope => 'active'}
|
||||
self.params[:user] = {page: '3', scope: 'active'}
|
||||
end
|
||||
|
||||
test 'for first page' do
|
||||
assert_not_match(/user%5Bpage%5D=\d+/, Kaminari::Helpers::Tag.new(self, :param_name => 'user[page]').page_url_for(1)) # not match user[page]=\d+
|
||||
assert_match(/user%5Bscope%5D=active/, Kaminari::Helpers::Tag.new(self, :param_name => 'user[page]').page_url_for(1)) # match user[scope]=active
|
||||
assert_not_match(/user%5Bpage%5D=\d+/, Kaminari::Helpers::Tag.new(self, param_name: 'user[page]').page_url_for(1)) # not match user[page]=\d+
|
||||
assert_match(/user%5Bscope%5D=active/, Kaminari::Helpers::Tag.new(self, param_name: 'user[page]').page_url_for(1)) # match user[scope]=active
|
||||
end
|
||||
|
||||
test 'for other page' do
|
||||
assert_match(/user%5Bpage%5D=2/, Kaminari::Helpers::Tag.new(self, :param_name => 'user[page]').page_url_for(2)) # match user[page]=2
|
||||
assert_match(/user%5Bscope%5D=active/, Kaminari::Helpers::Tag.new(self, :param_name => 'user[page]').page_url_for(2)) # match user[scope]=active
|
||||
assert_match(/user%5Bpage%5D=2/, Kaminari::Helpers::Tag.new(self, param_name: 'user[page]').page_url_for(2)) # match user[page]=2
|
||||
assert_match(/user%5Bscope%5D=active/, Kaminari::Helpers::Tag.new(self, param_name: 'user[page]').page_url_for(2)) # match user[scope]=active
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,11 +73,11 @@ if defined?(::Rails::Railtie) && defined?(ActionView)
|
|||
end
|
||||
|
||||
test 'for first page' do
|
||||
assert_not_match(/foo\.page=\d+/, Kaminari::Helpers::Tag.new(self, :param_name => 'foo.page').page_url_for(1))
|
||||
assert_not_match(/foo\.page=\d+/, Kaminari::Helpers::Tag.new(self, param_name: 'foo.page').page_url_for(1))
|
||||
end
|
||||
|
||||
test 'for other page' do
|
||||
assert_match(/foo\.page=\d+/, Kaminari::Helpers::Tag.new(self, :param_name => 'foo.page').page_url_for(2))
|
||||
assert_match(/foo\.page=\d+/, Kaminari::Helpers::Tag.new(self, param_name: 'foo.page').page_url_for(2))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -86,83 +86,83 @@ if defined?(::Rails::Railtie) && defined?(ActionView)
|
|||
class PaginatorTest < ActionView::TestCase
|
||||
test '#current?' do
|
||||
# current_page == page
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 26}, 26, nil).current?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 26}, 26, nil).current?
|
||||
# current_page != page
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 13}, 26, nil).current?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 13}, 26, nil).current?
|
||||
end
|
||||
|
||||
test '#first?' do
|
||||
# page == 1
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 26}, 1, nil).first?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 26}, 1, nil).first?
|
||||
# page != 1
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 13}, 2, nil).first?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 13}, 2, nil).first?
|
||||
end
|
||||
|
||||
test '#last?' do
|
||||
# current_page == page
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 39}, 39, nil).last?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 39}, 39, nil).last?
|
||||
# current_page != page
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 39}, 38, nil).last?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 39}, 38, nil).last?
|
||||
end
|
||||
|
||||
test '#next?' do
|
||||
# page == current_page + 1
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 52}, 53, nil).next?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 52}, 53, nil).next?
|
||||
# page != current_page + 1
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 52}, 77, nil).next?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 52}, 77, nil).next?
|
||||
end
|
||||
|
||||
test '#prev?' do
|
||||
# page == current_page - 1
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 77}, 76, nil).prev?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 77}, 76, nil).prev?
|
||||
# page != current_page + 1
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 77}, 80, nil).prev?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 77}, 80, nil).prev?
|
||||
end
|
||||
|
||||
test '#rel' do
|
||||
# page == current_page - 1
|
||||
assert_equal 'prev', Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 77}, 76, nil).rel
|
||||
assert_equal 'prev', Kaminari::Helpers::Paginator::PageProxy.new({current_page: 77}, 76, nil).rel
|
||||
# page == current_page
|
||||
assert_nil Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 78}, 78, nil).rel
|
||||
assert_nil Kaminari::Helpers::Paginator::PageProxy.new({current_page: 78}, 78, nil).rel
|
||||
# page == current_page + 1
|
||||
assert_equal 'next', Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 52}, 53, nil).rel
|
||||
assert_equal 'next', Kaminari::Helpers::Paginator::PageProxy.new({current_page: 52}, 53, nil).rel
|
||||
end
|
||||
|
||||
test '#left_outer?' do
|
||||
# current_page == left
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:left => 3}, 3, nil).left_outer?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({left: 3}, 3, nil).left_outer?
|
||||
# current_page == left + 1
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:left => 3}, 4, nil).left_outer?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({left: 3}, 4, nil).left_outer?
|
||||
# current_page == left + 2
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:left => 3}, 5, nil).left_outer?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({left: 3}, 5, nil).left_outer?
|
||||
end
|
||||
|
||||
test '#right_outer?' do
|
||||
# total_pages - page > right
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil).right_outer?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 10, right: 3}, 6, nil).right_outer?
|
||||
# total_pages - page == right
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil).right_outer?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 10, right: 3}, 7, nil).right_outer?
|
||||
# total_pages - page < right
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil).right_outer?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 10, right: 3}, 8, nil).right_outer?
|
||||
end
|
||||
|
||||
sub_test_case '#inside_window?' do
|
||||
test 'page > current_page' do
|
||||
# page - current_page > window
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 4, :window => 5}, 10, nil).inside_window?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 4, window: 5}, 10, nil).inside_window?
|
||||
# page - current_page == window
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 4, :window => 6}, 10, nil).inside_window?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 4, window: 6}, 10, nil).inside_window?
|
||||
# page - current_page < window
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 4, :window => 7}, 10, nil).inside_window?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 4, window: 7}, 10, nil).inside_window?
|
||||
end
|
||||
|
||||
test 'current_page > page' do
|
||||
# current_page - page > window
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 15, :window => 4}, 10, nil).inside_window?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({current_page: 15, window: 4}, 10, nil).inside_window?
|
||||
# current_page - page == window
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 15, :window => 5}, 10, nil).inside_window?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 15, window: 5}, 10, nil).inside_window?
|
||||
# current_page - page < window
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:current_page => 15, :window => 6}, 10, nil).inside_window?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({current_page: 15, window: 6}, 10, nil).inside_window?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -185,7 +185,7 @@ if defined?(::Rails::Railtie) && defined?(ActionView)
|
|||
|
||||
sub_test_case '#single_gap?' do
|
||||
setup do
|
||||
@window_options = {:left => 1, :window => 1, :right => 1, :total_pages => 9}
|
||||
@window_options = {left: 1, window: 1, right: 1, total_pages: 9}
|
||||
end
|
||||
|
||||
def gap_for(page)
|
||||
|
@ -228,11 +228,11 @@ if defined?(::Rails::Railtie) && defined?(ActionView)
|
|||
|
||||
test '#out_of_range?' do
|
||||
# within range
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 5}, 4, nil).out_of_range?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 5}, 4, nil).out_of_range?
|
||||
# on last page
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 5}, 5, nil).out_of_range?
|
||||
assert_false Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 5}, 5, nil).out_of_range?
|
||||
# out of range
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({:total_pages => 5}, 6, nil).out_of_range?
|
||||
assert_true Kaminari::Helpers::Paginator::PageProxy.new({total_pages: 5}, 6, nil).out_of_range?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,13 +5,13 @@ if defined? ActiveRecord
|
|||
class ActiveRecordRelationMethodsTest < ActiveSupport::TestCase
|
||||
sub_test_case '#total_count' do
|
||||
setup do
|
||||
@author = User.create! :name => 'author'
|
||||
@author2 = User.create! :name => 'author2'
|
||||
@author3 = User.create! :name => 'author3'
|
||||
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
|
||||
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
|
||||
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
|
||||
@readers = 4.times.map { User.create! :name => 'reader' }
|
||||
@author = User.create! name: 'author'
|
||||
@author2 = User.create! name: 'author2'
|
||||
@author3 = User.create! name: 'author3'
|
||||
@books = 2.times.map {|i| @author.books_authored.create!(title: "title%03d" % i) }
|
||||
@books2 = 3.times.map {|i| @author2.books_authored.create!(title: "title%03d" % i) }
|
||||
@books3 = 4.times.map {|i| @author3.books_authored.create!(title: "subject%03d" % i) }
|
||||
@readers = 4.times.map { User.create! name: 'reader' }
|
||||
@books.each {|book| book.readers << @readers }
|
||||
end
|
||||
teardown do
|
||||
|
@ -20,7 +20,7 @@ if defined? ActiveRecord
|
|||
end
|
||||
|
||||
test 'it should reset total_count memoization when the scope is cloned' do
|
||||
assert_equal 1, User.page.tap(&:total_count).where(:name => 'author').total_count
|
||||
assert_equal 1, User.page.tap(&:total_count).where(name: 'author').total_count
|
||||
end
|
||||
|
||||
test 'it should successfully count the results when the scope includes an order which references a generated column' do
|
||||
|
@ -39,12 +39,12 @@ if defined? ActiveRecord
|
|||
end
|
||||
|
||||
test 'it should ignore the options for rails 4.1+ when total_count receives options' do
|
||||
assert_equal 7, User.page(1).total_count(:name, :distinct => true)
|
||||
assert_equal 7, User.page(1).total_count(:name, distinct: true)
|
||||
end
|
||||
|
||||
test 'it should not throw exception by passing options to count when the scope returns an ActiveSupport::OrderedHash' do
|
||||
assert_nothing_raised do
|
||||
@author.readers.by_read_count.page(1).total_count(:name, :distinct => true)
|
||||
@author.readers.by_read_count.page(1).total_count(:name, distinct: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ if defined? ActiveRecord
|
|||
class << self
|
||||
def startup
|
||||
[User, GemDefinedModel, Device].each do |m|
|
||||
1.upto(100) {|i| m.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
|
||||
1.upto(100) {|i| m.create! name: "user#{'%03d' % i}", age: (i / 10)}
|
||||
end
|
||||
super
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class PaginatableArrayTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'specifying limit and offset when initializing' do
|
||||
assert_equal 3, Kaminari::PaginatableArray.new((1..100).to_a, :limit => 10, :offset => 20).current_page
|
||||
assert_equal 3, Kaminari::PaginatableArray.new((1..100).to_a, limit: 10, offset: 20).current_page
|
||||
end
|
||||
|
||||
sub_test_case '#page' do
|
||||
|
@ -143,7 +143,7 @@ class PaginatableArrayTest < ActiveSupport::TestCase
|
|||
|
||||
sub_test_case 'when setting total count explicitly' do
|
||||
test 'array 1..10, page 5, per 10, total_count 9999' do
|
||||
arr = Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10)
|
||||
arr = Kaminari::PaginatableArray.new((1..10).to_a, total_count: 9999).page(5).per(10)
|
||||
|
||||
assert_equal 10, arr.count
|
||||
assert_equal 1, arr.first
|
||||
|
@ -152,7 +152,7 @@ class PaginatableArrayTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'array 1..15, page 1, per 10, total_count 15' do
|
||||
arr = Kaminari::PaginatableArray.new((1..15).to_a, :total_count => 15).page(1).per(10)
|
||||
arr = Kaminari::PaginatableArray.new((1..15).to_a, total_count: 15).page(1).per(10)
|
||||
|
||||
assert_equal 10, arr.count
|
||||
assert_equal 1, arr.first
|
||||
|
@ -161,7 +161,7 @@ class PaginatableArrayTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'array 1..25, page 2, per 10, total_count 15' do
|
||||
arr = Kaminari::PaginatableArray.new((1..25).to_a, :total_count => 15).page(2).per(10)
|
||||
arr = Kaminari::PaginatableArray.new((1..25).to_a, total_count: 15).page(2).per(10)
|
||||
|
||||
assert_equal 5, arr.count
|
||||
assert_equal 11, arr.first
|
||||
|
|
|
@ -73,7 +73,7 @@ class ConfigurationMethodsTest < ActiveSupport::TestCase
|
|||
|
||||
setup do
|
||||
100.times do |count|
|
||||
User.create!(:name => "User#{count}")
|
||||
User.create!(name: "User#{count}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class NavigationTest < Test::Unit::TestCase
|
|||
include Capybara::DSL
|
||||
|
||||
setup do
|
||||
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
|
||||
1.upto(100) {|i| User.create! name: "user#{'%03d' % i}" }
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
|
|
@ -6,7 +6,7 @@ class RenderingWithFormatOptionTest < Test::Unit::TestCase
|
|||
include Capybara::DSL
|
||||
|
||||
setup do
|
||||
User.create! :name => 'user1'
|
||||
User.create! name: 'user1'
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
|
Loading…
Reference in a new issue