lib/hobo_fields/field_spec.rb in hobofields-0.8.10 vs lib/hobo_fields/field_spec.rb in hobofields-0.9.0

- old
+ new

@@ -15,10 +15,22 @@ attr_accessor :model, :name, :type, :position, :options TYPE_SYNONYMS = [[:timestamp, :datetime]] + begin + MYSQL_COLUMN_CLASS = ActiveRecord::ConnectionAdapters::MysqlColumn + rescue NameError + MYSQL_COLUMN_CLASS = NilClass + end + + begin + SQLITE_COLUMN_CLASS = ActiveRecord::ConnectionAdapters::SQLiteColumn + rescue NameError + SQLITE_COLUMN_CLASS = NilClass + end + def sql_type options[:sql_type] or begin if native_type?(type) type else @@ -53,20 +65,27 @@ TYPE_SYNONYMS.each do |synonyms| if t.in? synonyms return col_spec.type.in?(synonyms) end end - t = col_spec.type + t == col_spec.type end def different_to?(col_spec) !same_type?(col_spec) || begin check_attributes = [:null, :default] - check_attributes += [:precision, :scale] if sql_type == :decimal + check_attributes += [:precision, :scale] if sql_type == :decimal && !col_spec.is_a?(SQLITE_COLUMN_CLASS) # remove when rails fixes https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2872 + check_attributes -= [:default] if sql_type == :text && col_spec.is_a?(MYSQL_COLUMN_CLASS) check_attributes << :limit if sql_type.in?([:string, :text, :binary, :integer]) - check_attributes.any? { |k| col_spec.send(k) != self.send(k) } + check_attributes.any? do |k| + if k==:default && sql_type==:datetime + col_spec.default.try.to_datetime != default.try.to_datetime + else + col_spec.send(k) != self.send(k) + end + end end end private