aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/enum_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2015-02-13 23:51:43 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2015-02-13 23:51:43 -0800
commite076d7290d523759900ee1ba3c9843c7f324adc7 (patch)
tree98997cf8cdd7d26d8b5b6f8ca511bc3bd24ba167 /activerecord/test/cases/enum_test.rb
parent53f3803b52bfe2f4a8e0550a0c5d9df1865d90cb (diff)
downloadrails-e076d7290d523759900ee1ba3c9843c7f324adc7.tar.gz
rails-e076d7290d523759900ee1ba3c9843c7f324adc7.tar.bz2
rails-e076d7290d523759900ee1ba3c9843c7f324adc7.zip
Fixed a bug where NULLs are casted into the first enum value
Diffstat (limited to 'activerecord/test/cases/enum_test.rb')
-rw-r--r--activerecord/test/cases/enum_test.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 41685cbc39..025e39c02d 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -168,19 +168,24 @@ class EnumTest < ActiveRecord::TestCase
assert_equal "'unknown' is not a valid status", e.message
end
+ test "NULL values from database should be casted to nil" do
+ Book.where(id: @book.id).update_all("status = NULL")
+ assert_nil @book.reload.status
+ end
+
test "assign nil value" do
@book.status = nil
- assert @book.status.nil?
+ assert_nil @book.status
end
test "assign empty string value" do
@book.status = ''
- assert @book.status.nil?
+ assert_nil @book.status
end
test "assign long empty string value" do
@book.status = ' '
- assert @book.status.nil?
+ assert_nil @book.status
end
test "constant to access the mapping" do