-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Return API Users with distinct result when using Ransack #3674
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Works for me, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a spec for this?
I was not quite sure to write one. |
Yeah, I think a request spec in the file |
I was wondering if having distinct results may be something we may want to move upstream, ie. avoid that any subclass of Spree::Api::ResourceController returns duplicates, not only this one. |
@spaghetticode this was the approach used in another PR for the same issue. Please see this comment #3195 (comment) and let me know any thoughts on that. |
I think about the considerations from @kennyadsl in #3195:
However, about the use in the resource controller i am not sure. i imagine scenarios where one could want none distinct results when searching for product/variants or orders/line items etc. My first idea was to just remove
because i never would search for an user by an adress when i want to give promotions on a user basis. Its the only place where the user picker is used. Please tell me about the preferred way to go here.. |
3ca901b
to
12944a1
Compare
OK. i've added a spec test for the original approach of this PR with a distinct API Users ransack search result for users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, works for me.
@@ -144,6 +144,21 @@ module Spree | |||
expect(response.status).to eq(422) | |||
expect(json_response).to eq({ "error" => "Cannot delete record." }) | |||
end | |||
|
|||
it "returns distinct search results" do | |||
uuser = create(:user, email: '[email protected]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo here, should be user
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was meant to be an abbreviation of unique_user. i have changed the spec to be more precise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it! Yeah, I think the full version is more easily understandable.
5bd9e61
to
42a5d46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like that better as well.
@hefan can you please rebase with master? This build is failing due to an annoying flaky spec that was fixed recently. After the rebase your build should become green 💚 ... thanks 🙏 |
42a5d46
to
fb65b54
Compare
done |
Thank you Stefan! |
Description
Return API Users ransack searches with a distinct result.
Fixes #3183
-->
Checklist: