@@ -309,7 +309,9 @@ module Alchemy
309309 end
310310
311311 describe "#delete_multiple" do
312- subject { delete :delete_multiple , params : { picture_ids : picture_ids } }
312+ subject do
313+ delete :delete_multiple , params : { picture_ids : picture_ids }
314+ end
313315
314316 it_behaves_like :redirecting_to_picture_library do
315317 let ( :subject ) do
@@ -319,12 +321,8 @@ module Alchemy
319321 end
320322 end
321323
322- let ( :deletable_picture ) do
323- mock_model ( "Picture" , name : "pic of the pig" , deletable? : true )
324- end
325-
326- let ( :not_deletable_picture ) do
327- mock_model ( "Picture" , name : "pic of the chick" , deletable? : false )
324+ let ( :picture ) do
325+ build_stubbed ( :alchemy_picture )
328326 end
329327
330328 context "no picture_ids given" do
@@ -337,49 +335,12 @@ module Alchemy
337335 end
338336
339337 context "picture_ids given" do
340- context "all are deletable" do
341- let ( :picture_ids ) { deletable_picture . id . to_s }
342-
343- before do
344- allow ( Picture ) . to receive ( :find ) . and_return ( [ deletable_picture ] )
345- end
346-
347- it "should delete the pictures give a notice about deleting them" do
348- subject
349- expect ( flash [ :notice ] ) . to match ( "successfully" )
350- end
351- end
352-
353- context "deletable and not deletable" do
354- let ( :picture_ids ) { "#{ deletable_picture . id } ,#{ not_deletable_picture . id } " }
355-
356- before do
357- allow ( Picture ) . to receive ( :find ) . and_return ( [ deletable_picture , not_deletable_picture ] )
358- end
338+ let ( :picture_ids ) { [ picture . id ] }
359339
360- it "should give a warning for the non deletable pictures and delete the others" do
361- expect ( deletable_picture ) . to receive ( :destroy )
362- subject
363- expect ( flash [ :warn ] ) . to match ( "could not be deleted" )
364- end
365- end
366-
367- context "with error happening" do
368- let ( :picture_ids ) { deletable_picture . id . to_s }
369-
370- before do
371- expect ( Picture ) . to receive ( :find ) . and_raise ( "yada" )
372- end
373-
374- it "sets error message" do
375- subject
376- expect ( flash [ :error ] ) . not_to be_blank
377- end
378-
379- it "redirects to index" do
380- subject
381- expect ( response ) . to redirect_to admin_pictures_path
382- end
340+ it "enqueues the picture delete job" do
341+ subject
342+ expect ( DeletePictureJob ) . to have_been_enqueued . with ( picture . id . to_s )
343+ expect ( flash [ :notice ] ) . to match ( "Pictures will be deleted now" )
383344 end
384345 end
385346 end
0 commit comments