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

Ticket #11398: tests_to_show_how_integer_and_float_columns_behave_differently.diff

File tests_to_show_how_integer_and_float_columns_behave_differently.diff, 1.6 kB (added by h-lame, 5 months ago)

Tests that will show how integer columns and float columns behave differently

  • activerecord/test/schema/schema.rb

    old new  
    424424    t.integer :sponsorable_id 
    425425    t.string :sponsorable_type 
    426426  end 
     427   
     428  create_table :floats_and_ints, :force => true do |t| 
     429    t.integer :an_integer_column 
     430    t.float :a_float_column 
     431  end 
    427432end 
  • activerecord/test/cases/base_test.rb

    old new  
    12641264    assert_equal BigDecimal("1000234000567.95"), m1.big_bank_balance 
    12651265  end 
    12661266 
     1267  class FloatsAndInts < ActiveRecord::Base; end 
     1268 
     1269  # Mirroring the test_integers_as_nil test way above 
     1270  def test_floats_as_nil 
     1271    test = FloatsAndInts.create(:a_float_column => '') 
     1272    assert_nil FloatsAndInts.find(test.id).a_float_column 
     1273  end 
     1274   
     1275  def test_we_get_integers_as_values_for_our_integer_columns_after_setting_other_values 
     1276    [[], {}, Date.today, true].each do |v| 
     1277      f = FloatsAndInts.create(:an_integer_column => v) 
     1278      assert f.an_integer_column.class <= Integer 
     1279    end 
     1280  end 
     1281   
     1282  def test_we_get_floats_as_values_for_our_float_columns_after_setting_other_values 
     1283    [[], {}, Date.today, true].each do |v| 
     1284      f = FloatsAndInts.create(:a_float_column => v) 
     1285      assert f.a_float_column.class <= Float 
     1286    end 
     1287  end 
     1288   
    12671289  def test_auto_id 
    12681290    auto = AutoId.new 
    12691291    auto.save