active-fedora 9.9.0 → 9.10.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 +4 -4
- data/.rubocop.yml +20 -6
- data/.travis.yml +2 -6
- data/History.txt +146 -0
- data/active-fedora.gemspec +11 -8
- data/lib/active_fedora/associations/association.rb +44 -14
- data/lib/active_fedora/associations/association_scope.rb +6 -2
- data/lib/active_fedora/associations/basic_contains_association.rb +2 -3
- data/lib/active_fedora/associations/belongs_to_association.rb +23 -14
- data/lib/active_fedora/associations/builder/association.rb +95 -41
- data/lib/active_fedora/associations/builder/belongs_to.rb +30 -2
- data/lib/active_fedora/associations/builder/collection_association.rb +36 -4
- data/lib/active_fedora/associations/builder/contains.rb +10 -5
- data/lib/active_fedora/associations/builder/directly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +27 -20
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +7 -3
- data/lib/active_fedora/associations/builder/has_many.rb +8 -45
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/property.rb +6 -12
- data/lib/active_fedora/associations/builder/singular_association.rb +3 -5
- data/lib/active_fedora/associations/builder/singular_property.rb +5 -4
- data/lib/active_fedora/associations/collection_association.rb +22 -26
- 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 +2 -3
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +24 -5
- data/lib/active_fedora/associations/rdf.rb +1 -20
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/attached_files.rb +2 -2
- data/lib/active_fedora/attribute_assignment.rb +55 -0
- data/lib/active_fedora/attribute_methods/read.rb +29 -44
- data/lib/active_fedora/attribute_methods/write.rb +16 -19
- data/lib/active_fedora/attribute_methods.rb +149 -29
- data/lib/active_fedora/attributes.rb +6 -18
- data/lib/active_fedora/autosave_association.rb +8 -12
- data/lib/active_fedora/base.rb +2 -2
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/callbacks.rb +9 -9
- data/lib/active_fedora/common.rb +67 -0
- data/lib/active_fedora/core.rb +11 -23
- data/lib/active_fedora/default_model_mapper.rb +24 -0
- data/lib/active_fedora/errors.rb +42 -0
- data/lib/active_fedora/fedora.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +9 -10
- data/lib/active_fedora/file.rb +19 -56
- data/lib/active_fedora/file_persistence.rb +27 -0
- data/lib/active_fedora/indexing.rb +15 -9
- data/lib/active_fedora/indexing_service.rb +4 -4
- data/lib/active_fedora/inheritance.rb +34 -0
- 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 +23 -5
- 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 +212 -80
- data/lib/active_fedora/relation/calculations.rb +1 -5
- data/lib/active_fedora/relation/finder_methods.rb +39 -26
- data/lib/active_fedora/relation.rb +17 -0
- data/lib/active_fedora/scoping/default.rb +117 -0
- data/lib/active_fedora/scoping/named.rb +152 -4
- data/lib/active_fedora/scoping.rb +85 -2
- 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/boolean.rb +23 -0
- data/lib/active_fedora/type/value.rb +118 -0
- data/lib/active_fedora/type.rb +8 -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/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +35 -15
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +4 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +4 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +5 -0
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +15 -0
- data/solr/config/solrconfig.xml +15 -0
- data/spec/config_helper.rb +0 -5
- data/spec/integration/associations_spec.rb +5 -5
- data/spec/integration/attached_files_spec.rb +4 -4
- data/spec/integration/base_spec.rb +4 -4
- data/spec/integration/bug_spec.rb +0 -1
- data/spec/integration/collection_association_spec.rb +34 -3
- data/spec/integration/file_spec.rb +2 -2
- 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 +7 -7
- data/spec/integration/persistence_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +1 -1
- data/spec/integration/scoped_query_spec.rb +13 -13
- 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/attributes_spec.rb +13 -7
- 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/collection_proxy_spec.rb +1 -1
- data/spec/unit/default_model_mapper_spec.rb +39 -0
- data/spec/unit/file_spec.rb +21 -2
- data/spec/unit/finder_methods_spec.rb +30 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +4 -4
- data/spec/unit/has_many_association_spec.rb +25 -3
- 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/reflection_spec.rb +2 -2
- 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
- data/spec/unit/validations_spec.rb +1 -1
- metadata +82 -20
- data/spec/support/freeze_mocks.rb +0 -12
|
@@ -11,8 +11,6 @@ describe ActiveFedora::Base do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
let(:library) { Library.create! }
|
|
14
|
-
let!(:book1) { Book.create!(library: library) }
|
|
15
|
-
let!(:book2) { Book.create!(library: library) }
|
|
16
14
|
|
|
17
15
|
after do
|
|
18
16
|
Object.send(:remove_const, :Library)
|
|
@@ -20,6 +18,9 @@ describe ActiveFedora::Base do
|
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
describe "load_from_solr" do
|
|
21
|
+
let!(:book1) { Book.create!(library: library) }
|
|
22
|
+
let!(:book2) { Book.create!(library: library) }
|
|
23
|
+
|
|
23
24
|
it "sets rows to count, if not specified" do
|
|
24
25
|
expect(library.books(response_format: :solr).size).to eq 2
|
|
25
26
|
end
|
|
@@ -35,6 +36,8 @@ describe ActiveFedora::Base do
|
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
describe "#delete_all" do
|
|
39
|
+
let!(:book1) { Book.create!(library: library) }
|
|
40
|
+
let!(:book2) { Book.create!(library: library) }
|
|
38
41
|
it "deletes em" do
|
|
39
42
|
expect {
|
|
40
43
|
library.books.delete_all
|
|
@@ -59,6 +62,8 @@ describe ActiveFedora::Base do
|
|
|
59
62
|
end
|
|
60
63
|
|
|
61
64
|
describe "#destroy_all" do
|
|
65
|
+
let!(:book1) { Book.create!(library: library) }
|
|
66
|
+
let!(:book2) { Book.create!(library: library) }
|
|
62
67
|
it "deletes em" do
|
|
63
68
|
expect {
|
|
64
69
|
library.books.destroy_all
|
|
@@ -67,6 +72,8 @@ describe ActiveFedora::Base do
|
|
|
67
72
|
end
|
|
68
73
|
|
|
69
74
|
describe "#find" do
|
|
75
|
+
let!(:book1) { Book.create!(library: library) }
|
|
76
|
+
let!(:book2) { Book.create!(library: library) }
|
|
70
77
|
it "finds the record that matches" do
|
|
71
78
|
expected = library.books.find(book1.id)
|
|
72
79
|
expect(expected).to eq book1
|
|
@@ -80,8 +87,11 @@ describe ActiveFedora::Base do
|
|
|
80
87
|
end
|
|
81
88
|
|
|
82
89
|
describe "#select" do
|
|
90
|
+
let!(:book1) { Book.create!(library: library) }
|
|
91
|
+
let!(:book2) { Book.create!(library: library) }
|
|
92
|
+
|
|
83
93
|
# TODO: Bug described in issue #609
|
|
84
|
-
xit "
|
|
94
|
+
xit "chooses a subset of objects in the relationship" do
|
|
85
95
|
expect(library.books.select([:id])).to include(book1.id)
|
|
86
96
|
end
|
|
87
97
|
it "works as a block" do
|
|
@@ -89,6 +99,27 @@ describe ActiveFedora::Base do
|
|
|
89
99
|
end
|
|
90
100
|
end
|
|
91
101
|
|
|
102
|
+
describe "#size" do
|
|
103
|
+
context "with associations in memory" do
|
|
104
|
+
context "and the association is already loaded" do
|
|
105
|
+
before do
|
|
106
|
+
library.books.to_a # force the association to be loaded
|
|
107
|
+
library.books.build
|
|
108
|
+
end
|
|
109
|
+
subject { library.books.size }
|
|
110
|
+
it { is_expected.to eq 1 }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context "and the association is not loaded" do
|
|
114
|
+
before do
|
|
115
|
+
library.books.build
|
|
116
|
+
end
|
|
117
|
+
subject { library.books.size }
|
|
118
|
+
it { is_expected.to eq 1 }
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
92
123
|
describe "finding the inverse" do
|
|
93
124
|
context "when no inverse exists" do
|
|
94
125
|
before do
|
|
@@ -108,8 +108,8 @@ describe ActiveFedora::File do
|
|
|
108
108
|
test_object.save
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
-
it "
|
|
112
|
-
expect(test_object.attached_files[path]).to_not
|
|
111
|
+
it "is not changed" do
|
|
112
|
+
expect(test_object.attached_files[path]).to_not be_content_changed
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "is able to read the content from fedora" do
|
|
@@ -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
|
|
@@ -30,15 +30,15 @@ describe ActiveFedora::OmDatastream do
|
|
|
30
30
|
end
|
|
31
31
|
it "does not be changed if the new xml matches the old xml" do
|
|
32
32
|
subject.content = subject.content
|
|
33
|
-
expect(subject).to_not
|
|
33
|
+
expect(subject).to_not be_content_changed
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "is changed if there are minor differences in whitespace" do
|
|
37
37
|
subject.content = "<a><b>1</b></a>"
|
|
38
38
|
obj.save
|
|
39
|
-
expect(subject).to_not
|
|
39
|
+
expect(subject).to_not be_content_changed
|
|
40
40
|
subject.content = "<a>\n<b>1</b>\n</a>"
|
|
41
|
-
expect(subject).to
|
|
41
|
+
expect(subject).to be_content_changed
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -56,11 +56,11 @@ describe ActiveFedora::OmDatastream do
|
|
|
56
56
|
obj.reload
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
it "
|
|
59
|
+
it "is not dirty after .update_values is saved" do
|
|
60
60
|
obj.descMetadata.update_values([{ name: 0 }, { role: 0 }, :text] => "Funder")
|
|
61
|
-
expect(obj.descMetadata).to
|
|
61
|
+
expect(obj.descMetadata).to be_content_changed
|
|
62
62
|
obj.save
|
|
63
|
-
expect(obj.descMetadata).to_not
|
|
63
|
+
expect(obj.descMetadata).to_not be_content_changed
|
|
64
64
|
expect(obj.descMetadata.term_values({ name: 0 }, { role: 0 }, :text)).to eq ["Funder"]
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -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
|
|
@@ -7,7 +7,7 @@ describe "persisting objects" do
|
|
|
7
7
|
has_metadata type: ActiveFedora::SimpleDatastream, name: "foo" do |m|
|
|
8
8
|
m.field "name", :string
|
|
9
9
|
end
|
|
10
|
-
property :name,
|
|
10
|
+
property :name, predicate: ::RDF::Vocab::DC.title, multiple: false
|
|
11
11
|
validates :name, presence: true
|
|
12
12
|
end
|
|
13
13
|
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
|
|
@@ -39,7 +39,7 @@ describe ActiveFedora::Querying do
|
|
|
39
39
|
result = ModelIntegrationSpec::Basic.all.to_a
|
|
40
40
|
expect(result).to be_instance_of(Array)
|
|
41
41
|
# this test is meaningless if the array length is zero
|
|
42
|
-
expect(result.length
|
|
42
|
+
expect(result.length).to be > 0
|
|
43
43
|
expect(result).to all(be_an(ModelIntegrationSpec::Basic))
|
|
44
44
|
end
|
|
45
45
|
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
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
ENV["environment"] ||= 'test'
|
|
2
2
|
require "bundler/setup"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
SimpleCov.start do
|
|
10
|
-
add_filter "/spec/"
|
|
11
|
-
add_filter "/gemfiles/"
|
|
12
|
-
end
|
|
4
|
+
require 'simplecov'
|
|
5
|
+
require 'coveralls'
|
|
6
|
+
|
|
7
|
+
SimpleCov.start do
|
|
8
|
+
add_filter "/spec/"
|
|
13
9
|
end
|
|
14
10
|
|
|
15
11
|
require 'active-fedora'
|
|
@@ -115,30 +115,4 @@ describe ActiveFedora do
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
|
-
|
|
119
|
-
describe "#class_from_string" do
|
|
120
|
-
before do
|
|
121
|
-
module ParentClass
|
|
122
|
-
class SiblingClass
|
|
123
|
-
end
|
|
124
|
-
class OtherSiblingClass
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
it "returns class constants based on strings" do
|
|
129
|
-
expect(described_class.class_from_string("Om")).to eq Om
|
|
130
|
-
expect(described_class.class_from_string("ActiveFedora::RDF::IndexingService")).to eq ActiveFedora::RDF::IndexingService
|
|
131
|
-
expect(described_class.class_from_string("IndexingService", ActiveFedora::RDF)).to eq ActiveFedora::RDF::IndexingService
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "finds sibling classes" do
|
|
135
|
-
expect(described_class.class_from_string("SiblingClass", ParentClass::OtherSiblingClass)).to eq ParentClass::SiblingClass
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "raises a NameError if the class isn't found" do
|
|
139
|
-
expect {
|
|
140
|
-
described_class.class_from_string("FooClass", ParentClass::OtherSiblingClass)
|
|
141
|
-
}.to raise_error NameError, "uninitialized constant FooClass"
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
118
|
end
|
|
@@ -38,7 +38,9 @@ describe ActiveFedora::Base do
|
|
|
38
38
|
before do
|
|
39
39
|
class BarHistory4 < ActiveFedora::Base
|
|
40
40
|
has_metadata type: BarStream2, name: "xmlish"
|
|
41
|
-
|
|
41
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
42
|
+
property :cow, delegate_to: 'xmlish'
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
after do
|
|
@@ -63,7 +65,9 @@ describe ActiveFedora::Base do
|
|
|
63
65
|
before do
|
|
64
66
|
class BarHistory4 < ActiveFedora::Base
|
|
65
67
|
has_metadata type: BarStream2, name: "xmlish"
|
|
66
|
-
|
|
68
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
69
|
+
property :cow, delegate_to: 'xmlish', multiple: false
|
|
70
|
+
end
|
|
67
71
|
end
|
|
68
72
|
end
|
|
69
73
|
after do
|
|
@@ -83,7 +87,9 @@ describe ActiveFedora::Base do
|
|
|
83
87
|
before do
|
|
84
88
|
class BarHistory4 < ActiveFedora::Base
|
|
85
89
|
has_metadata type: BarStream2, name: "xmlish"
|
|
86
|
-
|
|
90
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
91
|
+
property :cow, delegate_to: 'xmlish', multiple: false
|
|
92
|
+
end
|
|
87
93
|
end
|
|
88
94
|
end
|
|
89
95
|
after do
|
|
@@ -294,17 +300,17 @@ describe ActiveFedora::Base do
|
|
|
294
300
|
end
|
|
295
301
|
|
|
296
302
|
it "raises an error on the reader when the field isn't delegated" do
|
|
297
|
-
expect { subject['donkey'] }.to raise_error ActiveFedora::UnknownAttributeError, "
|
|
303
|
+
expect { subject['donkey'] }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'donkey' for BarHistory2."
|
|
298
304
|
end
|
|
299
305
|
|
|
300
306
|
it "raises an error on the setter when the field isn't delegated" do
|
|
301
|
-
expect { subject['donkey'] = "bray" }.to raise_error ActiveFedora::UnknownAttributeError, "
|
|
307
|
+
expect { subject['donkey'] = "bray" }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'donkey' for BarHistory2."
|
|
302
308
|
end
|
|
303
309
|
end
|
|
304
310
|
|
|
305
311
|
describe "attributes=" do
|
|
306
312
|
it "raises an error on an invalid attribute" do
|
|
307
|
-
expect { subject.attributes = { 'donkey' => "bray" } }.to raise_error ActiveFedora::UnknownAttributeError, "
|
|
313
|
+
expect { subject.attributes = { 'donkey' => "bray" } }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'donkey' for BarHistory2."
|
|
308
314
|
end
|
|
309
315
|
end
|
|
310
316
|
|
|
@@ -330,7 +336,7 @@ describe ActiveFedora::Base do
|
|
|
330
336
|
end
|
|
331
337
|
|
|
332
338
|
it 'raises an error if the attribute does not exist' do
|
|
333
|
-
expect { BarHistory2.multiple?(:arbitrary_nonexistent_attribute) }.to raise_error ActiveFedora::UnknownAttributeError, "
|
|
339
|
+
expect { BarHistory2.multiple?(:arbitrary_nonexistent_attribute) }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'arbitrary_nonexistent_attribute' for BarHistory2."
|
|
334
340
|
end
|
|
335
341
|
end
|
|
336
342
|
|
data/spec/unit/base_spec.rb
CHANGED
|
@@ -333,4 +333,24 @@ describe ActiveFedora::Base do
|
|
|
333
333
|
end
|
|
334
334
|
end
|
|
335
335
|
end
|
|
336
|
+
|
|
337
|
+
describe '.dangerous_attribute_method?' do
|
|
338
|
+
before do
|
|
339
|
+
class FooHistory < ActiveFedora::Base
|
|
340
|
+
type ::RDF::URI.new('http://example.com/foo')
|
|
341
|
+
property :title, predicate: ::RDF::Vocab::DC.title
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
after do
|
|
345
|
+
Object.send(:remove_const, :FooHistory)
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it 'is dangerous if it is defined by the class' do
|
|
349
|
+
expect(FooHistory.dangerous_attribute_method?(:save)).to eq true
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
it 'is not dangerous if it is defined outside of ActiveFedora' do
|
|
353
|
+
expect(FooHistory.dangerous_attribute_method?(:puts)).to eq false
|
|
354
|
+
end
|
|
355
|
+
end
|
|
336
356
|
end
|
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::Associations::Builder::HasAndBelongsToMany do
|
|
4
4
|
describe "valid_options" do
|
|
5
|
-
subject { described_class.valid_options }
|
|
6
|
-
it { should
|
|
7
|
-
:after_remove, :inverse_of, :solr_page_size, :autosave] }
|
|
5
|
+
subject { described_class.valid_options({}) }
|
|
6
|
+
it { should match_array [:class_name, :predicate, :type_validator, :before_add, :after_add, :before_remove, :after_remove, :inverse_of, :solr_page_size, :autosave] }
|
|
8
7
|
end
|
|
9
8
|
end
|
data/spec/unit/callback_spec.rb
CHANGED
|
@@ -2,11 +2,6 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::Base do
|
|
4
4
|
before :each do
|
|
5
|
-
begin
|
|
6
|
-
described_class.find('test:123').delete
|
|
7
|
-
rescue
|
|
8
|
-
end
|
|
9
|
-
|
|
10
5
|
class CallbackStub < ActiveFedora::Base
|
|
11
6
|
has_metadata type: ActiveFedora::SimpleDatastream, name: "someData" do |m|
|
|
12
7
|
m.field "fubar", :string
|
|
@@ -43,7 +38,7 @@ describe ActiveFedora::Base do
|
|
|
43
38
|
allow_any_instance_of(CallbackStub).to receive :a_create
|
|
44
39
|
allow_any_instance_of(CallbackStub).to receive(:b_save)
|
|
45
40
|
allow_any_instance_of(CallbackStub).to receive(:a_save)
|
|
46
|
-
@cb = CallbackStub.new
|
|
41
|
+
@cb = CallbackStub.new
|
|
47
42
|
@cb.save
|
|
48
43
|
end
|
|
49
44
|
|
|
@@ -53,7 +48,7 @@ describe ActiveFedora::Base do
|
|
|
53
48
|
allow_any_instance_of(CallbackStub).to receive(:a_create)
|
|
54
49
|
allow_any_instance_of(CallbackStub).to receive(:b_save)
|
|
55
50
|
allow_any_instance_of(CallbackStub).to receive(:a_save)
|
|
56
|
-
@cb = CallbackStub.new
|
|
51
|
+
@cb = CallbackStub.new
|
|
57
52
|
@cb.save
|
|
58
53
|
allow_any_instance_of(CallbackStub).to receive(:a_init)
|
|
59
54
|
allow_any_instance_of(CallbackStub).to receive(:b_save)
|
|
@@ -63,7 +58,7 @@ describe ActiveFedora::Base do
|
|
|
63
58
|
allow_any_instance_of(CallbackStub).to receive(:a_update)
|
|
64
59
|
allow_any_instance_of(CallbackStub).to receive(:do_stuff)
|
|
65
60
|
|
|
66
|
-
@cb = CallbackStub.find(
|
|
61
|
+
@cb = CallbackStub.find(@cb.id)
|
|
67
62
|
@cb.save!
|
|
68
63
|
|
|
69
64
|
@cb.destroy
|
|
@@ -14,7 +14,7 @@ describe ActiveFedora::Associations::CollectionProxy do
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
describe "#spawn" do
|
|
17
|
-
let(:reflection) {
|
|
17
|
+
let(:reflection) { ActiveFedora::Reflection.create(:has_many, :pages, nil, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection }, Book) }
|
|
18
18
|
let(:association) { ActiveFedora::Associations::HasManyAssociation.new(Book.new, reflection) }
|
|
19
19
|
let(:proxy) { described_class.new(association) }
|
|
20
20
|
|