active-fedora 9.9.1 → 9.10.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -53,7 +53,7 @@ module ActiveFedora
|
|
53
53
|
# Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
|
54
54
|
# if the record is not valid.
|
55
55
|
def save!(options = {})
|
56
|
-
perform_validations(options) ? super :
|
56
|
+
perform_validations(options) ? super : raise_validation_error
|
57
57
|
end
|
58
58
|
|
59
59
|
# Runs all the validations within the specified context. Returns true if no errors are found,
|
@@ -65,11 +65,13 @@ module ActiveFedora
|
|
65
65
|
# Validations with no <tt>:on</tt> option will run no matter the context. Validations with
|
66
66
|
# some <tt>:on</tt> option will only run in the specified context.
|
67
67
|
def valid?(context = nil)
|
68
|
-
context ||=
|
68
|
+
context ||= default_validation_context
|
69
69
|
output = super(context)
|
70
70
|
errors.empty? && output
|
71
71
|
end
|
72
72
|
|
73
|
+
alias validate valid?
|
74
|
+
|
73
75
|
# Test to see if the given field is required
|
74
76
|
# @param [Symbol] key a field
|
75
77
|
# @return [Boolean] is it required or not
|
@@ -79,9 +81,16 @@ module ActiveFedora
|
|
79
81
|
|
80
82
|
protected
|
81
83
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
84
|
+
def default_validation_context
|
85
|
+
new_record? ? :create : :update
|
86
|
+
end
|
87
|
+
|
88
|
+
def raise_validation_error
|
89
|
+
raise RecordInvalid, self
|
90
|
+
end
|
91
|
+
|
92
|
+
def perform_validations(options = {}) # :nodoc:
|
93
|
+
options[:validate] == false || valid?(options[:context])
|
85
94
|
end
|
86
95
|
end
|
87
96
|
end
|
@@ -25,10 +25,14 @@ module ActiveFedora
|
|
25
25
|
# Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects.
|
26
26
|
# Excludes auto-snapshot versions from Fedora.
|
27
27
|
def versions(reload = false)
|
28
|
+
response = versions_request
|
29
|
+
|
30
|
+
return ActiveFedora::VersionsGraph.new unless response
|
31
|
+
|
28
32
|
if reload
|
29
|
-
@versions = ActiveFedora::VersionsGraph.new <<
|
33
|
+
@versions = ActiveFedora::VersionsGraph.new << versions_request.reader
|
30
34
|
else
|
31
|
-
@versions ||= ActiveFedora::VersionsGraph.new <<
|
35
|
+
@versions ||= ActiveFedora::VersionsGraph.new << versions_request.reader
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -57,11 +61,8 @@ module ActiveFedora
|
|
57
61
|
private
|
58
62
|
|
59
63
|
def versions_request
|
60
|
-
return
|
61
|
-
|
62
|
-
raise ActiveFedoraError, status_message(resp) unless resp.success?
|
63
|
-
raise ActiveFedoraError, bad_headers(resp) unless resp.headers['content-type'] == 'text/turtle'
|
64
|
-
resp.body
|
64
|
+
return false unless has_versions?
|
65
|
+
ActiveFedora.fedora.connection.get(versions_uri)
|
65
66
|
end
|
66
67
|
|
67
68
|
def versions_uri
|
data/spec/config_helper.rb
CHANGED
@@ -234,8 +234,8 @@ describe ActiveFedora::Base do
|
|
234
234
|
|
235
235
|
solr_resp = @library.books(response_format: :solr)
|
236
236
|
expect(solr_resp.size).to eq 2
|
237
|
-
expect(solr_resp[0]
|
238
|
-
expect(solr_resp[1]
|
237
|
+
expect(solr_resp[0].id).to eq @book.id
|
238
|
+
expect(solr_resp[1].id).to eq @book2.id
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
@@ -584,7 +584,7 @@ describe ActiveFedora::Base do
|
|
584
584
|
end
|
585
585
|
|
586
586
|
it "it should find the reflection that bears the predicate" do
|
587
|
-
expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble.
|
587
|
+
expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble._reflect_on_association(:media_object)
|
588
588
|
end
|
589
589
|
end
|
590
590
|
|
@@ -604,7 +604,7 @@ describe ActiveFedora::Base do
|
|
604
604
|
end
|
605
605
|
|
606
606
|
it "it should find the reflection that bears the predicate" do
|
607
|
-
expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile.
|
607
|
+
expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile._reflect_on_association(:media_object)
|
608
608
|
end
|
609
609
|
end
|
610
610
|
|
@@ -624,7 +624,7 @@ describe ActiveFedora::Base do
|
|
624
624
|
end
|
625
625
|
|
626
626
|
it "it should find the reflection that bears the predicate" do
|
627
|
-
expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject.
|
627
|
+
expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject._reflect_on_association(:baubles)
|
628
628
|
end
|
629
629
|
end
|
630
630
|
end
|
@@ -22,8 +22,8 @@ describe ActiveFedora::Base do
|
|
22
22
|
obj = described_class.find(@obj.id)
|
23
23
|
expect(obj.foo).to_not be_new_record
|
24
24
|
expect(obj.foo.person).to eq ['bob']
|
25
|
-
person_field = ActiveFedora
|
26
|
-
solr_result = ActiveFedora::SolrService.query("{!
|
25
|
+
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
26
|
+
solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
|
27
27
|
expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
|
28
28
|
end
|
29
29
|
end
|
@@ -41,7 +41,7 @@ describe ActiveFedora::Base do
|
|
41
41
|
end
|
42
42
|
it "saves the datastream." do
|
43
43
|
expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
|
44
|
-
person_field = ActiveFedora
|
44
|
+
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
45
45
|
expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
|
46
46
|
end
|
47
47
|
end
|
@@ -164,7 +164,7 @@ describe ActiveFedora::Base do
|
|
164
164
|
let(:obj) { ExampleBase.new }
|
165
165
|
it "configures properties and solrize them" do
|
166
166
|
obj.title = ["Test"]
|
167
|
-
expect(obj.to_solr[ActiveFedora
|
167
|
+
expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name("title", :symbol)]).to eq ["Test"]
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -131,11 +131,11 @@ describe ActiveFedora::Base do
|
|
131
131
|
|
132
132
|
@test_history.save
|
133
133
|
|
134
|
-
@solr_result = OralHistory.
|
134
|
+
@solr_result = OralHistory.search_with_conditions(id: @test_history.id)[0]
|
135
135
|
@properties_sample_values.each_pair do |field, value|
|
136
136
|
next if field == :hard_copy_availability # FIXME: HYDRA-824
|
137
137
|
next if field == :location # FIXME HYDRA-825
|
138
|
-
expect((@solr_result[ActiveFedora
|
138
|
+
expect((@solr_result[ActiveFedora.index_field_mapper.solr_name(field, type: :string)] || @solr_result[ActiveFedora.index_field_mapper.solr_name(field, type: :date)])).to eq [::Solrizer::Extractor.format_node_value(value)]
|
139
139
|
end
|
140
140
|
|
141
141
|
@dublin_core_sample_values.each_pair do |field, value|
|
@@ -153,8 +153,8 @@ describe ActiveFedora::Base do
|
|
153
153
|
expect(dc_xml.root.elements["dcterms:subject"].text).to eq "My Subject Heading"
|
154
154
|
end
|
155
155
|
|
156
|
-
it "supports #
|
157
|
-
solr_result = OralHistory.
|
156
|
+
it "supports #search_with_conditions" do
|
157
|
+
solr_result = OralHistory.search_with_conditions({})
|
158
158
|
expect(solr_result).to_not be_nil
|
159
159
|
end
|
160
160
|
end
|
@@ -395,7 +395,7 @@ describe ActiveFedora::Base do
|
|
395
395
|
end
|
396
396
|
|
397
397
|
context "when the has_and_belongs_to_many provides an inverse_of" do
|
398
|
-
let(:reflection) { Component.
|
398
|
+
let(:reflection) { Component._reflect_on_association(:items) }
|
399
399
|
before do
|
400
400
|
reflection.options[:inverse_of] = :components
|
401
401
|
end
|
@@ -27,6 +27,35 @@ describe ActiveFedora::Associations::HasManyAssociation do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context "when the owner is not saved, and potential targets (Books) exist" do
|
31
|
+
let!(:book) { Book.create }
|
32
|
+
let(:library) { Library.new }
|
33
|
+
subject { library.books.count }
|
34
|
+
it "it excludes the books that aren't associated" do
|
35
|
+
expect(subject).to eq 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the owner is saved with associations" do
|
40
|
+
let(:book) { Book.create }
|
41
|
+
let!(:library) { Library.create(books: [book]) }
|
42
|
+
subject { library.reload; library.books.count }
|
43
|
+
it "it excludes the books that are associated" do
|
44
|
+
expect(subject).to eq 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the owner is not saved after checking the count" do
|
49
|
+
let!(:book) { Book.create }
|
50
|
+
let(:library) { Library.new }
|
51
|
+
it "refreshes the cache" do
|
52
|
+
expect(library.books.count).to eq 0
|
53
|
+
library.books << book
|
54
|
+
library.save!
|
55
|
+
expect(library.books.count).to eq 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
30
59
|
context "loading the association prior to a save that affects the association" do
|
31
60
|
let(:library) { Library.new }
|
32
61
|
before do
|
@@ -61,7 +90,7 @@ describe ActiveFedora::Associations::HasManyAssociation do
|
|
61
90
|
expect(library.books).to be_loaded
|
62
91
|
end
|
63
92
|
it "loads from solr" do
|
64
|
-
expect(library.books.load_from_solr.map
|
93
|
+
expect(library.books.load_from_solr.map(&:id)).to eq([book.id])
|
65
94
|
end
|
66
95
|
it "loads from solr with options" do
|
67
96
|
expect(library.books.load_from_solr(rows: 0).size).to eq(0)
|
@@ -98,7 +98,7 @@ describe "Indirect containers" do
|
|
98
98
|
context "when the class is implied" do
|
99
99
|
before do
|
100
100
|
class FooHistory < ActiveFedora::Base
|
101
|
-
# TODO: inserted_content_relation can look up the predicate at options[:through].constantize.
|
101
|
+
# TODO: inserted_content_relation can look up the predicate at options[:through].constantize._reflect_on_association(options[:foreign_key]).predicate
|
102
102
|
indirectly_contains :related_objects,
|
103
103
|
has_member_relation: ::RDF::URI.new('http://www.openarchives.org/ore/terms/aggregates'),
|
104
104
|
inserted_content_relation: ::RDF::URI.new('http://www.openarchives.org/ore/terms/proxyFor'),
|
@@ -102,6 +102,12 @@ describe "NestedAttribute behavior" do
|
|
102
102
|
it "creates a new record" do
|
103
103
|
expect {
|
104
104
|
car.update bars_attributes: [{ uno: "bar1 uno", _destroy: "1" }]
|
105
|
+
}.to change { car.bars(true).count }.by(1)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not create a new record if reject_if conditions are triggered" do
|
109
|
+
expect {
|
110
|
+
car.update bars_attributes: [{ uno: "", _destroy: "1" }]
|
105
111
|
}.not_to change { car.bars(true).count }
|
106
112
|
end
|
107
113
|
end
|
@@ -92,21 +92,21 @@ EOF
|
|
92
92
|
subject.date_uploaded = [Date.parse('2012-11-02')]
|
93
93
|
expect(subject.date_uploaded.first).to be_kind_of Date
|
94
94
|
solr_document = subject.to_solr
|
95
|
-
expect(solr_document[ActiveFedora
|
95
|
+
expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__date_uploaded', type: :date)]).to eq ['2012-11-02T00:00:00Z']
|
96
96
|
end
|
97
97
|
it "handles integers" do
|
98
98
|
subject.filesize = 12_345
|
99
99
|
expect(subject.filesize).to be_kind_of Fixnum
|
100
100
|
solr_document = subject.to_solr
|
101
|
-
expect(solr_document[ActiveFedora
|
101
|
+
expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__filesize', :stored_sortable, type: :integer)]).to eq '12345'
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
it "produces a solr document" do
|
106
106
|
@subject = RdfTest.new(title: "War and Peace")
|
107
107
|
solr_document = @subject.to_solr
|
108
|
-
expect(solr_document[ActiveFedora
|
109
|
-
expect(solr_document[ActiveFedora
|
108
|
+
expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__title', :facetable)]).to eq ["War and Peace"]
|
109
|
+
expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__title', type: :string)]).to eq ["War and Peace"]
|
110
110
|
end
|
111
111
|
|
112
112
|
it "sets and recall values" do
|
@@ -72,7 +72,7 @@ describe ActiveFedora::OmDatastream do
|
|
72
72
|
obj.reload
|
73
73
|
end
|
74
74
|
it "solrizes terms with :type=>'date' to *_dt solr terms" do
|
75
|
-
expect(obj.to_solr[ActiveFedora
|
75
|
+
expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq ['2012-11-02T00:00:00Z']
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -16,7 +16,7 @@ describe ActiveFedora::Model do
|
|
16
16
|
|
17
17
|
def to_solr(doc = {})
|
18
18
|
doc = super
|
19
|
-
doc[ActiveFedora
|
19
|
+
doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
|
20
20
|
doc
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ describe ActiveFedora::Querying do
|
|
16
16
|
|
17
17
|
def to_solr(doc = {})
|
18
18
|
doc = super
|
19
|
-
doc[ActiveFedora
|
19
|
+
doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
|
20
20
|
doc
|
21
21
|
end
|
22
22
|
end
|
@@ -64,12 +64,12 @@ describe ActiveFedora::Querying do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "queries" do
|
67
|
-
field = ActiveFedora
|
67
|
+
field = ActiveFedora.index_field_mapper.solr_name('foo', type: :string)
|
68
68
|
expect(ModelIntegrationSpec::Basic.where(field => 'Beta')).to eq [test_instance1]
|
69
69
|
expect(ModelIntegrationSpec::Basic.where('foo' => 'Beta')).to eq [test_instance1]
|
70
70
|
end
|
71
71
|
it "orders" do
|
72
|
-
expect(ModelIntegrationSpec::Basic.order(ActiveFedora
|
72
|
+
expect(ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')).to eq [test_instance2, test_instance1, test_instance3]
|
73
73
|
end
|
74
74
|
it "limits" do
|
75
75
|
expect(ModelIntegrationSpec::Basic.limit(1)).to eq [test_instance1]
|
@@ -79,7 +79,7 @@ describe ActiveFedora::Querying do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "chains queries" do
|
82
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora
|
82
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc').limit(1)).to eq [test_instance2]
|
83
83
|
end
|
84
84
|
|
85
85
|
it "wraps string conditions with parentheses" do
|
@@ -87,31 +87,31 @@ describe ActiveFedora::Querying do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it "chains where queries" do
|
90
|
-
first_condition = { ActiveFedora
|
90
|
+
first_condition = { ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts' }
|
91
91
|
second_condition = "foo_tesim:bar"
|
92
92
|
where_values = ModelIntegrationSpec::Basic.where(first_condition)
|
93
93
|
.where(second_condition).where_values
|
94
|
-
expect(where_values).to eq ["bar_tesim
|
94
|
+
expect(where_values).to eq ["_query_:\"{!field f=bar_tesim}Peanuts\"",
|
95
95
|
"(foo_tesim:bar)"]
|
96
96
|
end
|
97
97
|
|
98
98
|
it "chains count" do
|
99
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora
|
99
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').count).to eq 2
|
100
100
|
end
|
101
101
|
|
102
102
|
it "calling first should not affect the relation's ability to get all results later" do
|
103
|
-
relation = ModelIntegrationSpec::Basic.where(ActiveFedora
|
103
|
+
relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
|
104
104
|
expect { relation.first }.not_to change { relation.to_a.size }
|
105
105
|
end
|
106
106
|
|
107
107
|
it "calling where should not affect the relation's ability to get all results later" do
|
108
|
-
relation = ModelIntegrationSpec::Basic.where(ActiveFedora
|
109
|
-
expect { relation.where(ActiveFedora
|
108
|
+
relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
|
109
|
+
expect { relation.where(ActiveFedora.index_field_mapper.solr_name('foo', type: :string) => 'bar') }.not_to change { relation.to_a.size }
|
110
110
|
end
|
111
111
|
|
112
112
|
it "calling order should not affect the original order of the relation later" do
|
113
|
-
relation = ModelIntegrationSpec::Basic.order(ActiveFedora
|
114
|
-
expect { relation.order(ActiveFedora
|
113
|
+
relation = ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')
|
114
|
+
expect { relation.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' desc') }.not_to change { relation.to_a }
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::SolrHit do
|
4
|
+
before do
|
5
|
+
class Foo < ActiveFedora::Base
|
6
|
+
has_metadata 'descMetadata', type: ActiveFedora::SimpleDatastream do |m|
|
7
|
+
m.field "foo", :text
|
8
|
+
m.field "bar", :text
|
9
|
+
end
|
10
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
11
|
+
has_attributes :foo, datastream: 'descMetadata', multiple: true
|
12
|
+
has_attributes :bar, datastream: 'descMetadata', multiple: false
|
13
|
+
end
|
14
|
+
property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:another) { Foo.create }
|
19
|
+
|
20
|
+
let!(:obj) { Foo.create!(
|
21
|
+
id: 'test-123',
|
22
|
+
foo: ["baz"],
|
23
|
+
bar: 'quix',
|
24
|
+
title: 'My Title'
|
25
|
+
) }
|
26
|
+
|
27
|
+
let(:profile) { { "foo" => ["baz"], "bar" => "quix", "title" => "My Title" }.to_json }
|
28
|
+
let(:doc) { { 'id' => 'test-123', 'has_model_ssim' => ['Foo'], 'object_profile_ssm' => profile } }
|
29
|
+
let(:solr_hit) { described_class.new(doc) }
|
30
|
+
|
31
|
+
after do
|
32
|
+
Object.send(:remove_const, :Foo)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#reify" do
|
36
|
+
subject { solr_hit.reify }
|
37
|
+
|
38
|
+
it "finds the document in solr" do
|
39
|
+
expect(subject).to be_instance_of Foo
|
40
|
+
expect(subject.title).to eq 'My Title'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#instantiate_with_json" do
|
45
|
+
subject { solr_hit.instantiate_with_json }
|
46
|
+
|
47
|
+
it "finds the document in solr" do
|
48
|
+
expect(subject).to be_instance_of Foo
|
49
|
+
expect(subject.title).to eq 'My Title'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -508,8 +508,8 @@ module Hydra
|
|
508
508
|
def to_solr(solr_doc = {}, opts = {})
|
509
509
|
solr_doc = super
|
510
510
|
|
511
|
-
::Solrizer::Extractor.insert_solr_field_value(solr_doc,
|
512
|
-
::Solrizer::Extractor.insert_solr_field_value(solr_doc,
|
511
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, ActiveFedora.index_field_mapper.solr_name('object_type', :facetable), "Article")
|
512
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, ActiveFedora.index_field_mapper.solr_name('mods_journal_title_info', :facetable), "Unknown") if solr_doc["mods_journal_title_info_facet"].nil?
|
513
513
|
|
514
514
|
solr_doc
|
515
515
|
end
|