@@ -750,4 +750,42 @@ class CollectionsControllerTest < ActionController::TestCase
750750 assert_select 'h4' , text : 'Deleted resource'
751751 end
752752 end
753+
754+ test 'can edit collection with deleted resource' do
755+ sign_in @collection . user
756+
757+ m1 = materials ( :biojs )
758+ m2 = materials ( :interpro )
759+ ci1 = @collection . items . create! ( resource : materials ( :biojs ) , order : 2 , comment : 'hello' )
760+ ci2 = @collection . items . create! ( resource : materials ( :interpro ) , order : 1 , comment : 'hello!!' )
761+ assert_no_difference ( 'CollectionItem.count' ) do
762+ m1 . destroy!
763+ end
764+
765+ get :edit , params : { id : @collection }
766+ assert_response :success
767+ end
768+
769+ test 'can update collection with deleted resource' do
770+ sign_in @collection . user
771+
772+ m1 = materials ( :biojs )
773+ m2 = materials ( :interpro )
774+ ci1 = @collection . items . create! ( resource : materials ( :biojs ) , order : 2 , comment : 'hello' )
775+ ci2 = @collection . items . create! ( resource : materials ( :interpro ) , order : 1 , comment : 'hello!!' )
776+ assert_no_difference ( 'CollectionItem.count' ) do
777+ m1 . destroy!
778+ end
779+
780+ params = { id : ci1 . id , resource_type : ci1 . resource_type , resource_id : ci1 . resource_id }
781+
782+ patch :update , params : { id : @collection . id ,
783+ collection : {
784+ items_attributes : { '1' : params . merge ( comment : 'Some comment' ) }
785+ }
786+ }
787+
788+ assert_redirected_to collection_path ( assigns ( :collection ) )
789+ assert_equal 'Some comment' , ci1 . reload . comment
790+ end
753791end
0 commit comments