require 'spec_helper' describe NeatPages::Helpers::Navigation do include ViewHelpers describe "#generate" do let(:pagination) { double() } context "with a pagination that doesn't need pages" do before { pagination.stub(:paginated?).and_return(false) } let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) } context "when generating the navigation" do specify { builder.generate.should be_empty } end end context "with a 40 items pagination starting at 20 and having 10 items per page" do before do pagination.stub(:paginated?).and_return(true) pagination.stub(:current_page).and_return(3) pagination.stub(:next?).and_return(true) pagination.stub(:next_page).and_return(4) pagination.stub(:offset).and_return(20) pagination.stub(:per_page).and_return(10) pagination.stub(:previous?).and_return(true) pagination.stub(:previous_page).and_return(2) pagination.stub(:total_items).and_return(40) pagination.stub(:total_pages).and_return(4) end let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) } context "when generating the navigation" do specify { builder.generate.should eql '
' } end end context "with a 40 items pagination starting at 30 and having 10 items per page" do before do pagination.stub(:paginated?).and_return(true) pagination.stub(:current_page).and_return(3) pagination.stub(:next?).and_return(false) pagination.stub(:next_page).and_return(nil) pagination.stub(:offset).and_return(30) pagination.stub(:per_page).and_return(10) pagination.stub(:previous?).and_return(true) pagination.stub(:previous_page).and_return(2) pagination.stub(:total_items).and_return(40) pagination.stub(:total_pages).and_return(4) end let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) } context "when generating the navigation" do specify { builder.generate.should eql ' ' } end end context "with a 200 items pagination starting at 110 and having 10 items per page" do before do pagination.stub(:paginated?).and_return(true) pagination.stub(:current_page).and_return(12) pagination.stub(:next?).and_return(true) pagination.stub(:next_page).and_return(13) pagination.stub(:offset).and_return(110) pagination.stub(:per_page).and_return(10) pagination.stub(:previous?).and_return(true) pagination.stub(:previous_page).and_return(11) pagination.stub(:total_items).and_return(200) pagination.stub(:total_pages).and_return(20) end let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) } context "when generating the navigation" do specify { builder.generate.should eql ' ' } end end end end