active-fedora 8.5.0 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4974eb96df12d79e7d11f6fe3597c3dfb95fe017
4
- data.tar.gz: b562792daabda45401cc1a203c426df2e3b75d62
2
+ SHA256:
3
+ metadata.gz: fb6990ade9b80f8791ad5f0198253f5a528cefd3d95b464bb1f3e0d4411ff5fc
4
+ data.tar.gz: 063af609fdfe2ccc6f5f01fe59aa3ee4861267a3ced7916b63ab0d912ef5e757
5
5
  SHA512:
6
- metadata.gz: 3653cf10baf9e0b68f500dff5feb7a7d38b0651159fb1a8f5493dbe68e20bb1b79d58eb53944c43a800ea47ed5d46fec7b144211149c7496048471df8f1d8def
7
- data.tar.gz: adbd259ede621a91f344cceb56ed3e0f73ae37b9202ec91186d2b7bf8c079f723cf7a56589625da99c6a39cb7ef440b416d658ffbd1875593fcb144da786bf21
6
+ metadata.gz: 97492f688b577f381a4d265c761943f11149d45ab14d73d035d823467320d59c7e24caa8f7a43b52a249e5181a64c2c9d7fab63a50700c885e79e374badf2cb9
7
+ data.tar.gz: 8d5c82996f6d07470b268fe0e6afa26112c0c49694b621f9300ec6b6bdd3cfa8e5271ac17e882884238e4fab7acaaf1e406a56a25bf795261bd06684c1f7b4d2
@@ -20,7 +20,7 @@ module ActiveFedora
20
20
  Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
21
21
  Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
22
22
  Solrizer.set_field(solr_doc, 'object_state', state, :stored_sortable)
23
- Solrizer.set_field(solr_doc, 'active_fedora_model', self.class.inspect, :stored_sortable)
23
+ Solrizer.set_field(solr_doc, 'active_fedora_model', has_model, :stored_sortable)
24
24
  solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid)
25
25
  solrize_profile(solr_doc)
26
26
  end
@@ -73,6 +73,13 @@ module ActiveFedora
73
73
  end
74
74
  end
75
75
 
76
+ private
77
+
78
+ # Override this method if you want to represent the class in a different way
79
+ def has_model
80
+ self.class.inspect
81
+ end
82
+
76
83
 
77
84
  module ClassMethods
78
85
  # This method can be used instead of ActiveFedora::Model::ClassMethods.find.
@@ -1,8 +1,8 @@
1
1
  require 'rsolr'
2
2
 
3
3
  module ActiveFedora
4
- class SolrService
5
-
4
+ class SolrService
5
+
6
6
  attr_reader :conn
7
7
 
8
8
  def initialize(host, args)
@@ -11,7 +11,7 @@ module ActiveFedora
11
11
  args.merge!(:url=>host)
12
12
  @conn = RSolr.connect args
13
13
  end
14
-
14
+
15
15
  class << self
16
16
  def register(host=nil, args={})
17
17
  Thread.current[:solr_service] = new(host, args)
@@ -23,7 +23,7 @@ module ActiveFedora
23
23
 
24
24
  def instance
25
25
  # Register Solr
26
-
26
+
27
27
  unless Thread.current[:solr_service]
28
28
  register(ActiveFedora.solr_config[:url])
29
29
  end
@@ -39,7 +39,7 @@ module ActiveFedora
39
39
  end
40
40
  end
41
41
  end
42
-
42
+
43
43
  def reify_solr_results(solr_results, opts = {})
44
44
  solr_results.collect {|hit| reify_solr_result(hit, opts)}
45
45
  end
@@ -57,7 +57,10 @@ module ActiveFedora
57
57
  def class_from_solr_document(hit, opts = {})
58
58
  #Set the default starting point to the class specified, if available.
59
59
  best_model_match = Model.from_class_uri(opts[:class]) unless opts[:class].nil?
60
- hit[HAS_MODEL_SOLR_FIELD].each do |value|
60
+ model = hit.fetch(HAS_MODEL_SOLR_FIELD) do
61
+ raise "Solr document (id: #{hit['id']}) is missing required #{HAS_MODEL_SOLR_FIELD} field."
62
+ end
63
+ model.each do |value|
61
64
 
62
65
  model_value = Model.from_class_uri(value)
63
66
 
@@ -75,7 +78,7 @@ module ActiveFedora
75
78
  ActiveFedora::Base.logger.warn "Could not find a model for #{hit["id"]}, defaulting to ActiveFedora::Base" unless best_model_match if ActiveFedora::Base.logger
