Sha256: 89099a523e331e9d5930cb88f0d8a9f3c338078965658ea531837011fa13fdea

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'test_helper'

class MultipleListItemTest < ActiveSupport::TestCase
  def setup
    4.times { MultipleListItem.create }
    @items = MultipleListItem.find(:all, :order => 'id')
    @ids = @items.map(&:id)
  end

  include SimpleTests
  include SimpleGaplessTests
  
  def test_multiple_list_insertion
    item = create
    assert item.in_list?(:default)
    assert item.in_list?(:client)
    assert item.in_list?(:developer)
  end
  
  def test_multiple_list_removal_should_not_mess_other_lists
    @items.second.remove_from_list(:client)
    assert_equal_ids [1,3,4], :client
    assert_equal_ids [1,2,3,4], :default
    assert_equal_ids [1,2,3,4], :developer
  end
  
  def test_multiple_list_destroy_should_update_all_lists
    @items.second.destroy
    assert_equal_ids [1,3,4], :default
    assert_equal_ids [1,3,4], :client
    assert_equal_ids [1,3,4], :developer
  end
  
  def test_multiple_list_move
    @items.second.move_down(:client)
    assert_equal_ids [1,2,3,4], :default
    assert_equal_ids [1,3,2,4], :client
    assert_equal_ids [1,2,3,4], :developer
  end
  
  def test_multiple_list_insert_at
    @items.second.insert_at(:bottom, :client)
    assert_equal_ids [1,2,3,4], :default
    assert_equal_ids [1,3,4,2], :client
    assert_equal_ids [1,2,3,4], :developer
  end
  
  protected
    def ordered_ids(*args)
      position = 'position'
      unless args.empty?
        position = {:default => 'position', :client => 'client_position', :developer => 'developer_position'}[args.first]
      end
      MultipleListItem.find(:all, :order => position, :conditions => "#{position} IS NOT NULL").map(&:id)
    end
    
    def create(*args)
      MultipleListItem.create
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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