rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
972 stars 558 forks source link

Rails 7 fails with Enum columns #1042

Closed KDGundermann closed 1 year ago

KDGundermann commented 1 year ago

Issue

Migrating my old application to Rails 7 my tests fails on accessing the enum columns

Expected behavior

When accessing an enum column which is defined as: enum orderstate: { open: "O", closed: "C" } either order.open? or order.closed? should be truthy

Actual behavior

accessing an enum column always return false

How to reproduce

ActiveRecord Enum Test

class Datatypes < ActiveRecord::Base
  self.table_name = 'sst_datatypes'

  enum tinyint: { andromeda: 10 , bootes: 20 }
  enum char_10: { alpha: "A", beta: "B" }
end

class EnumTest < Minitest::Test
  def test_enum
    r = Datatypes.new

    r.andromeda!
    r.alpha!

    assert r.andromeda?
    refute r.bootes?

    assert r.alpha?
    refute r.beta?
  end
end

Details

KDGundermann commented 1 year ago

debug stepping through the test leads to :

    # activerecord-ssqlserver-adapter-7.0.0.0/lib/active_record/connection_adapter/sqlserver/type/data.rb
      def eql?(other)
        self.class == other.class && value == other.value
      end

where self.class => ActiveRecord::ConnectionAdapters::SQLServer::Type::Data with value "A" and other.class => String with value "A"

so its failing on self.class == other.class