Skip to content

Commit

Permalink
close #104 abstractable.remove_abstractions does
Browse files Browse the repository at this point in the history
not clean up abstractor_abstraction_group_members
and abstractor_abstraction_groups

* However, left a failing spec related to another
issue unearthed.  That the creation of
abstractor abstraction groups does not
seem to respect namespaces.  References #126
  • Loading branch information
mgurley committed Jun 30, 2015
1 parent e1d58f7 commit a615ed2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/abstractor/abstractable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def remove_abstractions(options = {})
options = { abstractor_abstractions: abstractor_abstractions }.merge(options)
abstractor_abstractions = abstractor_abstractions_by_abstraction_schemas(options)
end
abstractor_abstraction_groups = []
abstractor_abstractions.each do |abstractor_abstraction|
if abstractor_abstraction.abstractor_abstraction_group
abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group
end
end
abstractor_abstraction_groups.uniq!
abstractor_abstractions.each do |abstractor_abstraction|
if !options[:only_unreviewed] || (options[:only_unreviewed] && abstractor_abstraction.unreviewed?)
abstractor_abstraction.abstractor_suggestions.each do |abstractor_suggestion|
Expand All @@ -195,9 +202,15 @@ def remove_abstractions(options = {})
abstractor_abstraction.abstractor_indirect_sources.each do |abstractor_indirect_source|
abstractor_indirect_source.destroy
end

abstractor_abstraction.destroy
end
end
abstractor_abstraction_groups.each do |abstractor_abstraction_group|
if abstractor_abstraction_group.reload.abstractor_abstraction_group_members.empty?
abstractor_abstraction_group.destroy
end
end
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/abstractor/methods/models/abstractor_abstraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.included(base)
base.send :has_many, :abstractor_abstraction_sources, :through => :abstractor_abstractor_suggestions
base.send :has_many, :abstractor_indirect_sources

base.send :has_one, :abstractor_abstraction_group_member
base.send :has_one, :abstractor_abstraction_group_member, dependent: :destroy
base.send :has_one, :abstractor_abstraction_group, :through => :abstractor_abstraction_group_member
base.send :has_one, :abstractor_abstraction_schema, :through => :abstractor_subject

Expand Down
14 changes: 11 additions & 3 deletions spec/models/abstractor/imaging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,24 @@
end

#removing abstractions
it "removes abstractions in a namespace", focus: false do
it "removes abstractions and groups in a namespace", focus: false do
@imaging_exam.abstract(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id)

expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).size).to eq(5)
expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id).size).to eq(5)

abstractor_abstraction_groups = []
@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).each do |abstractor_abstraction|
if abstractor_abstraction.abstractor_abstraction_group
abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group
end
end
@imaging_exam.remove_abstractions(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id)
expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).size).to eq(5)
expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id).size).to eq(0)
abstractor_abstraction_groups.each do |abstractor_abstraction_group|
expect(Abstractor::AbstractorAbstractionGroup.find(abstractor_abstraction_group.id)).to be_nil
end
end

it "will not remove reviewed abstractions in a namespace (if so instructed)", focus: false do
Expand Down Expand Up @@ -466,12 +475,11 @@
expect(@imaging_exam.reload.detect_abstractor_abstraction(@abstractor_subject_abstraction_schema_diagnosis_duration_2)).to be_nil
end

#removing abstractions
it "removes abstractions in a namespace", focus: false do
@imaging_exam.abstract(namespace_type: @abstractor_subject_abstraction_schema_moomin_minor.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_minor.namespace_id)

expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_minor.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_minor.namespace_id).size).to eq(5)
expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_major.namespace_id).size).to eq(3)
expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_major.namespace_id).size).to eq(3)

@imaging_exam.remove_abstractions(
namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type,
Expand Down
17 changes: 17 additions & 0 deletions spec/models/abstractor/radiation_therapy_prescription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@
expect(radiation_therapy_prescription.reload.detect_abstractor_abstraction(@abstractor_subject_abstraction_schema_has_anatomical_location).abstractor_suggestions.select { |abstractor_suggestion| abstractor_suggestion.unknown }.size).to eq(1)
end

#removing abstractions
it "removes grouped abstractor abstractions", focus: false do
radiation_therapy_prescription = FactoryGirl.create(:radiation_therapy_prescription, site_name: 'left parietal lobe')
radiation_therapy_prescription.abstract
abstractor_abstraction_groups = []
radiation_therapy_prescription.abstractor_abstractions.each do |abstractor_abstraction|
abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group
end
abstractor_abstraction_groups.uniq!
expect(radiation_therapy_prescription.abstractor_abstractions.size).to eq(2)
radiation_therapy_prescription.remove_abstractions
expect(radiation_therapy_prescription.reload.abstractor_abstractions.size).to eq(0)
abstractor_abstraction_groups.each do |abstractor_abstraction_group|
expect(Abstractor::AbstractorAbstractionGroup.where(id: abstractor_abstraction_group.id).first).to be_nil
end
end

#groups
it "creates a abstractor abstraction group" do
radiation_therapy_prescription = FactoryGirl.create(:radiation_therapy_prescription, site_name: 'left parietal lobe')
Expand Down

0 comments on commit a615ed2

Please sign in to comment.