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

Change Grape::API's @setup var to an Array (from a Set) #2529

Merged

Conversation

Haerezis
Copy link
Contributor

A Set lead Grape to ignore identical DSL calls when mounting an API, as they were not recorded when the API was first loaded (because identical item are ignored when added to a Set).

#2173

@dblock
Copy link
Member

dblock commented Jan 31, 2025

I like it, @ericproulx any comments/objections?

Choose a reason for hiding this comment

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

I'm not sure if creating a test with Set here makes sense. It could test only the expected behavior, and not a code that will be removed from the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kinda agree but that was what was asked so..

Copy link
Member

@dblock dblock Feb 1, 2025

Choose a reason for hiding this comment

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

@Haerezis I think we misunderstood each other :)

@stephannv is right, the only test we need is one that would fail without the change in lib/grape/api.rb. So you can remove SetupSetAPI and SetupArrayAPI, reduce the test to a minimum that fails without the change to = []. Maybe even add the scenario to an existing _spec.rb.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, sorry, we must have effectively misunderstood each other.

So in short it's not even a test changing anything about @setup, it's just a test checking that mounted routes have the correct number of settings and that none are missing. And this test would fail with the current Impl using a Set, but because I would also change the current impl to use an Array, it would NOT fail.

Sorry I was confused with the wording of a test that fails without the change to = []. I understood it as "show us a comparison test because we don't accept the change without the comparison".

At least the current spec have shown beyond the shadow of a doubt that using a Set introduce a bug.

I'll come back quickly with what you asked.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, English is my third language ;) Thank you!

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

@stephannv is right here, my bad. Thanks for you help!

Copy link
Member

@dblock dblock Feb 1, 2025

Choose a reason for hiding this comment

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

@Haerezis I think we misunderstood each other :)

@stephannv is right, the only test we need is one that would fail without the change in lib/grape/api.rb. So you can remove SetupSetAPI and SetupArrayAPI, reduce the test to a minimum that fails without the change to = []. Maybe even add the scenario to an existing _spec.rb.

@Haerezis
Copy link
Contributor Author

Haerezis commented Feb 1, 2025

@dblock @stephannv I've redone the specs. Remove old file, added the tests to api_remount_spec.rb (seems like the right place for it).
I can confirm that if I keep a Set for @setup, the second "it" fail. With an array, it passes.

Copy link
Member

@dblock dblock 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, let's put the CHANGELOG in the right place?

CHANGELOG.md Outdated
@@ -11,6 +11,7 @@
* [#2514](https://github.com/ruby-grape/grape/pull/2514): Add rails 8.0 to CI - [@ericproulx](https://github.com/ericproulx).
* [#2516](https://github.com/ruby-grape/grape/pull/2516): Dynamic registration for parsers, formatters, versioners - [@ericproulx](https://github.com/ericproulx).
* [#2518](https://github.com/ruby-grape/grape/pull/2518): Add ruby 3.4 to CI - [@ericproulx](https://github.com/ericproulx).
* [#2529](https://github.com/ruby-grape/grape/pull/2529): Change Grape::API's `@setup` var to an array (from a set) - [@Haerezis](https://github.com/Haerezis).
Copy link
Member

Choose a reason for hiding this comment

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

This is actually a bug fix, should go below under fixes with something like "Fix route_setting used with multiple mount".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the changelog and put the change in fixes section with a title I thought fit better.

@dblock
Copy link
Member

dblock commented Feb 2, 2025

Merci @Haerezis!

@dblock dblock merged commit af1a6a2 into ruby-grape:master Feb 2, 2025
63 checks passed
@Haerezis
Copy link
Contributor Author

Haerezis commented Feb 2, 2025

my pleasure. Sorry for the misunderstanding :) Thanks for the quick replies !

@Haerezis Haerezis deleted the feature/grape-api-setup-var-array branch February 2, 2025 20:50
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.

3 participants