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

Support for activerecord-typedstore v1.5.0 #976

Merged
merged 5 commits into from
Jun 12, 2022

Conversation

etiennebarrie
Copy link
Member

@etiennebarrie etiennebarrie commented Jun 9, 2022

Motivation

The internals changed in byroot/activerecord-typedstore#91 and store.accessors is now a Hash instead of an Array. The value is the name of the method for which we need to compile the RBI.

Implementation

I implemented it in a way that should be compatible with the previous version.

Instead of flat_map(&:accessors).empty?, which used to give [] but now gives [{}] if a store has no field, I use all?, and I use the fact that Hash objects yield two values to each to preserve the previous behavior.

Tests

I made the changes first without the gem bump, to show it's still the same behavior, then the gem bump and the additional test for the new feature.

Closes #949

@etiennebarrie etiennebarrie force-pushed the activerecord-typedstore-v1.5.0 branch from 7789751 to ccbc44a Compare June 9, 2022 14:14
@Morriar Morriar requested a review from a team June 9, 2022 17:19
Comment on lines +102 to +103
store_data.accessors.each do |accessor, name|
field = store_data.fields.fetch(accessor)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this change means we're not going to be retro-compatible with activerecord-typedstore < 1.5.0?

Copy link
Collaborator

Choose a reason for hiding this comment

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

btw: #949

Copy link
Member Author

Choose a reason for hiding this comment

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

No fields is still a Hash. Previously we got a NoMethodError type_sym, using fetch would have shown the error at the moment it was the most logical.

Sorry I missed #949. I think it's missing some things, I'll comment there, but feel free to close this PR here if that makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

But this change here going from fields[accessor] to fields.fetch(accessor) is not strictly necessary.

Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

I like this change, thank you!

@etiennebarrie
Copy link
Member Author

Copied the test from @KaanOzkan testing against 1.4.0.

Otherwise you get "Resolving dependencies..." sometimes as the first
line.
For speed reasons, the project is only setup once, but if a gem is
added, it can leak to other tests.

This saves Gemfile and Gemfile.lock before all `generate` tests, and
restores it before each of the test, which avoids re-creating the whole
project, or even just running `bundle install` which takes a couple of
seconds.
@etiennebarrie
Copy link
Member Author

So I got some flakiness with this commit, where installing the activerecord-typedstore gem would leak to other tests and result in a bunch of unexpected RBI files being generated for dependencies of that gem like activerecord or activemodel. Instead of just fixing the single test (I could save and restore Gemfile/Gemfile.lock just in the new test), I went ahead and made the setup a bit more reproducible for all tests. I also found a flakiness issue where one gem was added but not bundled installed, so in some cases it caused an additional Resolving dependencies... line coming from Bundler. Let me know if you'd rather have those in a separate PR.

@paracycle
Copy link
Member

Instead of just fixing the single test (I could save and restore Gemfile/Gemfile.lock just in the new test), I went ahead and made the setup a bit more reproducible for all tests.

I like this approach and I think it is fine having it inside this PR. I think we can extract that to the general @project setup/teardown, so that we don't have to worry about this kind of cross-test leaking.

I also found a flakiness issue where one gem was added but not bundled installed, so in some cases it caused an additional Resolving dependencies... line coming from Bundler. Let me know if you'd rather have those in a separate PR.

This is also a good fix and I think we can make this better later as well, e.g. by running bundle install, if needed, inside the @project.tapioca call itself.

@paracycle paracycle merged commit 3327062 into main Jun 12, 2022
@paracycle paracycle deleted the activerecord-typedstore-v1.5.0 branch June 12, 2022 10:48
@shopify-shipit shopify-shipit bot temporarily deployed to production July 7, 2022 17:53 Inactive
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.

None yet

4 participants