From 2a4e6f8232096b1c26702dc357be7a07c4637aac Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Fri, 26 Feb 2016 11:49:47 -0500 Subject: [PATCH] Fixing an issue with rails 5 enums. Don't use read_before_type_cast for enums as that will return a string for the enum key which is incorrect. For example, this fixes failing tests when running: AR_VERSION=5.0 bundle exec rake test:mysql2 --- lib/activerecord-import/import.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index 73501c1e..55a5ecc1 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -339,10 +339,11 @@ def import_helper( *args ) # this next line breaks sqlite.so with a segmentation fault # if model.new_record? || options[:on_duplicate_key_update] column_names.map do |name| - if model.class.column_defaults[name.to_s].is_a? Integer - model.read_attribute(name.to_s) + name = name.to_s + if model.class.column_defaults[name].is_a?(Integer) || defined_enums.has_key?(name) + model.read_attribute(name) else - model.read_attribute_before_type_cast(name.to_s) + model.read_attribute_before_type_cast(name) end end # end