mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Bugfix introduced by last commit
- fixed bug created by last commit - refactored to new method respond_with_error - need for 2 cases in request spec: html & turbo
This commit is contained in:
@@ -40,10 +40,7 @@ module Spree
|
||||
|
||||
redirect_to location_after_save
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
@errors = e.record.errors.map(&:full_message)
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render :edit }
|
||||
end
|
||||
respond_with_error(e)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -55,10 +52,7 @@ module Spree
|
||||
|
||||
redirect_to location_after_save
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
@errors = e.record.errors.map(&:full_message)
|
||||
respond_with do |format|
|
||||
format.turbo_stream { render :edit }
|
||||
end
|
||||
respond_with_error(e)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -108,6 +102,14 @@ module Spree
|
||||
:attachment, :viewable_id, :alt
|
||||
)
|
||||
end
|
||||
|
||||
def respond_with_error(error)
|
||||
@errors = error.record.errors.map(&:full_message)
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@object) }
|
||||
format.turbo_stream { render :edit }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,12 +55,26 @@ RSpec.describe "/admin/products/:product_id/images", type: :request do
|
||||
end
|
||||
|
||||
describe "POST /admin/products/:product_id/images" do
|
||||
subject { post(spree.admin_product_images_path(product), params:) }
|
||||
|
||||
it_behaves_like "updating images"
|
||||
end
|
||||
describe "POST /admin/products/:product_id/images with turbo" do
|
||||
subject { post(spree.admin_product_images_path(product), params:, as: :turbo_stream) }
|
||||
|
||||
it_behaves_like "updating images"
|
||||
end
|
||||
|
||||
describe "PATCH /admin/products/:product_id/images/:id" do
|
||||
let!(:product) { create(:product_with_image) }
|
||||
subject {
|
||||
patch(spree.admin_product_image_path(product, product.image), params:)
|
||||
}
|
||||
|
||||
it_behaves_like "updating images"
|
||||
end
|
||||
|
||||
describe "PATCH /admin/products/:product_id/images/:id with turbo" do
|
||||
let!(:product) { create(:product_with_image) }
|
||||
subject {
|
||||
patch(spree.admin_product_image_path(product, product.image), params:, as: :turbo_stream)
|
||||
|
||||
Reference in New Issue
Block a user