You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Undeclared attribute type for enum 'status'. Enums must be backed by a database column or declared with an explicit type via `attribute`.
Here is a reproducible example:
require"bundler/inline"gemfile(true)dosource"https://rubygems.org"gem'pry'gem'rspec'gem"activerecord",'7.1.2'gem'activerecord-nulldb-adapter','1.0.1',require: falseendrequire"active_record"require'nulldb_rspec'require"rspec/autorun"schema=<<-SCHEMAActiveRecord::Schema[7.1].define do create_enum "post_status", ["draft", "published"] create_table "posts", force: :cascade do |t| t.enum "status", default: "draft", enum_type: "post_status" endendSCHEMAschema_filename=File.join(__dir__,'schema.rb')File.write(schema_filename,schema)ActiveRecord::Base.establish_connection(adapter: :nulldb,schema: schema_filename)require_relative'schema'classPost < ActiveRecord::Baseenumstatus: %i[draftpublished]endRSpec.describe'enum'doit'has status column'doexpect(Post.column_names).toinclude('status')endit'does not raise an error'doexpect{Post.new}.not_toraise_errorendend
The exception comes from ActiveRecord::Enum#_enum (gems/activerecord-7.1.2/lib/active_record/enum.rb:250).
attribute(name, **options)do |subtype|
249: binding.pry=>250: ifsubtype == ActiveModel::Type.default_value251: raise"Undeclared attribute type for enum '#{name}'. Enums must be" \
252: " backed by a database column or declared with an explicit type" \
253: " via `attribute`."254: end
With NullDB subtype, in the above, is the same as ActiveModel::Type.default_value, thus the error:
The error we get is:
Here is a reproducible example:
The exception comes from
ActiveRecord::Enum#_enum
(gems/activerecord-7.1.2/lib/active_record/enum.rb:250).With NullDB
subtype
, in the above, is the same asActiveModel::Type.default_value
, thus the error:With regular adapter they are different and thus no error:
It's been great having unit tests use this gem. Any ideas greatly appreciated!
The text was updated successfully, but these errors were encountered: