Skip to content

Commit

Permalink
Merge pull request #380 from psu-stewardship/frozen
Browse files Browse the repository at this point in the history
Adding check to be certain the owner has not already been deleted before...
  • Loading branch information
jcoyne committed Mar 31, 2014
2 parents baa5a87 + 2978536 commit fcf5fcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def count_records
end

def delete_records(records, method)
records.each do |r|
records.each do |r|
@owner.remove_relationship(@reflection.options[:property], r)

if (@reflection.options[:inverse_of])
Expand All @@ -71,7 +71,7 @@ def delete_records(records, method)
r.save
end
end
@owner.save!
@owner.save! unless @owner.new_record?
end

end
Expand Down
30 changes: 30 additions & 0 deletions spec/unit/has_and_belongs_to_many_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,34 @@ class Page < ActiveFedora::Base
ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
ac.find_target
end

context "class with association" do
before do
class Collection < ActiveFedora::Base
has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base" , :after_remove => :remove_member
def remove_member (m)
end
end

class Thing < ActiveFedora::Base
has_many :collections, property: :has_collection_member, :class_name => "ActiveFedora::Base"
end
end

after do
Collection.destroy_all
Thing.destroy_all
Object.send(:remove_const, :Collection)
Object.send(:remove_const, :Thing)
end

let(:thing) {Thing.create()}
let(:collection) {Collection.create().tap {|c| c.members << thing}}

it "should call destroy" do
expect(collection.destroy).to_not raise_error
end

end

end

0 comments on commit fcf5fcd

Please sign in to comment.