-
-
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
Cleanup - Specify Spree:: namespace in all Product calls #1615
Conversation
I don't quite understand.. if we have code like: class Product
def m
puts "Product::m"
end
end
module Spree
class Product
def m
puts "Spree::Product::m"
end
end
class Caller
def call_product
Product.new.m
end
end
end
Spree::Caller.new.call_product shouldn't the |
@flyfy1 |
I'm with @flyfy1 on this one in that I'm not sure under what circumstances the wrong product will be called, could it be something like code you've copy-pasted into a decorator that is causing the issue? I tried a local repo and couldn't recreate the undesired behavior. |
Hmm. Moved past that code and can't dig up the point of reproduction. I'll reopen this PR if I can get a handle on it. |
@fylooi When I was reading Rails Docs upon module loading today, at section 6.2, it mentioned sth below (cannot copy with style so I just include the screenshot): I think it's something related to your issue (and which also means, seems to make ur pull request valid) |
@flyfy1 Ensuring that all models in controllers are consistently invoked with the If you guys are okay with this, I can do the changes and update this PR. |
@fylooi I haven't looked through the documentation yet.. nor do I sure if u should continue with the PR. probably need comments from the core team. Meanwhile, I think it's definitely helpful to create a sample App and surface the problem.. |
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.
I'm ok with adding the model module namespace.
It has no downsides for us having them (besides bytecount ^_^).
I think it even makes the code better understandable. Not everybody is super aware of Ruby/Rails module constant lookup. And if this helps avoiding super hard to track down bugs, even better.
From me 👍
@@ -173,7 +173,7 @@ def self.property_conditions(property) | |||
|
|||
# Can't use add_search_scope for this as it needs a default argument | |||
def self.available(available_on = nil, currency = nil) | |||
Spree::Deprecation.warn("The second currency argument on Product.available has no effect, and is deprecated", caller) if currency | |||
Spree::Deprecation.warn("The second currency argument on Spree::Product.available has no effect, and is deprecated", caller) if currency | |||
joins(master: :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on || Time.current) |
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.
Here we have one Product
missing its module namespace
ba42917
to
2ac7c38
Compare
Updated the PR to cover all model invocations in controllers and models. |
I'm also fine with this. Quoting the Zen of Python:
;) |
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.
Good by me, thanks for seeing this through
Thank you |
Managed to reproduce one case. Documenting the steps for reference. This is as of v1.4. Assuming you have a
The |
Some calls to Product are not namespaced with Spree::. This leads to a collision if the including application has an existing Product model defined.