Skip to content
This repository was archived by the owner on Feb 23, 2020. It is now read-only.

Commit 9339e40

Browse files
committed
respond properly if variant not found
1 parent 902859f commit 9339e40

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/spree/wombat/handler/update_product_handler.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ class UpdateProductHandler < ProductHandlerBase
77

88
def process
99
id = params.delete(:id)
10-
product = Spree::Variant.where(is_master: true, sku: params[:sku]).first.product
11-
return response("Cannot find product with SKU #{params[:sku]}!", 500) unless product
10+
variant = Variant.where(is_master: true, sku: params[:sku]).first
11+
12+
if variant.nil? || variant.product.nil?
13+
return response("Cannot find product with SKU #{params[:sku]}!", 500)
14+
end
15+
16+
product = variant.product
17+
1218
# Disable the after_touch callback on taxons
1319
Spree::Product.skip_callback(:touch, :after, :touch_taxons)
1420

spec/lib/spree/wombat/handler/update_product_handler_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
module Spree
44
module Wombat
55
describe Handler::UpdateProductHandler do
6-
76
before do
87
img_fixture = File.open(File.expand_path('../../../../../fixtures/thinking-cat.jpg', __FILE__))
98
URI.stub(:parse).and_return img_fixture
109
end
1110

11+
it "respond properly if product not found" do
12+
handler = described_class.new Hub::Samples::Product.request.to_json
13+
response = handler.process
14+
expect(response.summary).to match "Cannot find product with SKU"
15+
end
16+
1217
context "#process" do
1318
let!(:message) do
1419
hsh = ::Hub::Samples::Product.request

0 commit comments

Comments
 (0)