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

Improve product -> master attributes delegation #2474

Merged
merged 6 commits into from
Jan 2, 2018

Conversation

kennyadsl
Copy link
Member

With #2427 we found out that we are delegating some methods to master variant incorrectly. Some of the attributes defined in MASTER_ATTRIBUTES only have their setter or getter corresponding method on the variant side.

I made this little script to verify which one would trigger a NoMethodError:

product = Spree::Product.last

Spree::Product::MASTER_ATTRIBUTES.each do |attribute|
  begin  
    product.send(attribute) 
  rescue Exception => e  
    puts "#{attribute} has no getter" if e.is_a? NoMethodError 
  end
  
  begin
    product.send("#{attribute}=", 'test') 
  rescue Exception => e  
    puts "#{attribute} has no setter" if e.is_a? NoMethodError 
  end
end

Running this in console produces this output:

currency has no getter
currency has no setter
rebuild_vat_prices has no getter
price_in has no setter
price_for has no setter
amount_in has no setter

This leads me in changing how we are defining those delegations.

This ensures we can have a better git history for future changes
when we'll need to add/change/remove some items in that list.
Surprisingly, we do not have this method anymore on products and variants:

product.currency
NoMethodError: undefined method `currency' for #<Spree::Variant:0x007fdd2242a548>

product.currency = 'EUR'
NoMethodError: undefined method `currency=' for #<Spree::Variant:0x007fdd2242a548>
This method has only its attr_writer defined on Spree::Variant
price_in, price_for and amount_in have no setter methods
@kennyadsl kennyadsl self-assigned this Dec 24, 2017
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Thank you, much more clear. Sweet!

@kennyadsl kennyadsl merged commit 1e1ff30 into solidusio:master Jan 2, 2018
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