active-fedora 9.9.1 → 9.10.0.pre1
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 +4 -4
- data/.rubocop.yml +4 -2
- data/.travis.yml +2 -6
- data/active-fedora.gemspec +9 -6
- data/lib/active_fedora.rb +31 -15
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/associations/association.rb +6 -2
- data/lib/active_fedora/associations/belongs_to_association.rb +0 -10
- data/lib/active_fedora/associations/builder/association.rb +85 -12
- data/lib/active_fedora/associations/builder/belongs_to.rb +3 -1
- data/lib/active_fedora/associations/builder/collection_association.rb +4 -3
- data/lib/active_fedora/associations/builder/contains.rb +7 -2
- data/lib/active_fedora/associations/builder/directly_contains.rb +7 -3
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +8 -4
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +6 -2
- data/lib/active_fedora/associations/builder/has_many.rb +6 -2
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +7 -3
- data/lib/active_fedora/associations/builder/property.rb +7 -2
- data/lib/active_fedora/associations/builder/singular_association.rb +3 -1
- data/lib/active_fedora/associations/builder/singular_property.rb +3 -1
- data/lib/active_fedora/associations/collection_association.rb +9 -5
- data/lib/active_fedora/associations/collection_proxy.rb +1 -1
- data/lib/active_fedora/associations/contained_finder.rb +1 -2
- data/lib/active_fedora/associations/directly_contains_one_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +1 -5
- data/lib/active_fedora/associations/rdf.rb +1 -20
- data/lib/active_fedora/attached_files.rb +1 -1
- data/lib/active_fedora/attribute_methods.rb +18 -0
- data/lib/active_fedora/attributes.rb +1 -1
- data/lib/active_fedora/autosave_association.rb +8 -12
- data/lib/active_fedora/base.rb +0 -2
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/default_model_mapper.rb +24 -0
- data/lib/active_fedora/fedora.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +4 -5
- data/lib/active_fedora/identifiable.rb +5 -0
- data/lib/active_fedora/indexing.rb +13 -7
- data/lib/active_fedora/indexing_service.rb +4 -4
- data/lib/active_fedora/ldp_resource.rb +1 -0
- data/lib/active_fedora/model.rb +18 -16
- data/lib/active_fedora/model_classifier.rb +77 -0
- data/lib/active_fedora/nested_attributes.rb +145 -18
- data/lib/active_fedora/persistence.rb +1 -1
- data/lib/active_fedora/predicates.rb +3 -0
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +12 -28
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
- data/lib/active_fedora/reflection.rb +15 -7
- data/lib/active_fedora/relation.rb +17 -0
- data/lib/active_fedora/relation/calculations.rb +1 -5
- data/lib/active_fedora/relation/finder_methods.rb +39 -26
- data/lib/active_fedora/scoping.rb +5 -0
- data/lib/active_fedora/scoping/default.rb +113 -0
- data/lib/active_fedora/scoping/named.rb +11 -3
- data/lib/active_fedora/simple_datastream.rb +1 -1
- data/lib/active_fedora/solr_hit.rb +71 -0
- data/lib/active_fedora/solr_instance_loader.rb +12 -36
- data/lib/active_fedora/solr_query_builder.rb +20 -25
- data/lib/active_fedora/solr_service.rb +24 -13
- data/lib/active_fedora/type.rb +8 -0
- data/lib/active_fedora/type/boolean.rb +23 -0
- data/lib/active_fedora/type/value.rb +118 -0
- data/lib/active_fedora/validations.rb +14 -5
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +8 -7
- data/spec/config_helper.rb +0 -5
- data/spec/integration/associations_spec.rb +5 -5
- data/spec/integration/base_spec.rb +4 -4
- data/spec/integration/bug_spec.rb +0 -1
- data/spec/integration/full_featured_model_spec.rb +4 -4
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +30 -1
- data/spec/integration/indirect_container_spec.rb +1 -1
- data/spec/integration/nested_attribute_spec.rb +6 -0
- data/spec/integration/ntriples_datastream_spec.rb +4 -4
- data/spec/integration/om_datastream_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +1 -1
- data/spec/integration/scoped_query_spec.rb +12 -12
- data/spec/integration/solr_hit_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +2 -2
- data/spec/spec_helper.rb +5 -9
- data/spec/unit/active_fedora_spec.rb +0 -26
- data/spec/unit/base_spec.rb +20 -0
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
- data/spec/unit/callback_spec.rb +3 -8
- data/spec/unit/default_model_mapper_spec.rb +39 -0
- data/spec/unit/finder_methods_spec.rb +30 -6
- data/spec/unit/has_many_association_spec.rb +23 -1
- data/spec/unit/indexing_spec.rb +17 -3
- data/spec/unit/model_classifier_spec.rb +49 -0
- data/spec/unit/model_spec.rb +0 -9
- data/spec/unit/ntriples_datastream_spec.rb +16 -16
- data/spec/unit/om_datastream_spec.rb +7 -7
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
- data/spec/unit/query_result_builder_spec.rb +4 -10
- data/spec/unit/query_spec.rb +28 -28
- data/spec/unit/rdf/indexing_service_spec.rb +16 -16
- data/spec/unit/scoping_spec.rb +67 -0
- data/spec/unit/simple_datastream_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +29 -32
- data/spec/unit/solr_hit_spec.rb +58 -0
- data/spec/unit/solr_query_builder_spec.rb +9 -1
- data/spec/unit/solr_service_spec.rb +19 -3
- metadata +73 -17
- data/spec/support/freeze_mocks.rb +0 -12
data/spec/unit/query_spec.rb
CHANGED
@@ -7,8 +7,8 @@ describe ActiveFedora::Base do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
|
-
let(:sort_query) { ActiveFedora
|
11
|
-
let(:model_query) { "_query_:\"{!
|
10
|
+
let(:sort_query) { ActiveFedora.index_field_mapper.solr_name("system_create", :stored_sortable, type: :date) + ' asc' }
|
11
|
+
let(:model_query) { "_query_:\"{!field f=has_model_ssim}SpecModel::Basic\"" }
|
12
12
|
|
13
13
|
after(:all) do
|
14
14
|
Object.send(:remove_const, :SpecModel)
|
@@ -77,9 +77,9 @@ describe ActiveFedora::Base do
|
|
77
77
|
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
78
78
|
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
79
79
|
let(:expected_query) { "#{model_query} AND " \
|
80
|
-
"_query_:\"{!
|
81
|
-
"_query_:\"{!
|
82
|
-
"_query_:\"{!
|
80
|
+
"_query_:\"{!field f=foo}bar\" AND " \
|
81
|
+
"_query_:\"{!field f=baz}quix\" AND " \
|
82
|
+
"_query_:\"{!field f=baz}quack\"" }
|
83
83
|
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
84
84
|
let(:expected_sort_params) { { params: { sort: ["title_t desc"], fl: 'id', q: expected_query, qt: 'standard' } } }
|
85
85
|
let(:mock_docs) { [{ "id" => "changeme:30" }, { "id" => "changeme:22" }] }
|
@@ -136,9 +136,9 @@ describe ActiveFedora::Base do
|
|
136
136
|
describe "with conditions" do
|
137
137
|
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
138
138
|
let(:expected_query) { "#{model_query} AND " \
|
139
|
-
"_query_:\"{!
|
140
|
-
"_query_:\"{!
|
141
|
-
"_query_:\"{!
|
139
|
+
"_query_:\"{!field f=foo}bar\" AND " \
|
140
|
+
"_query_:\"{!field f=baz}quix\" AND " \
|
141
|
+
"_query_:\"{!field f=baz}quack\"" }
|
142
142
|
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
143
143
|
let(:mock_docs) { [{ "id" => "changeme-30" }, { "id" => "changeme-22" }] }
|
144
144
|
|
@@ -153,13 +153,13 @@ describe ActiveFedora::Base do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
describe '#
|
156
|
+
describe '#search_in_batches' do
|
157
157
|
describe "with conditions hash" do
|
158
158
|
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
159
159
|
let(:expected_query) { "#{model_query} AND " \
|
160
|
-
"_query_:\"{!
|
161
|
-
"_query_:\"{!
|
162
|
-
"_query_:\"{!
|
160
|
+
"_query_:\"{!field f=foo}bar\" AND " \
|
161
|
+
"_query_:\"{!field f=baz}quix\" AND " \
|
162
|
+
"_query_:\"{!field f=baz}quack\"" }
|
163
163
|
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
164
164
|
let(:mock_docs) { double('docs') }
|
165
165
|
|
@@ -168,7 +168,7 @@ describe ActiveFedora::Base do
|
|
168
168
|
expect(solr).to receive(:paginate).with(1, 1002, 'select', expected_params).and_return('response' => { 'docs' => mock_docs })
|
169
169
|
yielded = double("yielded method")
|
170
170
|
expect(yielded).to receive(:run).with(mock_docs)
|
171
|
-
SpecModel::Basic.
|
171
|
+
SpecModel::Basic.search_in_batches({ foo: 'bar', baz: ['quix', 'quack'] }, batch_size: 1002, fl: 'id') { |group| yielded.run group }
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
@@ -177,22 +177,22 @@ describe ActiveFedora::Base do
|
|
177
177
|
let(:mock_result) { { 'response' => { 'numFound' => 7 } } }
|
178
178
|
|
179
179
|
it "returns a count" do
|
180
|
-
expect(ActiveFedora::SolrService).to receive(:
|
181
|
-
.with(model_query, rows: 0
|
180
|
+
expect(ActiveFedora::SolrService).to receive(:get)
|
181
|
+
.with(model_query, rows: 0)
|
182
182
|
.and_return(mock_result)
|
183
183
|
expect(SpecModel::Basic.count).to eq 7
|
184
184
|
end
|
185
185
|
|
186
186
|
it "allows conditions" do
|
187
|
-
expect(ActiveFedora::SolrService).to receive(:
|
188
|
-
.with("#{model_query} AND (foo:bar)", rows: 0
|
187
|
+
expect(ActiveFedora::SolrService).to receive(:get)
|
188
|
+
.with("#{model_query} AND (foo:bar)", rows: 0)
|
189
189
|
.and_return(mock_result)
|
190
190
|
expect(SpecModel::Basic.count(conditions: 'foo:bar')).to eq 7
|
191
191
|
end
|
192
192
|
|
193
193
|
it "counts without a class specified" do
|
194
|
-
expect(ActiveFedora::SolrService).to receive(:
|
195
|
-
.with("(foo:bar)", rows: 0
|
194
|
+
expect(ActiveFedora::SolrService).to receive(:get)
|
195
|
+
.with("(foo:bar)", rows: 0)
|
196
196
|
.and_return(mock_result)
|
197
197
|
expect(described_class.count(conditions: 'foo:bar')).to eq 7
|
198
198
|
end
|
@@ -240,10 +240,10 @@ describe ActiveFedora::Base do
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
-
describe '#
|
243
|
+
describe '#search_with_conditions' do
|
244
244
|
let(:mock_result) { double('Result') }
|
245
245
|
let(:klass) { SpecModel::Basic }
|
246
|
-
subject { klass.
|
246
|
+
subject { klass.search_with_conditions(conditions) }
|
247
247
|
|
248
248
|
before do
|
249
249
|
expect(ActiveFedora::SolrService).to receive(:query)
|
@@ -252,9 +252,9 @@ describe ActiveFedora::Base do
|
|
252
252
|
|
253
253
|
context "with a hash of conditions" do
|
254
254
|
let(:expected_query) { "#{model_query} AND " \
|
255
|
-
"_query_:\"{!
|
256
|
-
"_query_:\"{!
|
257
|
-
"_query_:\"{!
|
255
|
+
"_query_:\"{!field f=foo}bar\" AND " \
|
256
|
+
"_query_:\"{!field f=baz}quix\" AND " \
|
257
|
+
"_query_:\"{!field f=baz}quack\"" }
|
258
258
|
let(:conditions) { { foo: 'bar', baz: ['quix', 'quack'] } }
|
259
259
|
|
260
260
|
it "makes a query to solr and returns the results" do
|
@@ -264,9 +264,9 @@ describe ActiveFedora::Base do
|
|
264
264
|
|
265
265
|
context "with quotes in the params" do
|
266
266
|
let(:expected_query) { "#{model_query} AND " \
|
267
|
-
"_query_:\"{!
|
268
|
-
"_query_:\"{!
|
269
|
-
"_query_:\"{!
|
267
|
+
"_query_:\"{!field f=foo}9\\\" Nails\" AND " \
|
268
|
+
"_query_:\"{!field f=baz}7\\\" version\" AND " \
|
269
|
+
"_query_:\"{!field f=baz}quack\"" }
|
270
270
|
let(:conditions) { { foo: '9" Nails', baz: ['7" version', 'quack'] } }
|
271
271
|
|
272
272
|
it "escapes quotes" do
|
@@ -279,7 +279,7 @@ describe ActiveFedora::Base do
|
|
279
279
|
|
280
280
|
context "with a hash" do
|
281
281
|
let(:conditions) { { baz: 'quack' } }
|
282
|
-
let(:expected_query) { "_query_:\"{!
|
282
|
+
let(:expected_query) { "_query_:\"{!field f=baz}quack\"" }
|
283
283
|
it "doesn't use the class if it's called on AF:Base " do
|
284
284
|
expect(subject).to eq mock_result
|
285
285
|
end
|
@@ -47,25 +47,25 @@ describe ActiveFedora::RDF::IndexingService do
|
|
47
47
|
describe "#generate_solr_document" do
|
48
48
|
subject { indexer.generate_solr_document(lambda { |key| "solr_rdf__#{key}" }) }
|
49
49
|
it "returns the right fields" do
|
50
|
-
expect(subject.keys).to include(ActiveFedora
|
51
|
-
ActiveFedora
|
52
|
-
ActiveFedora
|
53
|
-
ActiveFedora
|
54
|
-
ActiveFedora
|
55
|
-
ActiveFedora
|
56
|
-
ActiveFedora
|
57
|
-
ActiveFedora
|
58
|
-
ActiveFedora
|
59
|
-
ActiveFedora
|
50
|
+
expect(subject.keys).to include(ActiveFedora.index_field_mapper.solr_name("solr_rdf__related_url", type: :string),
|
51
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", type: :string),
|
52
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", :sortable),
|
53
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", :facetable),
|
54
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__created", :sortable, type: :date),
|
55
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__created", :displayable),
|
56
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__title", type: :string),
|
57
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__title", :sortable),
|
58
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__based_near", type: :string),
|
59
|
+
ActiveFedora.index_field_mapper.solr_name("solr_rdf__based_near", :facetable))
|
60
60
|
end
|
61
61
|
|
62
62
|
it "returns the right values" do
|
63
|
-
expect(subject[ActiveFedora
|
64
|
-
expect(subject[ActiveFedora
|
65
|
-
expect(subject[ActiveFedora
|
66
|
-
expect(subject[ActiveFedora
|
67
|
-
expect(subject[ActiveFedora
|
68
|
-
expect(subject[ActiveFedora
|
63
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__related_url", type: :string)]).to eq ["http://example.org/blogtastic/"]
|
64
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__based_near", type: :string)]).to eq ["Tacoma, WA", "Renton, WA"]
|
65
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__based_near", :facetable)]).to eq ["Tacoma, WA", "Renton, WA"]
|
66
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", type: :string)]).to eq ["Bob's Blogtastic Publishing"]
|
67
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", :sortable)]).to eq "Bob's Blogtastic Publishing"
|
68
|
+
expect(subject[ActiveFedora.index_field_mapper.solr_name("solr_rdf__publisher", :facetable)]).to eq ["Bob's Blogtastic Publishing"]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Scoping::Default do
|
4
|
+
describe "when default_scope is overridden" do
|
5
|
+
before do
|
6
|
+
class Book < ActiveFedora::Base
|
7
|
+
property :published, predicate: ::RDF::Vocab::EBUCore.pubStatus do |index|
|
8
|
+
index.as :symbol
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.default_scope
|
12
|
+
where published_ssim: 'true'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Book.destroy_all
|
17
|
+
Book.create!(published: [true])
|
18
|
+
Book.create!(published: [true])
|
19
|
+
Book.create!(published: [false])
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
Object.send(:remove_const, :Book)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns only the scoped records" do
|
27
|
+
expect(Book.all.size).to eq 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns all the records" do
|
31
|
+
Book.unscoped do
|
32
|
+
expect(Book.all.size).to eq 3
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "when default_scope is called" do
|
38
|
+
before do
|
39
|
+
class Book < ActiveFedora::Base
|
40
|
+
property :published, predicate: ::RDF::Vocab::EBUCore.pubStatus do |index|
|
41
|
+
index.as :symbol
|
42
|
+
end
|
43
|
+
|
44
|
+
default_scope -> { where published_ssim: 'true' }
|
45
|
+
end
|
46
|
+
|
47
|
+
Book.destroy_all
|
48
|
+
Book.create!(published: [true])
|
49
|
+
Book.create!(published: [true])
|
50
|
+
Book.create!(published: [false])
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
Object.send(:remove_const, :Book)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns only the scoped records" do
|
58
|
+
expect(Book.all.size).to eq 2
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns all the records" do
|
62
|
+
Book.unscoped do
|
63
|
+
expect(Book.all.size).to eq 3
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -54,8 +54,8 @@ describe ActiveFedora::SimpleDatastream do
|
|
54
54
|
describe "#to_solr" do
|
55
55
|
it "has title" do
|
56
56
|
solr = @test_ds.to_solr
|
57
|
-
expect(solr[ActiveFedora
|
58
|
-
expect(solr[ActiveFedora
|
57
|
+
expect(solr[ActiveFedora.index_field_mapper.solr_name('publisher', type: :string)]).to eq "publisher1"
|
58
|
+
expect(solr[ActiveFedora.index_field_mapper.solr_name('creation_date', type: :date)]).to eq "2012-01-15"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -12,52 +12,49 @@ describe ActiveFedora do
|
|
12
12
|
@test_object = ActiveFedora::Base.new
|
13
13
|
end
|
14
14
|
|
15
|
-
describe "
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
after(:all) do
|
20
|
-
SOLR_DOCUMENT_ID = "id".freeze
|
15
|
+
describe ".id_field" do
|
16
|
+
let(:field) { "MY_SAMPLE_ID".freeze }
|
17
|
+
before do
|
18
|
+
allow(described_class).to receive(:id_field).and_return(field)
|
21
19
|
end
|
20
|
+
|
22
21
|
it "is used by ActiveFedora::Base.to_solr" do
|
23
22
|
allow(@test_object).to receive(:id).and_return('changeme:123')
|
24
|
-
|
25
|
-
expect(@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym]).to eq 'changeme:123'
|
23
|
+
expect(@test_object.to_solr[field.to_sym]).to eq 'changeme:123'
|
26
24
|
expect(@test_object.to_solr[:id]).to be_nil
|
27
25
|
end
|
28
26
|
|
29
|
-
it "is used by ActiveFedora::Base#
|
27
|
+
it "is used by ActiveFedora::Base#search_with_conditions" do
|
30
28
|
mock_response = double("SolrResponse")
|
31
29
|
expect(ActiveFedora::SolrService).to receive(:query)
|
32
|
-
.with("_query_:\"{!
|
33
|
-
"_query_:\"{!
|
34
|
-
sort: ["#{
|
30
|
+
.with("_query_:\"{!field f=has_model_ssim}SolrSpecModel::Basic\" AND " \
|
31
|
+
"_query_:\"{!field f=#{field}}changeme:30\"",
|
32
|
+
sort: ["#{described_class.index_field_mapper.solr_name('system_create', :stored_sortable, type: :date)} asc"])
|
35
33
|
.and_return(mock_response)
|
36
34
|
|
37
|
-
expect(SolrSpecModel::Basic.
|
35
|
+
expect(SolrSpecModel::Basic.search_with_conditions(id: "changeme:30")).to equal(mock_response)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
describe "
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
ENABLE_SOLR_UPDATES = true
|
47
|
-
end
|
39
|
+
describe ".enable_solr_updates?" do
|
40
|
+
context 'with .enable_solr_updates? disabled' do
|
41
|
+
before do
|
42
|
+
allow(described_class).to receive(:enable_solr_updates?).and_return(false)
|
43
|
+
end
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
45
|
+
it "prevents Base.save from calling update_index if false" do
|
46
|
+
dirty_ds = ActiveFedora::SimpleDatastream.new
|
47
|
+
@test_object.attached_files['ds1'] = dirty_ds
|
48
|
+
allow(@test_object).to receive(:datastreams).and_return(ds1: dirty_ds)
|
49
|
+
expect(@test_object).to receive(:update_index).never
|
50
|
+
expect(@test_object).to receive(:refresh)
|
51
|
+
@test_object.save
|
52
|
+
end
|
53
|
+
it "prevents Base.delete from deleting the corresponding Solr document if false" do
|
54
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(@test_object.id).never
|
55
|
+
expect(@test_object).to receive(:delete)
|
56
|
+
@test_object.delete
|
57
|
+
end
|
61
58
|
end
|
62
59
|
end
|
63
60
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::SolrHit do
|
4
|
+
before(:all) do
|
5
|
+
class AudioRecord < ActiveFedora::Base
|
6
|
+
attr_accessor :id
|
7
|
+
def self.connection_for_id(_id)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { described_class.new "id" => "my:_ID1_", ActiveFedora.index_field_mapper.solr_name("has_model", :symbol) => ["AudioRecord"] }
|
13
|
+
|
14
|
+
describe "#reify" do
|
15
|
+
it "uses .find to instantiate objects" do
|
16
|
+
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
17
|
+
subject.reify
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#id" do
|
22
|
+
it "extracts the id from the solr hit" do
|
23
|
+
expect(subject.id).to eq "my:_ID1_"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#rdf_uri" do
|
28
|
+
it "provides an RDF URI for the solr hit" do
|
29
|
+
expect(subject.rdf_uri).to eq ::RDF::URI.new(ActiveFedora::Base.id_to_uri("my:_ID1_"))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#model" do
|
34
|
+
it "selects the appropriate model for the solr result" do
|
35
|
+
expect(subject.model).to eq AudioRecord
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#models" do
|
40
|
+
it "provides all the relevant models for the solr result" do
|
41
|
+
expect(subject.models).to match_array [AudioRecord]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#model?" do
|
46
|
+
it 'is true if the object has the given model' do
|
47
|
+
expect(subject.model?(AudioRecord)).to eq true
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'is true if the object has an ancestor of the given model' do
|
51
|
+
expect(subject.model?(ActiveFedora::Base)).to eq true
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'is false if the given model is not in the ancestor tree for the models' do
|
55
|
+
expect(subject.model?(String)).to eq false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::SolrQueryBuilder do
|
4
4
|
describe "raw_query" do
|
5
5
|
it "generates a raw query clause" do
|
6
|
-
|
6
|
+
Deprecation.silence(described_class) do
|
7
|
+
expect(described_class.raw_query('id', "my:_ID1_")).to eq '_query_:"{!raw f=id}my:_ID1_"'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "construct_query" do
|
13
|
+
it "generates a query clause" do
|
14
|
+
expect(described_class.construct_query('id' => "my:_ID1_")).to eq '_query_:"{!field f=id}my:_ID1_"'
|
7
15
|
end
|
8
16
|
end
|
9
17
|
|
@@ -48,13 +48,13 @@ describe ActiveFedora::SolrService do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe "
|
51
|
+
describe "#get" do
|
52
52
|
it "calls solr" do
|
53
53
|
mock_conn = double("Connection")
|
54
54
|
stub_result = double("Result")
|
55
55
|
expect(mock_conn).to receive(:get).with('select', params: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
56
56
|
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
57
|
-
expect(described_class.
|
57
|
+
expect(described_class.get('querytext')).to eq stub_result
|
58
58
|
end
|
59
59
|
it "uses select_path" do
|
60
60
|
mock_conn = double("Connection")
|
@@ -62,9 +62,25 @@ describe ActiveFedora::SolrService do
|
|
62
62
|
expect(mock_conn).to receive(:get).with('select_test', params: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
63
63
|
expect(described_class).to receive(:select_path).and_return('select_test')
|
64
64
|
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
65
|
-
expect(described_class.
|
65
|
+
expect(described_class.get('querytext')).to eq stub_result
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
describe "#query" do
|
70
|
+
let(:doc) { { 'id' => 'x' } }
|
71
|
+
let(:docs) { [doc] }
|
72
|
+
|
73
|
+
it "wraps the solr response documents in Solr hits" do
|
74
|
+
mock_conn = double("Connection")
|
75
|
+
stub_result = { 'response' => { 'docs' => docs } }
|
76
|
+
expect(mock_conn).to receive(:get).with('select', params: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
77
|
+
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
78
|
+
result = described_class.query('querytext')
|
79
|
+
expect(result.size).to eq 1
|
80
|
+
expect(result.first.id).to eq 'x'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
describe ".count" do
|
69
85
|
it "returns a count of matching records" do
|
70
86
|
mock_conn = double("Connection")
|