Sha256: 4d84c019d8dd786ad48fa5d333794ab5ac14b9ad9aef2260e848936d7a928cb9

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "test_helper"

module Flexirails
  class ArrayViewTest < ActiveSupport::TestCase
    Point = Struct.new(:x, :y)

    class TestView < ::Flexirails::ArrayView
      def columns
        %w(x, y)
      end
    end

    attr_reader :items
    def setup
      @items = []
      10.times do |i|
        @items << Point.new(i, i)
      end
    end

    test "test_view correct total" do
      assert_equal items.size, TestView.new({}, items).total
    end

    test "returns all items if per_page > total" do
      view = TestView.new({ :per_page => "25" }, items)
      assert_equal view.items, view.rows
    end

    test "returns correct items for current_page" do
      view = TestView.new({ :per_page => "3", :current_page => "1" }, items)
      assert_equal view.items[0..2], view.rows

      refute view.has_prev_path
      assert view.has_next_path

      view = TestView.new({ :per_page => "3", :current_page => "2" }, items)
      assert_equal view.items[3..5], view.rows

      assert view.has_prev_path
      assert view.has_next_path
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flexirails-0.1.0 test/models/flexirails/array_view_test.rb