Skip to content

Commit

Permalink
HYDRA-654 -- Reify as the class in has_model instead of active_fedora…
Browse files Browse the repository at this point in the history
…_model. Ready to release 3.0.1
  • Loading branch information
jcoyne committed Sep 8, 2011
1 parent c8e8fbd commit 5d6d562
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -1,3 +1,7 @@
3.0.1

HYDRA-654 -- Fixed reification using has_model as the class instead of active_fedora_model

3.0.0

added belongs_to and has_many model relationships
Expand Down
1 change: 1 addition & 0 deletions lib/active_fedora.rb
Expand Up @@ -292,6 +292,7 @@ class ObjectNotFoundError < RuntimeError; end # :nodoc:
class PredicateMappingsNotFoundError < RuntimeError; end # :nodoc:
class UnknownAttributeError < NoMethodError; end; # :nodoc:
class ActiveFedoraConfigurationException < Exception; end # :nodoc:
class AssociationTypeMismatch < RuntimeError; end # :nodoc:

end

23 changes: 17 additions & 6 deletions lib/active_fedora/solr_service.rb
Expand Up @@ -32,12 +32,7 @@ def self.reify_solr_results(solr_result,opts={})
end
results = []
solr_result.hits.each do |hit|
model_value = hit[solr_name("active_fedora_model", :symbol)].first
if model_value.include?("::")
classname = eval(model_value)
else
classname = Kernel.const_get(model_value)
end
classname = class_from_solr_document(hit)
if opts[:load_from_solr]
results << classname.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
else
Expand All @@ -46,6 +41,22 @@ def self.reify_solr_results(solr_result,opts={})
end
return results
end

def self.class_from_solr_document(hit)
model_value = hit[solr_name("has_model", :symbol)].first
if match_data = /info:fedora\/afmodel:(.+)$/.match(model_value)
model_value = match_data[1]
model_value.gsub!('_', '::')
else
raise "has_model assertion incorrectly formatted: #{model_value}"
end

if model_value.include?("::")
eval(model_value)
else
Kernel.const_get(model_value)
end
end

# Construct a solr query for a list of pids
# This is used to get a solr response based on the list of pids in an object's RELS-EXT relationhsips
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/version.rb
@@ -1,3 +1,3 @@
module ActiveFedora
VERSION = "3.0.0"
VERSION = "3.0.1"
end
12 changes: 8 additions & 4 deletions spec/unit/semantic_node_spec.rb
Expand Up @@ -25,9 +25,9 @@ def increment_pid
before(:all) do
@pid = "test:sample_pid"
@uri = "info:fedora/#{@pid}"
@sample_solr_hits = [{"id"=>"_PID1_", "active_fedora_model_s"=>["AudioRecord"]},
{"id"=>"_PID2_", "active_fedora_model_s"=>["AudioRecord"]},
{"id"=>"_PID3_", "active_fedora_model_s"=>["AudioRecord"]}]
@sample_solr_hits = [{"id"=>"_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
{"id"=>"_PID2_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
{"id"=>"_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
end

before(:each) do
Expand Down Expand Up @@ -347,7 +347,11 @@ class MockHasRelationshipDuplicatePredicate2 < SpecNode2
local_node.expects(:outbound_relationships).returns({:is_member_of => ["my:_PID1_", "my:_PID2_", "my:_PID3_"]}).times(2)
mock_repo = mock("repo")
solr_result = mock("solr result", :is_a? => true)
solr_result.expects(:hits).returns([{"id"=> "my:_PID1_", "active_fedora_model_s" => ["SpecNode"]}, {"id"=> "my:_PID2_", "active_fedora_model_s" => ["SpecNode"]}, {"id"=> "my:_PID3_", "active_fedora_model_s" => ["SpecNode"]}])
solr_result.expects(:hits).returns(
[{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
{"id"=> "my:_PID2_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
{"id"=> "my:_PID3_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]}])

ActiveFedora::SolrService.instance.conn.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns(solr_result)
mock_repo.expects(:find_model).with("my:_PID1_", SpecNode).returns("AR1")
mock_repo.expects(:find_model).with("my:_PID2_", SpecNode).returns("AR2")
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/solr_service_spec.rb
Expand Up @@ -47,9 +47,9 @@

describe "#reify_solr_results" do
before(:each) do
@sample_solr_hits = [{"id"=>"my:_PID1_", "active_fedora_model_s"=>["AudioRecord"]},
{"id"=>"my:_PID2_", "active_fedora_model_s"=>["AudioRecord"]},
{"id"=>"my:_PID3_", "active_fedora_model_s"=>["AudioRecord"]}]
@sample_solr_hits = [{"id"=>"my:_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
{"id"=>"my:_PID2_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
{"id"=>"my:_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
end
it "should only take Solr::Response::Standard objects as input" do
mocko = mock("input", :is_a? => false)
Expand Down

0 comments on commit 5d6d562

Please sign in to comment.