spree-contrib / spree_wishlist

Wishlist extension for Spree Commerce.

Home Page:http://guides.spreecommerce.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Specs fail on spree master because of required belongs_to

bbonislawski opened this issue · comments

Since Rails 5.1 we should explicitly define that belongs_to relation is optional. WishedProducts fails to save because it doesn't have variant created in specs. We should add optional param to belongs_to relations:

Here's the problem:

(byebug) @wished_product
#<Spree::WishedProduct id: nil, variant_id: nil, wishlist_id: 2, remark: "Some remark..", created_at: nil, updated_at: nil, quantity: 1>
(byebug) @wished_product.valid?
false
(byebug) @wished_product.errors
#<ActiveModel::Errors:0x007fb92c3eb830 @base=#<Spree::WishedProduct id: nil, variant_id: nil, wishlist_id: 2, remark: "Some remark..", created_at: nil, updated_at: nil, quantity: 1>, @messages={:variant=>["must exist"]}, @details={:variant=>[{:error=>:blank}]}>

I want to tackle this issue. Should I add the optional flag to every belongs_to relation?

Yeah. I think it should fix the issue.

instead of adding the flag to every belongs_to relation you could consider setting this in the configs:
Rails.application.config.active_record.belongs_to_required_by_default