mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Issue #310 fixed. Refactored code to use a single method to know if a tag page should be displayed.
310 - Fixed. Need to write some tests now. 310 - Fixed. Need to write some tests now. Stubbed Specs All tests are passing
This commit is contained in:
parent
016a97dd5a
commit
0689b23bbc
2 changed files with 54 additions and 0 deletions
|
@ -165,6 +165,11 @@ module Kaminari
|
|||
(@options[:current_page] - @page).abs <= @options[:window]
|
||||
end
|
||||
|
||||
def single_gap?
|
||||
(@page.to_i == @options[:current_page] - @options[:window] - 1) && (@page.to_i == @options[:left] + 1) ||
|
||||
(@page.to_i == @options[:current_page] + @options[:window] + 1) && (@page.to_i == @options[:total_pages] - @options[:right])
|
||||
end
|
||||
|
||||
# The last rendered tag was "truncated" or not
|
||||
def was_truncated?
|
||||
@last.is_a? Gap
|
||||
|
|
|
@ -176,6 +176,55 @@ describe 'Kaminari::Helpers' do
|
|||
its(:was_truncated?) { should_not be_true }
|
||||
end
|
||||
end
|
||||
describe "#single_gap?" do
|
||||
let(:window_options) do
|
||||
{
|
||||
:left => 1,
|
||||
:window => 1,
|
||||
:right => 1,
|
||||
:total_pages => 9
|
||||
}
|
||||
end
|
||||
|
||||
def gap_for(page)
|
||||
Paginator::PageProxy.new(window_options, page, nil)
|
||||
end
|
||||
|
||||
context "in case of '1 ... 4 5 6 ... 9'" do
|
||||
before { window_options[:current_page] = 5 }
|
||||
|
||||
its("gap for 2") { gap_for(2).should_not be_a_single_gap }
|
||||
its("gap for 3") { gap_for(3).should_not be_a_single_gap }
|
||||
its("gap for 7") { gap_for(7).should_not be_a_single_gap }
|
||||
its("gap for 8") { gap_for(8).should_not be_a_single_gap }
|
||||
end
|
||||
|
||||
context "in case of '1 ... 3 4 5 ... 9'" do
|
||||
before { window_options[:current_page] = 4 }
|
||||
|
||||
its("gap for 2") { gap_for(2).should be_a_single_gap }
|
||||
its("gap for 6") { gap_for(6).should_not be_a_single_gap }
|
||||
its("gap for 8") { gap_for(8).should_not be_a_single_gap }
|
||||
end
|
||||
|
||||
context "in case of '1 ... 3 4 5 ... 7'" do
|
||||
before do
|
||||
window_options[:current_page] = 4
|
||||
window_options[:total_pages] = 7
|
||||
end
|
||||
|
||||
its("gap for 2") { gap_for(2).should be_a_single_gap }
|
||||
its("gap for 6") { gap_for(6).should be_a_single_gap }
|
||||
end
|
||||
|
||||
context "in case of '1 ... 5 6 7 ... 9'" do
|
||||
before { window_options[:current_page] = 6 }
|
||||
|
||||
its("gap for 2") { gap_for(2).should_not be_a_single_gap }
|
||||
its("gap for 4") { gap_for(4).should_not be_a_single_gap }
|
||||
its("gap for 8") { gap_for(8).should be_a_single_gap }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue