File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -78,9 +78,14 @@ def update
7878
7979 def destroy
8080 purchase = current_organization . purchases . find ( params [ :id ] )
81- PurchaseDestroyService . call ( purchase )
81+ begin
82+ PurchaseDestroyService . call ( purchase )
83+ rescue => e
84+ flash [ :error ] = e . message
85+ else
86+ flash [ :notice ] = "Purchase #{ params [ :id ] } has been removed!"
87+ end
8288
83- flash [ :notice ] = "Purchase #{ params [ :id ] } has been removed!"
8489 redirect_to purchases_path
8590 end
8691
Original file line number Diff line number Diff line change 301301 sign_in organization_admin
302302 end
303303
304- it "allows deletion of a purchase" do
305- visit "#{ subject } /#{ purchase . id } "
306- expect ( page ) . to have_link ( "Delete" )
307- accept_confirm do
308- click_on "Delete"
304+ context "When the purchase remains in storage location" do
305+ it "allows deletion of a purchase" do
306+ visit "#{ subject } /#{ purchase . id } "
307+ expect ( page ) . to have_link ( "Delete" )
308+ accept_confirm do
309+ click_on "Delete"
310+ end
311+ expect ( page ) . to have_content "Purchase #{ purchase . id } has been removed!"
312+ expect ( page ) . to have_content "0 (Total)"
313+ end
314+ end
315+
316+ context "When the purchase has been distributed" do
317+ it "delete a purchase should get an error" do
318+ allow ( PurchaseDestroyService ) . to receive ( :call ) . with ( purchase ) . and_raise ( InventoryError )
319+
320+ visit "#{ subject } /#{ purchase . id } "
321+ expect ( page ) . to have_link ( "Delete" )
322+ accept_confirm do
323+ click_on "Delete"
324+ end
325+
326+ expect ( page ) . to have_css ( ".alert.error.alert-danger" )
309327 end
310- expect ( page ) . to have_content "Purchase #{ purchase . id } has been removed!"
311- expect ( page ) . to have_content "0 (Total)"
312328 end
313329 end
314330end
You can’t perform that action at this time.
0 commit comments