Skip to content

Commit

Permalink
Hide soft deleted prices from admin product view
Browse files Browse the repository at this point in the history
The `product.prices` relation has been changed in 3f4578a
to make eager loading possible, but this now shows soft deleted
prices in the admin product prices tab.

Hiding them again to restore previous behavior.
  • Loading branch information
tvdeyen committed Jan 3, 2023
1 parent 785995d commit 9da5ebf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/prices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PricesController < ResourceController
def index
params[:q] ||= {}

@search = @product.prices.accessible_by(current_ability, :index).ransack(params[:q])
@search = @product.prices.kept.accessible_by(current_ability, :index).ransack(params[:q])
@master_prices = @search.result
.currently_valid
.for_master
Expand Down
12 changes: 9 additions & 3 deletions backend/spec/controllers/spree/admin/prices_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
context "when only given a product" do
let(:product) { create(:product) }

let!(:deleted_master_price) { create(:price, variant: product.master).tap(&:discard!) }

subject { get :index, params: { product_id: product.slug } }

it { is_expected.to be_successful }

it 'assigns usable instance variables' do
subject
expect(assigns(:search)).to be_a(Ransack::Search)
expect(assigns(:variant_prices)).to eq(product.prices.for_variant)
expect(assigns(:master_prices)).to eq(product.prices.for_master)
expect(assigns(:variant_prices)).to be_empty
expect(assigns(:master_prices)).to eq(product.prices.kept.for_master)
expect(assigns(:master_prices)).to_not include(deleted_master_price)
expect(assigns(:product)).to eq(product)
end
end
Expand All @@ -28,16 +31,19 @@
let(:variant) { create(:variant) }
let(:product) { variant.product }

let!(:deleted_variant_price) { create(:price, variant: variant).tap(&:discard!) }

subject { get :index, params: { product_id: product.slug, variant_id: variant.id } }

it { is_expected.to be_successful }

it 'assigns usable instance variables' do
subject
expect(assigns(:search)).to be_a(Ransack::Search)
expect(assigns(:variant_prices)).to eq(product.prices.for_variant)
expect(assigns(:variant_prices)).to eq(product.prices.kept.for_variant)
expect(assigns(:master_prices)).to eq(product.prices.for_master)
expect(assigns(:variant_prices)).to include(variant.default_price)
expect(assigns(:variant_prices)).to_not include(deleted_variant_price)
expect(assigns(:product)).to eq(product)
end
end
Expand Down

0 comments on commit 9da5ebf

Please sign in to comment.