diff --git a/app/controllers/api/v1/subject_sets_controller.rb b/app/controllers/api/v1/subject_sets_controller.rb index 5684483c2..23cb2fb10 100644 --- a/app/controllers/api/v1/subject_sets_controller.rb +++ b/app/controllers/api/v1/subject_sets_controller.rb @@ -112,7 +112,7 @@ def add_relation(resource, relation, value) if relation == :subjects && value.is_a?(Array) #ids is returning duplicates even though the AR Relations were uniq subject_ids_to_link = new_items(resource, relation, value).distinct.ids - unless Subject.where(id: subject_ids_to_link).count == value.count + unless Subject.where(id: subject_ids_to_link, activated_state: 'active').count == value.count raise BadLinkParams.new("Error: check the subject set and all the subjects exist.") end new_sms_values = subject_ids_to_link.map do |subject_id| diff --git a/spec/controllers/api/v1/subject_sets_controller_spec.rb b/spec/controllers/api/v1/subject_sets_controller_spec.rb index 360db0c9c..e9f40cc8e 100644 --- a/spec/controllers/api/v1/subject_sets_controller_spec.rb +++ b/spec/controllers/api/v1/subject_sets_controller_spec.rb @@ -227,6 +227,15 @@ expect(response).to have_http_status(:ok) end end + + context 'when a linking resource has been soft deleted' do + it 'returns a 422 with a missing subject' do + last_subject = subjects.last + last_subject.update(activated_state: 'inactive') + run_update_links + expect(response).to have_http_status(:unprocessable_entity) + end + end end context 'with illegal link properties' do