require File.expand_path("../../test_helper", File.dirname(__FILE__)) class PaginationHelperTest < ActionView::TestCase include Paginary::Helpers::PaginationHelper delegate :params, :to => :controller def url_options { :controller => "widgets", :action => "index" } end def setup @klass = Widget @relation = @klass.unscoped end def builder(*args) builder = nil paginate(*args) { |b| builder = b } builder end # Items ==================================================================== test "items should return paginated relation" do assert_equal_relation @relation.paginate, builder(@relation).items end # Decorated links ========================================================== test "links should return nil if there is only one page" do assert_nil builder(@relation.paginate(:per_page => 12345)).links end test "links should return complete page links" do assert_dom_equal %Q{}, builder(@relation).links end test "page_links should return page links" do assert_dom_equal %Q{1} + %Q{2} + %Q{3} + %Q{4}, builder(@relation).page_links end test "next_link should return link to next page" do assert_dom_equal %Q{}, builder(@relation).next_link end test "next_link should return disabled link to next page if current page is last" do params[:page] = (@relation.count.to_f / 50).ceil assert_dom_equal %Q{Next >}, builder(@relation).next_link end test "previous_link should return link to previous page" do params[:page] = (@relation.count.to_f / 50).ceil assert_dom_equal %Q{}, builder(@relation).previous_link end test "previous_link should return disabled link to previous page if current page is first" do assert_dom_equal %Q{< Previous}, builder(@relation).previous_link end end