Sha256: 5f8b32ddc3efa008b52ba0bfb529852309bda7d0bc1ccf08309867d25b329fc4

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module SimpleGaplessTests
  # Insert and Remove Tests
  def test_simple_gapless_insert_on_list_after_create
    assert_equal @ids, ordered_ids
    @items.each_with_index do |item, index|
      assert item.in_list?
    end
    assert_equal [1,2,3,4], positions
  end
  
  def test_simple_gapless_insert_at
    @items.fourth.insert_at(@items.second.list_position)
    # List: [1,4,2,3]
    assert_equal [1,3,4,2], positions
    
    @items.first.insert_at(@items.third.list_position)
    # List: [4,2,3,1]
    assert_equal [4,2,3,1], positions
    
    @items.third.insert_at(@items.fourth.list_position)
    # List: [3,4,2,1]
    assert_equal [4,3,1,2], positions
    
    @items.second.insert_at(@items.fourth.list_position)
    # List: [3,2,4,1]
    assert_equal [4,2,1,3], positions
  end

  def test_simple_gapless_remove_from_list
    @items.second.remove_from_list
    # List: [1,3,4]
    assert_equal [1,nil,2,3], positions
  end

  def test_simple_gapless_remove_from_list_after_destroy
    @items.second.destroy
    # List: [1,3,4]
    assert_equal [1,2,3], positions(@items.second)
  end
  
  def test_simple_gapless_remove_from_list_shifts_lower_items_up
    @items.first.remove_from_list
    # List: [2,3,4]
    assert_equal [nil,1,2,3], positions
  end
  
  def test_simple_gapless_destroy_shifts_lower_items_up
    @items.first.destroy
    # List: [2,3,4]
    assert_equal [1,2,3], positions(@items.first)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aguids-positionable-0.2.1 test/rails_root/test/simple_gapless_tests.rb
aguids-positionable-0.2.2 test/rails_root/test/simple_gapless_tests.rb