76
79
  best_model_match || ActiveFedora::Base
77
80
  end
78
-
81
+
79
82
  # Construct a solr query for a list of pids
80
83
  # This is used to get a solr response based on the list of pids in an object's RELS-EXT relationhsips
81
84
  # If the pid_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response
@@ -96,7 +99,7 @@ module ActiveFedora
96
99
  def solr_name(*args)
97
100
  Solrizer.default_field_mapper.solr_name(*args)
98
101
  end
99
-
102
+
100
103
  # Create a query with a clause for each key, value
101
104
  # @param [Hash, Array<Array<String>>] args key is the predicate, value is the target_uri
102
105
  # @param [String] join_with ('AND') the value we're joining the clauses with
@@ -118,7 +121,7 @@ module ActiveFedora
118
121
  end
119
122
 
120
123
  # Get the count of records that match the query
121
- # @param [String] query a solr query
124
+ # @param [String] query a solr query
122
125
  # @param [Hash] args arguments to pass through to `args' param of SolrService.query (note that :rows will be overwritten to 0)
123
126
  # @return [Integer] number of records matching
124
127
  def count(query, args={})
@@ -127,7 +130,7 @@ module ActiveFedora
127
130
  end
128
131
 
129
132
  # @param [Hash] doc the document to index
130
- # @param [Hash] params
133
+ # @param [Hash] params
131
134
  # :commit => commits immediately
132
135
  # :softCommit => commit to memory, but don't flush to disk
133
136
  def add(doc, params = {})
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "8.5.0"
2
+ VERSION = "8.6.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- @@last_pid = 0
2
+ @@last_pid = 0
3
3
 
4
4
  describe ActiveFedora::Base do
5
5
  it_behaves_like "An ActiveModel"
@@ -128,7 +128,7 @@ describe ActiveFedora::Base do
128
128
  end
129
129
  has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel", :autocreate => true do |m|
130
130
  m.field "fubar", :text
131
- end
131
+ end
132
132
  has_attributes :fubar, datastream: 'withText', multiple: true
133
133
  has_attributes :swank, datastream: 'someData', multiple: true
134
134
  end
@@ -451,8 +451,12 @@ describe ActiveFedora::Base do
451
451
  end
452
452
  end
453
453
 
454
+ describe '#has_model' do
455
+ subject { FooHistory.new.send(:has_model) }
456
+ it { is_expected.to eq 'FooHistory' }
457
+ end
454
458
 
455
- describe ".to_solr" do
459
+ describe '#to_solr' do
456
460
  it "should provide .to_solr" do
457
461
  expect(@test_object).to respond_to(:to_solr)
458
462
  end
@@ -478,11 +482,10 @@ describe ActiveFedora::Base do
478
482
  expect(solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)]).to be_nil
479
483
  end
480
484
 
481
- it "should add self.class as the :active_fedora_model" do
485
+ it "adds has_model as the :active_fedora_model" do
482
486
  stub_get(@this_pid)
483
487
  stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
484
- @test_history = FooHistory.new()
485
- solr_doc = @test_history.to_solr
488
+ solr_doc = FooHistory.new.to_solr
486
489
  expect(solr_doc[ActiveFedora::SolrService.solr_name("active_fedora_model", :stored_sortable)]).to eql("FooHistory")
487
490
  end
488
491
 
@@ -4,11 +4,11 @@ describe ActiveFedora::SolrService do
4
4
  before do
5
5
  Thread.current[:solr_service]=nil
6
6
  end
7
-
7
+
8
8
  after(:all) do
9
9
  ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
10
10
  end
11
-
11
+
12
12
  it "should take a narg constructor and configure for localhost" do
13
13
  expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://localhost:8080/solr')
14
14
  ActiveFedora::SolrService.register
@@ -97,7 +97,7 @@ describe ActiveFedora::SolrService do
97
97
  expect(ActiveFedora::SolrService.raw_query('id', "my:_PID1_")).to eq '_query_:"{!raw f=id}my:_PID1_"'
98
98
  end
99
99
  end
100
-
100
+
101
101
  describe '#construct_query_for_pids' do
102
102
  it "should generate a useable solr query from an array of Fedora pids" do
103
103
  expect(ActiveFedora::SolrService.construct_query_for_pids(["my:_PID1_", "my:_PID2_", "my:_PID3_"])).to eq('_query_:"{!raw f=id}my:_PID1_" OR _query_:"{!raw f=id}my:_PID2_" OR _query_:"{!raw f=id}my:_PID3_"')
