Skip to content

Different prefixes are not detected by with_prefix #1659

@deniciocode

Description

@deniciocode

Description

When having two enums with the same string values in two different prefixes
will not be distinguished by with_prefix and the tests pass.

Reproduction Steps

class ContactSuggestion < ApplicationRecord
  STATUSES = { pending: 'pending', denied: 'denied', agreed: 'agreed' }.freeze

  enum :candidate_user_status, STATUSES, prefix: :user
  enum :candidate_contact_status, STATUSES, prefix: :contact
end
describe 'validations' do
  subject(:described_instance) { described_class.new }

  it do
    expect(described_instance).to define_enum_for(:candidate_user_status)
      .with_values(agreed: 'agreed', pending: 'pending', denied: 'denied')
      .with_prefix(:user) 
  end

  it do
    expect(described_instance).to define_enum_for(:candidate_contact_status)
      .with_values(agreed: 'agreed', pending: 'pending', denied: 'denied')
      .with_prefix(:user) # Wrong prefix here
  end
end

Expected behavior

As a user I would expect and hint by a failing spec that points out that candidate_contact_status is not prefixed by :user

Actual behavior

The test passes with not harm or information.

System configuration

shoulda_matchers version: 6.4.0
rails version: 8.0.1
ruby version: 3.3.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions