2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:50:17 -04:00
|
|
|
require "abstract_unit"
|
2020-02-27 17:12:09 -05:00
|
|
|
require "action_view/renderer/collection_renderer"
|
2012-09-16 16:45:08 -04:00
|
|
|
|
2014-07-16 13:13:42 -04:00
|
|
|
class PartialIterationTest < ActiveSupport::TestCase
|
2012-09-16 16:45:08 -04:00
|
|
|
def test_has_size_and_index
|
2014-07-16 13:28:39 -04:00
|
|
|
iteration = ActionView::PartialIteration.new 3
|
2012-09-16 16:45:08 -04:00
|
|
|
assert_equal 0, iteration.index, "should be at the first index"
|
|
|
|
assert_equal 3, iteration.size, "should have the size"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_first_is_true_when_current_is_at_the_first_index
|
2014-07-16 13:28:39 -04:00
|
|
|
iteration = ActionView::PartialIteration.new 3
|
2012-09-16 16:45:08 -04:00
|
|
|
assert iteration.first?, "first when current is 0"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_first_is_false_unless_current_is_at_the_first_index
|
2014-07-16 13:28:39 -04:00
|
|
|
iteration = ActionView::PartialIteration.new 3
|
|
|
|
iteration.iterate!
|
2018-05-12 22:26:10 -04:00
|
|
|
assert_not iteration.first?, "not first when current is 1"
|
2012-09-16 16:45:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_is_true_when_current_is_at_the_last_index
|
2014-07-16 13:28:39 -04:00
|
|
|
iteration = ActionView::PartialIteration.new 3
|
|
|
|
iteration.iterate!
|
|
|
|
iteration.iterate!
|
2012-09-16 16:45:08 -04:00
|
|
|
assert iteration.last?, "last when current is 2"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_is_false_unless_current_is_at_the_last_index
|
2014-07-16 13:28:39 -04:00
|
|
|
iteration = ActionView::PartialIteration.new 3
|
2018-05-12 22:26:10 -04:00
|
|
|
assert_not iteration.last?, "not last when current is 0"
|
2012-09-16 16:45:08 -04:00
|
|
|
end
|
|
|
|
end
|