Skip to content

Commit

Permalink
Issue kaminari#310 fixed. Refactored code to use a single method to k…
Browse files Browse the repository at this point in the history
…now 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
  • Loading branch information
anthonyalberto authored and yuki24 committed Mar 30, 2014
1 parent 016a97d commit 0689b23
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/kaminari/helpers/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def inside_window?
(@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
Expand Down
49 changes: 49 additions & 0 deletions spec/helpers/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,55 @@
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

0 comments on commit 0689b23

Please sign in to comment.