active-hash / active-hash/active_hash

Duplicate field names when using ActiveHash::Enum

Open
#322 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.4k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Environment

Ruby version: 3.3.4
ActiveHash version: 3.3.1

Description of the issue

When using ActiveHash::Enum in combination with ActiveHash::Base, the field_names method returns duplicate field names. This occurs only when enum_accessor is used.

Steps to reproduce

  1. Create an ActiveHash::Base class with some data
  2. Include ActiveHash::Enum
  3. Use enum_accessor
  4. Call .field_names on the class

Example code

class Sport < ActiveHash::Base
  self.data = [
    {
      key: "tennis",
      category: "ball",
    },
    {
      key: "soccer",
      category: "ball",
    },
  ]

  include ActiveHash::Enum
  enum_accessor :key
end

Sport.field_names
# => [:key, :category, :key, :category]

Expected behavior

The field_names method should return unique field names:

Sport.field_names
# => [:key, :category]

Additional information

This issue does not occur when ActiveHash::Enum is included without using enum_accessor:

class Sport < ActiveHash::Base
  self.data = [
    {
      key: "tennis",
      category: "ball",
    },
    {
      key: "soccer",
      category: "ball",
    },
  ]

  include ActiveHash::Enum
end

Sport.field_names
# => [:key, :category]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with ActiveHash::Base, ActiveHash::Enum, and enum_accessor, then inspect the field_names and enum_accessor entry points. Compare the returned fields with and without enum_accessor; done means Sport.field_names returns [:key, :category] without duplicates while the existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.