Skip to content

Commit

Permalink
Fix dirty handling of nullable non-integer numeric columns [#1692 sta…
Browse files Browse the repository at this point in the history
…te:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
  • Loading branch information
ckozus authored and lifo committed Jan 16, 2009
1 parent 0e92f67 commit 5ed119c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions activerecord/test/cases/dirty_test.rb
Expand Up @@ -21,6 +21,10 @@ def check_changes
end
end

class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
end

class DirtyTest < ActiveRecord::TestCase
def test_attribute_changes
# New record - no changes.
Expand Down Expand Up @@ -68,6 +72,26 @@ def test_nullable_number_not_marked_as_changed_if_new_value_is_blank
end
end

def test_nullable_decimal_not_marked_as_changed_if_new_value_is_blank
numeric_data = NumericData.new

["", nil].each do |value|
numeric_data.bank_balance = value
assert !numeric_data.bank_balance_changed?
assert_nil numeric_data.bank_balance_change
end
end

def test_nullable_float_not_marked_as_changed_if_new_value_is_blank
numeric_data = NumericData.new

["", nil].each do |value|
numeric_data.temperature = value
assert !numeric_data.temperature_changed?
assert_nil numeric_data.temperature_change
end
end

def test_nullable_integer_zero_to_string_zero_not_marked_as_changed
pirate = Pirate.new
pirate.parrot_id = 0
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/schema/schema.rb
Expand Up @@ -252,6 +252,7 @@ def create_table(*args, &block)
t.decimal :world_population, :precision => 10, :scale => 0
t.decimal :my_house_population, :precision => 2, :scale => 0
t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78
t.float :temperature
end

create_table :orders, :force => true do |t|
Expand Down

0 comments on commit 5ed119c

Please sign in to comment.