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

Make ID <=> String equality symmetrical #821

Merged
merged 4 commits into from
Mar 12, 2020
Merged

Make ID <=> String equality symmetrical #821

merged 4 commits into from
Mar 12, 2020

Conversation

no-reply
Copy link
Contributor

@no-reply no-reply commented Feb 7, 2020

Fixes #820

@no-reply no-reply force-pushed the string-equality branch 3 times, most recently from 1579ce6 to aaa6da5 Compare February 7, 2020 21:56
@no-reply
Copy link
Contributor Author

no-reply commented Feb 7, 2020

do we need to make definition of #to_str contingent on the equality configuration? or is it okay to introduce it in a bugfix or minor release?

Since we now support symmetric equality with `String` objects of the same
lexical value, there's no need for a specialized ID class specific
implementation. Instead, we always cast `self` with `#to_str` and delegate `#==`
to `other`.

In the case we are comapring two `Valkyrie::ID` objects, `id_1 == id_2`, we cast
the first and compare using `id_2 == id_1.to_str`; in turn, this casts `id_2`
and we end up with `id_1.to_str == id_2.to_str`. This sounds complicated but it
involves fewer comparisons and method calls that the old implementation, which
compared both `id_1.class == id_2.class` and then ran `Array` equality via
`id_1.state == id_2.state`.
jeremyf
jeremyf previously approved these changes Feb 8, 2020
end

it 'is equal to the equivalent string' do
expect('123' == resource.thumbnail_id).to be true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for completeness, I would also add:

  expect(resource.thumbnail_id == '123').to be true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the test on https://github.com/samvera/valkyrie/pull/821/files/d9f0895504c17dcd3056e783a24d7bab12742642#diff-b8273acc787c804ca17fe99782a00941R61, right?

this version needs to embed the equality check in the expectation to satisfy rubocop-rspec, which gets mad if you put a literal value in expect's actual. expect('123').to eq resource.thumbnail_id is equivalent, but fails style check (:

@tpendragon
Copy link
Collaborator

I have to run this through Figgy and see if it works okay without being in the conditional config. I don't really have the bandwidth atm, but I'll get to it when I can. Thank you!

@no-reply
Copy link
Contributor Author

would it be helpful if someone else could run the figgy test suite with this?

@no-reply
Copy link
Contributor Author

no-reply commented Mar 9, 2020

Wondering how i can help move this forward?

@tpendragon
Copy link
Collaborator

Sorry it has taken so long. I'm fiddling with it now, but I've actually discovered Figgy's throwing a ton of the deprecations, which makes me think there's some underlying library issue doing direct compares. I'm poking around.

@tpendragon
Copy link
Collaborator

tpendragon commented Mar 9, 2020

https://github.com/samvera/valkyrie/blob/master/lib/valkyrie/types.rb#L87 is throwing a deprecation error in our test suite, @no-reply can you just switch the order of those checks as part of this PR?

@tpendragon
Copy link
Collaborator

@no-reply I can confirm this works in Figgy. If you make that switch in the check above I'd be happy to merge.

Copy link
Collaborator

@tpendragon tpendragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request additional change to switch a conditional so the library doesn't throw a deprecation error.

tpendragon
tpendragon previously approved these changes Mar 10, 2020
@tpendragon
Copy link
Collaborator

I applied that change and it looks like that deprecation message never gets hit anymore. I'll have to look at adding a test or something, but have to move to local stuff for today.

Copy link
Member

@cjcolvar cjcolvar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

@tpendragon tpendragon merged commit f527fd0 into master Mar 12, 2020
@tpendragon tpendragon deleted the string-equality branch March 12, 2020 15:01
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 this pull request may close these issues.

New Valkyrie::ID#== is not symmetric over String
4 participants