Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError error on enum with _default option set #207

Closed
clinejj opened this issue Dec 15, 2021 · 0 comments · Fixed by #208
Closed

NoMethodError error on enum with _default option set #207

clinejj opened this issue Dec 15, 2021 · 0 comments · Fixed by #208

Comments

@clinejj
Copy link

clinejj commented Dec 15, 2021

We have a class with the following definition:

# == Schema Information
#
# Table name: product_filters
#
#  id               :bigint           not null, primary key
#  display_text_key :string
#  filter_type      :integer          default("select_multiple")
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#
# Indexes
#
#  index_product_filters_on_display_text_key  (display_text_key) UNIQUE
#
class ProductFilter < ApplicationRecord
  enum filter_type: { select_multiple: 0, select_single: 1, range: 2, text: 3 }, _default: :select_multiple
end

when running bin/rails rbs_rails:all --trace we get the following error:

** Invoke rbs_rails:all (first_time)
** Invoke rbs_rails:generate_rbs_for_models (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute rbs_rails:generate_rbs_for_models
rails aborted!
NoMethodError: undefined method `each' for :select_multiple:Symbol
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:246:in `block (2 levels) in enum_instance_methods'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:243:in `each'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:243:in `block in enum_instance_methods'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:242:in `each'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:242:in `enum_instance_methods'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:37:in `klass_decl'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:25:in `generate'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/active_record.rb:11:in `class_to_rbs'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/rake_task.rb:45:in `block (2 levels) in def_generate_rbs_for_models'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/rake_task.rb:38:in `each'
/gem_cache/ruby/3.0.0/gems/rbs_rails-0.9.0/lib/rbs_rails/rake_task.rb:38:in `block in def_generate_rbs_for_models'
/gem_cache/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'

The task completes as expected if the _default option is commented out, like so:

class ProductFilter < ApplicationRecord
  enum filter_type: { select_multiple: 0, select_single: 1, range: 2, text: 3 } #, _default: :select_multiple
end
@clinejj clinejj changed the title NoMethodError: undefined method each' for :Symbol` with enum NoMethodError: undefined method 'each' for :Symbol with enum Dec 15, 2021
@clinejj clinejj changed the title NoMethodError: undefined method 'each' for :Symbol with enum NoMethodError error on enum with _default option set Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant