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

New Valkyrie::ID#== is not symmetric over String #820

Closed
no-reply opened this issue Feb 7, 2020 · 1 comment · Fixed by #821
Closed

New Valkyrie::ID#== is not symmetric over String #820

no-reply opened this issue Feb 7, 2020 · 1 comment · Fixed by #821

Comments

@no-reply
Copy link
Contributor

no-reply commented Feb 7, 2020

After Valkyrie.config.id_string_equality = true:

Valkyrie::ID.new('an_id') == 'an_id' # => true
'an_id' == Valkyrie::ID.new('an_id') #=> false

Complicating things further, these objects are symmetrically equal for purposes of #<=>:

Valkyrie::ID.new('an_id') <=> 'an_id' #=> 0
'an_id' <=> Valkyrie::ID.new('an_id') #=> 0

This can be fixed by providing a Valkyrie::ID#to_str, which will cause String to use Valkyrie::ID#== to determine == style equality.

@no-reply
Copy link
Contributor Author

no-reply commented Feb 7, 2020

The implementation of #== in 83bf5d5 may be problematic for other reasons:

class Moomin
  def to_s
    'moomin'
  end
end

Moomin.new == Valkyrie::ID.new('moomin') # => false
Valkyrie::ID.new('moomin') == Moomin.new # => true

no-reply pushed a commit that referenced this issue Feb 7, 2020
no-reply pushed a commit that referenced this issue Feb 7, 2020
no-reply pushed a commit that referenced this issue Feb 7, 2020
no-reply pushed a commit that referenced this issue Feb 7, 2020
no-reply pushed a commit that referenced this issue Feb 7, 2020
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