From a77b192300a1aaf0fe32a10640ad3fa90caa8aa5 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index 73501c1e..62f4ed12 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -339,10 +339,13 @@ 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 respond_to?(:defined_enums) && defined_enums.has_key?(name) # ActiveRecord 5 + model.read_attribute(name) + elsif model.class.column_defaults[name].is_a?(Integer) + model.read_attribute(name) else - model.read_attribute_before_type_cast(name.to_s) + model.read_attribute_before_type_cast(name) end end # end