Sha256: bf743d201ee9ae74b35d25654a113f6b8728caffe7f214156fe94c27728e1f07

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'minitest_helper'

MiniTest::Unit.autorun

class TestSortableSeedYaml < MiniTest::Unit::TestCase
  def setup
    @sortable_seed = SortableSeedYaml.new(TestData::Seed::RandomOrder)
  end
  
  def test_sort_by
    # Case: sort by one sort key
    sort_by_id = @sortable_seed.sort_by{|record| record.attributes["id"] }
    assert_equal(TestData::Seed::SortById, sort_by_id)
    
    # Case: sort by 
    #       first sort key : category_id
    #       second sort key: id
    sort_by_category_id_and_id = 
      @sortable_seed.sort_by do |record|
        [ record.attributes["category_id"], record.attributes["id"] ]
      end

    assert_equal(TestData::Seed::SortByCategoryIdAndId, sort_by_category_id_and_id)
  end
  
  def test_sort
    # Case: sort by 
    #       first sort key : category_id -- ASC
    #       second sort key: id -- DES
    #
    # note: I don't think there is such use cases, but I made.
    sort_by_category_id_asc_and_id_desc =
      @sortable_seed.sort do |a, b|
        first_compare = (a.attributes["category_id"] <=> b.attributes["category_id"])
        first_compare.nonzero? || -(a.attributes["id"] <=> b.attributes["id"])
      end
      
    assert_equal(TestData::Seed::SortByCategoryId_ASC_And_Id_DESC, sort_by_category_id_asc_and_id_desc)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seed_sort_toolkit-0.0.1 test/test_sortable_seed_yaml.rb