Skip to content

Commit

Permalink
Fixing an issue with rails 5 enums.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zdennis committed Feb 26, 2016
1 parent 6dae70c commit a77b192
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/activerecord-import/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@sferik

sferik Mar 23, 2016

Contributor

@zdennis The conclusion of this elsif condition is the same as the if condition above it. Does it make sense to combine them into a single statement joined by an || or did you want to keep them separate for some reason?

else
model.read_attribute_before_type_cast(name.to_s)
model.read_attribute_before_type_cast(name)
end
end
# end
Expand Down

0 comments on commit a77b192

Please sign in to comment.