Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix typo - (parent) in location_after_destroy. (#11256)

Matthew Kennedy1178d901fd11
diff --git a/backend/app/controllers/spree/admin/images_controller.rb b/backend/app/controllers/spree/admin/images_controller.rb
index cc43b7d382..d765abb033 100644
--- a/backend/app/controllers/spree/admin/images_controller.rb
+++ b/backend/app/controllers/spree/admin/images_controller.rb
@@ -13,7 +13,7 @@ module Spree
private
def location_after_destroy
- spree.admin_product_images_url(@arent)
+ spree.admin_product_images_url(parent)
end
def location_after_save
diff --git a/backend/spec/controllers/spree/admin/images_controller_spec.rb b/backend/spec/controllers/spree/admin/images_controller_spec.rb
index 9ac760f3ae..8e77da7027 100644
--- a/backend/spec/controllers/spree/admin/images_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/images_controller_spec.rb
@@ -22,42 +22,83 @@ module Spree
end
describe '#destroy' do
- subject(:send_request) do
- delete :destroy, params: { product_id: product, id: image, format: :js }
- end
+ context 'when request format is javascript' do
+ subject(:send_request) do
+ delete :destroy, params: { product_id: product, id: image, format: :js }
+ end
- let(:image) { create(:image, viewable: product.master) }
+ let(:image) { create(:image, viewable: product.master) }
- shared_examples 'correct response' do
- it { expect(assigns(:image)).to eq(image) }
- it { expect(response).to have_http_status(:ok) }
- end
+ shared_examples 'correct response' do
+ it { expect(assigns(:image)).to eq(image) }
+ it { expect(response).to have_http_status(:ok) }
+ end
- context 'will successfully destroy image' do
- describe 'returns response' do
- before { send_request }
+ context 'will successfully destroy image' do
+ describe 'returns response' do
+ before { send_request }
- it_behaves_like 'correct response'
- it { expect(flash[:success]).to eq('Image has been successfully removed!') }
+ it_behaves_like 'correct response'
+ it { expect(flash[:success]).to eq('Image has been successfully removed!') }
+ end
end
- end
- context 'cannot destroy image of other product' do
- let(:other_product) { create(:product, stores: [store]) }
- let(:image) { create(:image, viewable: other_product) }
+ context 'cannot destroy image of other product' do
+ let(:other_product) { create(:product, stores: [store]) }
+ let(:image) { create(:image, viewable: other_product) }
- it { expect(send_request).to redirect_to(spree.admin_product_images_path(product)) }
+ it { expect(send_request).to redirect_to(spree.admin_product_images_path(product)) }
- it do
- send_request
- expect(flash[:error]).to eq('Image is not found')
+ it do
+ send_request
+ expect(flash[:error]).to eq('Image is not found')
+ end
+ end
+
+ context 'cannot destroy image of product from different store' do
+ let(:product) { create(:product, stores: [create(:store)]) }
+
+ it { expect { send_request }.to raise_error(ActiveRecord::RecordNotFound) }
end
end
- context 'cannot destroy image of product from different store' do
- let(:product) { create(:product, stores: [create(:store)]) }
+ context 'when request format is html' do
+ subject(:send_request) do
+ delete :destroy, params: { product_id: product, id: image, format: :html }
+ end
- it { expect { send_request }.to raise_error(ActiveRecord::RecordNotFound) }
+ let(:image) { create(:image, viewable: product.master) }
+
+ shared_examples 'correct response' do
+ it { expect(assigns(:image)).to eq(image) }
+ it { expect(response).to have_http_status(:ok) }
+ end
+
+ context 'will successfully destroy image' do
+ describe 'returns response' do
+ before { send_request }
+
+ it { expect(send_request).to redirect_to(spree.admin_product_images_path(product)) }
+ end
+ end
+
+ context 'cannot destroy image of other product' do
+ let(:other_product) { create(:product, stores: [store]) }
+ let(:image) { create(:image, viewable: other_product) }
+
+ it { expect(send_request).to redirect_to(spree.admin_product_images_path(product)) }
+
+ it do
+ send_request
+ expect(flash[:error]).to eq('Image is not found')
+ end
+ end
+
+ context 'cannot destroy image of product from different store' do
+ let(:product) { create(:product, stores: [create(:store)]) }
+
+ it { expect { send_request }.to raise_error(ActiveRecord::RecordNotFound) }
+ end
end
end
end