Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ActiveFedora under Ruby 2.1. #310

Merged
merged 1 commit into from
Jan 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/active_fedora/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,7 @@ def destroy_all(conditions = nil)
if conditions
where(conditions).destroy_all
else
to_a.each {|object|
begin
object.destroy
rescue ActiveFedora::ObjectNotFoundError
logger.error "When trying to destroy #{object.pid}, encountered an ObjectNotFoundError. Solr may be out of sync with Fedora"
end
}.tap { reset }.size
to_a.each {|object| object.destroy }.tap { reset }.size
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def find_each( conditions={}, opts={})
begin
yield(find_one(hit[SOLR_DOCUMENT_ID], cast))
rescue ActiveFedora::ObjectNotFoundError
logger.error "When trying to find_each #{hit[SOLR_DOCUMENT_ID]}, encountered an ObjectNotFoundError. Solr may be out of sync with Fedora"
logger.error "Although #{hit[SOLR_DOCUMENT_ID]} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch."
end
end
end
Expand Down
15 changes: 9 additions & 6 deletions spec/integration/delete_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def inc_counter

describe "when a model is missing" do
let(:model3) { SpecModel::Basic.create! }
after { model3.delete }
let!(:pid) { model3.pid }
before { model3.inner_object.delete }
after do
ActiveFedora::SolrService.instance.conn.tap do |conn|
conn.delete_by_query "id:\"#{pid}\""
conn.commit
end
end
it "should be able to skip a missing model" do
model1.should_receive(:destroy).and_call_original
model2.should_receive(:destroy).and_call_original
model3.should_receive(:destroy).and_raise(ActiveFedora::ObjectNotFoundError)
ActiveFedora::Relation.any_instance.should_receive(:to_a).and_return([model1, model3, model2])
ActiveFedora::Relation.logger.should_receive(:error).with("When trying to destroy #{model3.pid}, encountered an ObjectNotFoundError. Solr may be out of sync with Fedora")
ActiveFedora::Relation.logger.should_receive(:error).with("Although #{pid} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch.")
SpecModel::Basic.destroy_all
SpecModel::Basic.count.should == 1
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/scoped_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def to_solr(doc = {})
test_instance3.delete
end
it "should log an error" do
ActiveFedora::Relation.logger.should_receive(:error).with("When trying to find_each #{pid}, encountered an ObjectNotFoundError. Solr may be out of sync with Fedora")
ActiveFedora::Relation.logger.should_receive(:error).with("Although #{pid} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch.")
ModelIntegrationSpec::Basic.all.should == [test_instance1, test_instance3]
end
end
Expand Down