2016-10-12 05:44:41 +09:00
|
|
|
# frozen_string_literal: true
|
2016-11-19 16:51:21 +09:00
|
|
|
require 'test_helper'
|
2011-02-05 23:20:06 +09:00
|
|
|
|
2016-11-19 16:51:21 +09:00
|
|
|
class PaginatorHelperTest < ActiveSupport::TestCase
|
|
|
|
include Kaminari::Helpers
|
|
|
|
|
|
|
|
def template
|
2011-02-05 23:20:06 +09:00
|
|
|
stub(r = Object.new) do
|
|
|
|
render.with_any_args
|
|
|
|
params { {} }
|
2011-02-27 23:25:16 +09:00
|
|
|
options { {} }
|
2011-02-05 23:20:06 +09:00
|
|
|
url_for {|h| "/foo?page=#{h[:page]}"}
|
2014-03-15 15:18:54 -07:00
|
|
|
link_to { "<a href='#'>link</a>" }
|
2016-06-22 19:13:56 +09:00
|
|
|
output_buffer { defined?(ActionView) ? ::ActionView::OutputBuffer.new : ::ActiveSupport::SafeBuffer.new }
|
2011-02-05 23:20:06 +09:00
|
|
|
end
|
|
|
|
r
|
|
|
|
end
|
2014-03-15 15:18:54 -07:00
|
|
|
|
2016-11-19 16:51:21 +09:00
|
|
|
test 'view helper methods delegated to template' do
|
2016-11-22 22:16:57 +09:00
|
|
|
paginator = Paginator.new(template, params: {})
|
2016-11-19 16:51:21 +09:00
|
|
|
assert_equal "<a href='#'>link</a>", paginator.link_to('link', '#')
|
2014-03-15 15:18:54 -07:00
|
|
|
end
|
2011-02-13 18:25:07 +09:00
|
|
|
|
2016-11-19 16:51:21 +09:00
|
|
|
sub_test_case '#params' do
|
|
|
|
setup do
|
2016-11-22 22:16:57 +09:00
|
|
|
@paginator = Paginator.new(template, params: {controller: 'foo', action: 'bar'})
|
2016-11-19 16:51:21 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'when params has no form params' do
|
|
|
|
assert_equal({'controller' => 'foo', 'action' => 'bar'}, @paginator.page_tag(template).instance_variable_get('@params'))
|
2011-02-16 22:52:55 +09:00
|
|
|
end
|
2016-11-19 16:51:21 +09:00
|
|
|
|
|
|
|
test 'when params has form params' do
|
|
|
|
stub(template).params do
|
2016-11-22 22:16:57 +09:00
|
|
|
{authenticity_token: 'token', commit: 'submit', utf8: 'true', _method: 'patch'}
|
2014-03-12 20:23:13 -07:00
|
|
|
end
|
|
|
|
|
2016-11-19 16:51:21 +09:00
|
|
|
assert_equal({'controller' => 'foo', 'action' => 'bar'}, @paginator.page_tag(template).instance_variable_get('@params'))
|
2014-03-12 20:23:13 -07:00
|
|
|
end
|
2011-02-27 23:25:16 +09:00
|
|
|
end
|
|
|
|
|
2016-11-19 16:51:21 +09:00
|
|
|
test '#param_name' do
|
2016-11-22 22:16:57 +09:00
|
|
|
paginator = Paginator.new(template, param_name: :pagina)
|
2016-11-19 16:51:21 +09:00
|
|
|
assert_equal :pagina, paginator.page_tag(template).instance_variable_get('@param_name')
|
2011-02-13 18:25:07 +09:00
|
|
|
end
|
2011-02-05 23:20:06 +09:00
|
|
|
end
|