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

ActiveFedora::SolrService.reify_solr_result modified to pass Solr hit to... #298

Merged
merged 1 commit into from
Jan 2, 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
2 changes: 1 addition & 1 deletion lib/active_fedora/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.reify_solr_results(solr_results, opts = {})
def self.reify_solr_result(hit, opts = {})
klass = class_from_solr_document(hit)
if opts[:load_from_solr]
klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID], hit)
else
klass.find(hit[SOLR_DOCUMENT_ID], cast: true)
end
Expand Down
25 changes: 19 additions & 6 deletions spec/unit/solr_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def self.connection_for_pid(pid)
{"id"=>"my:_PID2_", ActiveFedora::SolrService.solr_name("has_model", :symbol)=>["info:fedora/afmodel:AudioRecord"]},
{"id"=>"my:_PID3_", ActiveFedora::SolrService.solr_name("has_model", :symbol)=>["info:fedora/afmodel:AudioRecord"]}]
end
describe ".reify_solr_result" do
it "should use .find to instantiate objects" do
AudioRecord.should_receive(:find).with("my:_PID1_", cast: true)
ActiveFedora::SolrService.reify_solr_result(@sample_solr_hits.first)
end
it "should use .load_instance_from_solr when called with :load_from_solr option" do
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits.first)
ActiveFedora::SolrService.should_not receive(:query)
ActiveFedora::SolrService.reify_solr_result(@sample_solr_hits.first, load_from_solr: true)
end
end
describe ".reify_solr_results" do
it "should use AudioRecord.find to instantiate objects" do
AudioRecord.should_receive(:find).with("my:_PID1_", cast: true)
Expand All @@ -57,9 +68,10 @@ def self.connection_for_pid(pid)
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits)
end
it "should use AudioRecord.load_instance_from_solr when called with :load_from_solr option" do
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
ActiveFedora::SolrService.should_not receive(:query)
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits, load_from_solr: true)
end
end
Expand All @@ -71,9 +83,10 @@ def self.connection_for_pid(pid)
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits).each {|r| r}
end
it "should use AudioRecord.load_instance_from_solr when called with :load_from_solr option" do
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_")
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
ActiveFedora::SolrService.should_not receive(:query)
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits, load_from_solr: true).each {|r| r}
end
end
Expand Down