active-hash / active-hash/active_hash
Duplicate field names when using ActiveHash::Enum
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
- Create an ActiveHash::Base class with some data
- Include ActiveHash::Enum
- Use enum_accessor
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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