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

Fix Spree::Admin::VariantsController#index for deleted products #1804

Merged
merged 4 commits into from
Jun 7, 2017
Merged
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
5 changes: 5 additions & 0 deletions backend/app/controllers/spree/admin/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def variant_includes
def redirect_on_empty_option_values
redirect_to admin_product_variants_url(params[:product_id]) if @product.empty_option_values?
end

def parent
@parent ||= Spree::Product.with_deleted.find_by(slug: params[:product_id])
@product = @parent
end
end
end
end
52 changes: 39 additions & 13 deletions backend/spec/controllers/spree/admin/variants_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,50 @@ module Admin

describe "#index" do
let(:product) { create(:product) }
let!(:variant_1) { create(:variant, product: product) }
let!(:variant_2) { create(:variant, product: product) }
let(:params) { { product_id: product.slug } }

before { variant_2.destroy }
subject { get :index, params: params }

context "deleted is not requested" do
it "does not assign deleted variants for a requested product" do
get :index, params: { product_id: product.slug }
expect(assigns(:collection)).to include variant_1
expect(assigns(:collection)).not_to include variant_2
context "the value of @parent" do
it "is the product" do
subject
expect(assigns(:parent)).to eq product
end

context "with a deleted product" do
before { product.destroy! }

it "is the product" do
subject
expect(assigns(:parent)).to eq product
end
end
end

context "deleted is requested" do
it "assigns deleted along with non-deleted variants for a requested product" do
get :index, params: { product_id: product.slug, deleted: "on" }
expect(assigns(:collection)).to include variant_1
expect(assigns(:collection)).to include variant_2
context "the value of @collection" do
let!(:variant) { create(:variant, product: product) }
let!(:deleted_variant) { create(:variant, product: product) }

context "with deleted variants" do
before { deleted_variant.destroy }

context "when deleted is not requested" do
it "excludes deleted variants" do
subject
expect(assigns(:collection)).to include variant
expect(assigns(:collection)).not_to include deleted_variant
end
end

context "when deleted is requested" do
let(:params) { { product_id: product.slug, deleted: "on" } }

it "includes deleted variants" do
subject
expect(assigns(:collection)).to include variant
expect(assigns(:collection)).to include deleted_variant
end
end
end
end
end
Expand Down