diff --git a/lib/subjects/remover.rb b/lib/subjects/remover.rb index 68262698d..17c9592be 100644 --- a/lib/subjects/remover.rb +++ b/lib/subjects/remover.rb @@ -30,10 +30,10 @@ def cleanup private def can_be_removed? - return false if belongs_to_other_subject_set? - return false if has_been_collected_or_classified? + return false if belongs_to_other_subject_set? + return false if has_been_talked_about? return false if has_been_counted_or_retired? diff --git a/spec/lib/subjects/remover_spec.rb b/spec/lib/subjects/remover_spec.rb index 4dfe67f36..ccbf186dd 100644 --- a/spec/lib/subjects/remover_spec.rb +++ b/spec/lib/subjects/remover_spec.rb @@ -105,14 +105,30 @@ expect { SetMemberSubject.find(sms_ids) }.to raise_error(ActiveRecord::RecordNotFound) end - context 'with multiple subject sets' do - let(:alternate_subject_set) { create(:subject_set) } - let(:remover) { described_class.new(subject.id, panoptes_client, alternate_subject_set.id) } - let(:new_sms) { create(:set_member_subject, subject: subject, subject_set: alternate_subject_set) } - - it 'does not remove subjects associated with multiple set_member_subjects' do - remover.cleanup - expect(Subject.where(id: subject.id)).to exist + context 'when subject_set_id is param in init' do + let(:remover_with_subject_set) { + described_class.new(subject.id, panoptes_client, subject_set.id) + } + + it 'removes a subject that has not been used' do + remover_with_subject_set.cleanup + expect { Subject.find(subject.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'does not remove a subject that has been classified' do + create(:classification, subjects: [subject]) + expect(remover_with_subject_set.cleanup).to be_falsey + end + + context 'with multiple subject sets' do + let(:alternate_subject_set) { create(:subject_set) } + let(:remover) { described_class.new(subject.id, panoptes_client, alternate_subject_set.id) } + let(:new_sms) { create(:set_member_subject, subject: subject, subject_set: alternate_subject_set) } + + it 'does not remove subjects associated with multiple set_member_subjects' do + remover.cleanup + expect(Subject.where(id: subject.id)).to exist + end end end