@@ -105,12 +105,12 @@ describe ActiveFedora::SolrService do
105
105
  end
106
106
  it "should return a valid solr query even if given an empty array as input" do
107
107
  expect(ActiveFedora::SolrService.construct_query_for_pids([""])).to eq("id:NEVER_USE_THIS_ID")
108
-
108
+
109
109
  end
110
110
  end
111
-
111
+
112
112
  describe ".query" do
113
- it "should call solr" do
113
+ it "should call solr" do
114
114
  mock_conn = double("Connection")
115
115
  stub_result = double("Result")
116
116
  expect(mock_conn).to receive(:get).with('select', :params=>{:q=>'querytext', :qt=>'standard'}).and_return(stub_result)
@@ -119,23 +119,23 @@ describe ActiveFedora::SolrService do
119
119
  end
120
120
  end
121
121
  describe ".count" do
122
- it "should return a count of matching records" do
122
+ it "should return a count of matching records" do
123
123
  mock_conn = double("Connection")
124
124
  stub_result = {'response' => {'numFound'=>'7'}}
125
125
  expect(mock_conn).to receive(:get).with('select', :params=>{:rows=>0, :q=>'querytext', :qt=>'standard'}).and_return(stub_result)
126
126
  allow(ActiveFedora::SolrService).to receive_messages(:instance =>double("instance", :conn=>mock_conn))
127
- expect(ActiveFedora::SolrService.count('querytext')).to eq(7)
127
+ expect(ActiveFedora::SolrService.count('querytext')).to eq(7)
128
128
  end
129
129
  it "should accept query args" do
130
130
  mock_conn = double("Connection")
131
131
  stub_result = {'response' => {'numFound'=>'7'}}
132
132
  expect(mock_conn).to receive(:get).with('select', :params=>{:rows=>0, :q=>'querytext', :qt=>'standard', :fq=>'filter'}).and_return(stub_result)
133
133
  allow(ActiveFedora::SolrService).to receive_messages(:instance =>double("instance", :conn=>mock_conn))
134
- expect(ActiveFedora::SolrService.count('querytext', :fq=>'filter', :rows=>10)).to eq(7)
134
+ expect(ActiveFedora::SolrService.count('querytext', :fq=>'filter', :rows=>10)).to eq(7)
135
135
  end
136
136
  end
137
137
  describe ".add" do
138
- it "should call solr" do
138
+ it "should call solr" do
139
139
  mock_conn = double("Connection")
140
140
  doc = {'id' => '1234'}
141
141
  expect(mock_conn).to receive(:add).with(doc, {:params=>{}})
@@ -144,7 +144,7 @@ describe ActiveFedora::SolrService do
144
144
  end
145
145
  end
146
146
  describe ".commit" do
147
- it "should call solr" do
147
+ it "should call solr" do
148
148
  mock_conn = double("Connection")
149
149
  doc = {'id' => '1234'}
150
150
  expect(mock_conn).to receive(:commit)
@@ -152,5 +152,27 @@ describe ActiveFedora::SolrService do
152
152
  ActiveFedora::SolrService.commit()
153
153
  end
154
154
  end
155
-
155
+
156
+ describe '.class_from_solr_document' do
157
+ subject { described_class.class_from_solr_document(document) }
158
+
159
+ context 'when the document does not have has_model_ssim' do
160
+ let (:document) do
161
+ { "id" => "my:_PID1_" }
162
+ end
163
+
164
+ it 'raises a helpful error' do
165
+ expect { subject }.to raise_error "Solr document (id: my:_PID1_) is missing required has_model_ssim field."
166
+ end
167
+ end
168
+
169
+ context 'when the document has has_model_ssim' do
170
+ let (:document) do
171
+ { "id" => "my:_PID1_", ActiveFedora::SolrService.solr_name("has_model", :symbol) => ["info:fedora/afmodel:AudioRecord"] }
172
+ end
173
+
174
+ it { is_expected.to eq AudioRecord }
175
+
176
+ end
177
+ end
156
178
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.5.0
4
+ version: 8.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-26 00:00:00.000000000 Z
13
+ date: 2018-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -563,7 +563,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
563
563
  version: '0'
564
564
  requirements: []
565
565
  rubyforge_project:
566
- rubygems_version: 2.6.11
566
+ rubygems_version: 2.7.6
567
567
  signing_key:
568
568
  specification_version: 4
569
569
  summary: A convenience libary for manipulating documents in the Fedora Repository.