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

Do not try to display discarded products/variants. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/spree/wishlist.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Spree::Wishlist < ActiveRecord::Base
belongs_to :user, class_name: 'Spree::User'
has_many :wished_products, dependent: :destroy
has_many :visible_wished_products,
-> { joins(:variant).where(spree_variants: {deleted_at: nil}) },
class_name: "Spree::WishedProduct"
before_create :set_access_hash

validates :name, presence: true
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/wishlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</tr>
</thead>
<tbody id="line_items">
<% if @wishlist.wished_products.size > 0 %>
<% @wishlist.wished_products.each do |wish|
<% if @wishlist.visible_wished_products.size > 0 %>
<% @wishlist.visible_wished_products.each do |wish|
variant = wish.variant
product = variant.product %>
<tr class="<%= cycle('', 'alt') %>">
Expand Down
28 changes: 28 additions & 0 deletions spec/features/spree/wishlist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@
sign_in_as! user
end

context 'show', :focus do
background do
wishlist.wished_products << Spree::WishedProduct.new(variant: product.master)
end

context 'wishlist has a current product' do
scenario 'it displays the product' do
visit spree.account_path
click_link wishlist.name

expect(page).to have_content(product.name)
end
end

context 'wishlist has a discarded product' do
background do
product.discard
end

scenario 'it does not display the product' do
visit spree.account_path
click_link wishlist.name

expect(page).to_not have_content(product.name)
end
end
end

context 'edit' do
scenario 'edit a wishlists name' do
visit_edit_wishlist
Expand Down