Skip to content

Commit

Permalink
Fix displaying of deleted variants in admin panel
Browse files Browse the repository at this point in the history
Because of the default scope added in
466251e,
the `discarded` scope currently operates on the default `kept` scope and
returns an empty set.

This fixes the scope for checking the `discarded` variants as
suggested here https://github.com/jhawthorn/discard#default-scope, to
correctly display the "deleted variants" filter in the admin variants
page.
  • Loading branch information
luca-landa committed Aug 20, 2021
1 parent 5cd7e9c commit 9dba25e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>

<% if product.variants.discarded.any? %>
<% if product.variants.with_discarded.discarded.any? %>
<div class="col-2">
<div class="field checkbox">
<label>
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/variants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<% end %>
<% end %>

<% if @variants.any? || @product.variants.discarded.any? %>
<% if @product.variants.with_discarded.any? %>
<%= render "table_filter", product: @product %>
<%= render "table", variants: @variants %>
<% else %>
Expand Down
22 changes: 22 additions & 0 deletions backend/spec/features/admin/products/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
end
end
end

context 'displaying discarded variants' do
let!(:existing_variant) { create(:variant, sku: 'existing_variant_sku', product: product) }
let!(:discarded_variant) { create(:variant, sku: 'discarded_variant_sku', product: product) }

before { discarded_variant.discard! }

it 'does not display deleted variants by default' do
visit spree.admin_product_variants_path(product)

expect(page).to have_content(existing_variant.sku)
expect(page).not_to have_content(discarded_variant.sku)
end

it 'allows to display deleted variants with a filter' do
visit spree.admin_product_variants_path(product)
check 'Show Deleted Variants'
click_button 'search'

expect(page).to have_content(discarded_variant.sku)
end
end
end

context "editing existent variant" do
Expand Down

0 comments on commit 9dba25e

Please sign in to comment.