-
Notifications
You must be signed in to change notification settings - Fork 235
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
Collection fix #415
base: master
Are you sure you want to change the base?
Collection fix #415
Conversation
this should be handled in the calling code section: cell('...', model, context: option[:context].merge({...})) |
@timoschilling Sorry, I don't understand. ViewModel#call is the public entry point. I could fix it in the calling code in rails-cells but then rails-cells would need to be aware of the collection handling logic, which doesn't seem right. The issue is described here: #413 (comment) |
I don't understand that.. the context is passed into collections, there's tests here: https://github.com/apotonick/cells/blob/master/test/context_test.rb#L18 Could you provide a test that fails for your fix? |
Sure, I'll add a test. The symptom of the problem is in rails, given this: = cell(:comment, collection: Comment.recent, context: { current_user: The contents of the context hash will be over-written with a new hash Rails-cells isn't collection aware so it sees an empty options hash (as the The problem is on the boundary between rails-cells and cells so it's not I don't understand that.. the context is passed into collections, there's Could you provide a test that fails for your fix? — |
|
||
merged_options = model.merge(options) | ||
merged_options[:context] = merged_context if merged_context.any? | ||
merged_options = nil if merged_options.empty? |
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.
This line is useless, merged_options
always contains the :collection
key.
The problem is that you overwrite the context in your example. You need to merge your |
# wrong
= cell(:comment, collection: Comment.recent, context: { current_user:
current_user } )
# right
= cell(:comment, collection: Comment.recent, context: option[:context].merge(current_user: current_user)) |
@apotonick This cells-rails fork includes a demonstration of this problem samstickland/cells-rails@9540a5e The added test fails in the existing version of cells, but passes using my PR above. @timoschilling But context is overwritten inside of the cells gem when it merges the two options hashes - one provided by the user, one provided by rails-cells. |
@apotonick @timoschilling Right, I've rewritten that test case to be contained within a single file, rather than spread out across routes, controllers etc. samstickland/cells-rails@3eae04f
|
If you run that test case you will see the problem straight away! ;) |
@timoschilling Do you mean this line? I'm not sure where I'm looking at to see the linenote:
I had to add that line to make some of the existing test cases pass in the cells test suite. I'll need to remove it and run it again to remember which ones they were. @apotonick , @timoschilling I don't proposing that we merge this PR in it's current state, I threw it together - along with the rough test case - to demonstrate the bug in collection handling ;) Like I said it could be argued that the bug is on the boundary between cells and cells-rails - hence why my proposed fix is currently in cells and the test case is in cells-rails. I'm happy to try to explain this again, but if you run the test case above you'll instantly see the problem! And then I'd a steer as to where this should be fixed, and I'll tidy up this PR. |
I'm aware it's not good practice to comment on a PR/issue and clutter it with "me too!" (one should normally just 'subscribe'), but since this hasn't been touched by the maintainers in a month, I'll give @samstickland a boost and say that this affects our Rails/Cells setup, as well - and that the proposed PR works as intended. |
Hahaha thanks @toastercup I'm having a look today! |
Any news? :) |
me too! :P |
Well I guess I'll be using the code from that commit until it is merged to the main branch, because I really need that. |
Just giving you a heads-up: we are planning to introduce a new collection API with a dedicated collection cell that you can override, etc. That is no excuse, though, why I haven't merged and fine-tuned this PR, though 😊. Though. |
@apotonick I'm happy to tidy this up myself, but this is the first time I've even really received an acknowledgement from a maintainer that this problem is genuine! ;) I also, as mentioned above, made a demo test-case for this here: samstickland/cells-rails@9540a5e But as you can see the test is in cells-rails and the fix is in cells. Hardly ideal. If you can let me know what needs to happen or be tidied up for this to be accepted I'll make it happen! |
It's actually a bug in this gem, so you're doing right in posting that here. It shouldn't merge the options hash that way! |
This PR is still open, but I think the fix has made it onto master via another route? |
This PR fixes passing context into collections. This probably only affects Cells in rails (since cells-rails is providing the default context that is breaking the collection handling), so there's a potential discussion as to whether this fix should go in Cells or Cells-rails.
If you think the fix is appropriate here let me know and I'll add a test case to this PR.