Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7477: fix_broken_active_support_to_query_tests.diff

File fix_broken_active_support_to_query_tests.diff, 1.5 kB (added by chadfowler, 2 years ago)

Patch for active support hash tests

  • activesupport/test/core_ext/hash_ext_test.rb

    old new  
    534534  end 
    535535   
    536536  def test_nested_conversion 
    537     assert_equal 'person[name]=Nicholas&person[login]=seckar', 
    538       {:person => {:name => 'Nicholas', :login => 'seckar'}}.to_query 
     537    actual_value = {:person => {:name => 'Nicholas', :login => 'seckar'}}.to_query 
     538    expected = ['person[name]=Nicholas&person[login]=seckar',  
     539                'person[login]=seckar&person[name]=Nicholas'] 
     540    assert_equal_one_of(expected, actual_value) 
    539541  end 
    540542   
    541543  def test_multiple_nested 
    542     assert_equal 'account[person][id]=20&person[id]=10', 
    543       {:person => {:id => 10}, :account => {:person => {:id => 20}}}.to_query 
     544    expected = ['account[person][id]=20&person[id]=10', 'person[id]=10&account[person][id]=20'] 
     545    actual_value = {:person => {:id => 10}, :account => {:person => {:id => 20}}}.to_query 
     546    assert_equal_one_of(expected, actual_value) 
    544547  end 
    545548   
    546549  def test_array_values 
    547550    assert_equal 'person[id][]=10&person[id][]=20', 
    548551      {:person => {:id => [10, 20]}}.to_query 
    549552  end 
     553   
     554  def assert_equal_one_of(list_of_potential_expected_matches, actual_value) 
     555    assert list_of_potential_expected_matches.any? {|value| 
     556        value == actual_value 
     557      }, "Expected one of:\n#{list_of_potential_expected_matches.join(', OR ')} but got:\n#{actual_value}" 
     558  end 
    550559end