active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
it { is_expected.not_to be_readonly }
|
5
|
+
|
6
|
+
describe "#readonly!" do
|
7
|
+
it "should make the object readonly" do
|
8
|
+
expect { subject.readonly! }.to change { subject.readonly? }.from(false).to(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "a readonly record" do
|
13
|
+
before { subject.readonly! }
|
14
|
+
|
15
|
+
it "should not be destroyable" do
|
16
|
+
expect { subject.destroy }.to raise_error ActiveFedora::ReadOnlyRecord
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not be mutable" do
|
20
|
+
expect { subject.save }.to raise_error ActiveFedora::ReadOnlyRecord
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,27 +3,27 @@ require 'ostruct'
|
|
3
3
|
require "active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher"
|
4
4
|
|
5
5
|
describe RSpec::Matchers, "belong_to_associated_active_fedora_object_matcher" do
|
6
|
-
subject { OpenStruct.new(:
|
7
|
-
let(:
|
6
|
+
subject { OpenStruct.new(:id => id )}
|
7
|
+
let(:id) { 123 }
|
8
8
|
let(:object1) { Object.new }
|
9
9
|
let(:object2) { Object.new }
|
10
10
|
let(:association) { :association }
|
11
11
|
|
12
12
|
it 'should match when association is properly stored in fedora' do
|
13
|
-
expect(subject.class).to receive(:find).with(
|
13
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
14
14
|
expect(subject).to receive(association).and_return(object1)
|
15
15
|
expect(subject).to belong_to_associated_active_fedora_object(association).with_object(object1)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not match when association is different' do
|
19
|
-
expect(subject.class).to receive(:find).with(
|
19
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
20
20
|
expect(subject).to receive(association).and_return(object1)
|
21
21
|
expect {
|
22
22
|
expect(subject).to belong_to_associated_active_fedora_object(association).with_object(object2)
|
23
23
|
}.to (
|
24
24
|
raise_error(
|
25
25
|
RSpec::Expectations::ExpectationNotMetError,
|
26
|
-
/expected #{subject.class}
|
26
|
+
/expected #{subject.class} ID=#{id} association: #{association.inspect}/
|
27
27
|
)
|
28
28
|
)
|
29
29
|
end
|
@@ -34,7 +34,7 @@ describe RSpec::Matchers, "belong_to_associated_active_fedora_object_matcher" do
|
|
34
34
|
}.to(
|
35
35
|
raise_error(
|
36
36
|
ArgumentError,
|
37
|
-
"subject.
|
37
|
+
"expect(subject).to belong_to_associated_active_fedora_object(<association_name>).with_object(<object>)"
|
38
38
|
)
|
39
39
|
)
|
40
40
|
end
|
@@ -3,28 +3,28 @@ require 'ostruct'
|
|
3
3
|
require "active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher"
|
4
4
|
|
5
5
|
describe RSpec::Matchers, "have_many_associated_active_fedora_objects_matcher" do
|
6
|
-
subject { OpenStruct.new(:
|
7
|
-
let(:
|
6
|
+
subject { OpenStruct.new(:id => id )}
|
7
|
+
let(:id) { 123 }
|
8
8
|
let(:object1) { Object.new }
|
9
9
|
let(:object2) { Object.new }
|
10
10
|
let(:object3) { Object.new }
|
11
11
|
let(:association) { :association }
|
12
12
|
|
13
13
|
it 'should match when association is properly stored in fedora' do
|
14
|
-
expect(subject.class).to receive(:find).with(
|
14
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
15
15
|
expect(subject).to receive(association).and_return([object1,object2])
|
16
16
|
expect(subject).to have_many_associated_active_fedora_objects(association).with_objects([object1, object2])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should not match when association is different' do
|
20
|
-
expect(subject.class).to receive(:find).with(
|
20
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
21
21
|
expect(subject).to receive(association).and_return([object1,object3])
|
22
22
|
expect {
|
23
23
|
expect(subject).to have_many_associated_active_fedora_objects(association).with_objects([object1, object2])
|
24
24
|
}.to (
|
25
25
|
raise_error(
|
26
26
|
RSpec::Expectations::ExpectationNotMetError,
|
27
|
-
/expected #{subject.class}
|
27
|
+
/expected #{subject.class} ID=#{id} association: #{association.inspect}/
|
28
28
|
)
|
29
29
|
)
|
30
30
|
end
|
@@ -35,7 +35,7 @@ describe RSpec::Matchers, "have_many_associated_active_fedora_objects_matcher" d
|
|
35
35
|
}.to(
|
36
36
|
raise_error(
|
37
37
|
ArgumentError,
|
38
|
-
|
38
|
+
"expect(subject).to have_many_associated_active_fedora_objects(<association_name>).with_objects(<objects[]>)"
|
39
39
|
)
|
40
40
|
)
|
41
41
|
end
|
@@ -3,28 +3,28 @@ require 'ostruct'
|
|
3
3
|
require "active_fedora/rspec_matchers/have_predicate_matcher"
|
4
4
|
|
5
5
|
describe RSpec::Matchers, "have_predicate_matcher" do
|
6
|
-
subject { OpenStruct.new(:
|
7
|
-
let(:
|
6
|
+
subject { OpenStruct.new(:id => id )}
|
7
|
+
let(:id) { 123 }
|
8
8
|
let(:object1) { Object.new }
|
9
9
|
let(:object2) { Object.new }
|
10
10
|
let(:object3) { Object.new }
|
11
11
|
let(:predicate) { :predicate }
|
12
12
|
|
13
13
|
it 'should match when relationship is "what we have in Fedora"' do
|
14
|
-
expect(subject.class).to receive(:find).with(
|
14
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
15
15
|
expect(subject).to receive(:relationships).with(predicate).and_return([object1,object2])
|
16
16
|
expect(subject).to have_predicate(predicate).with_objects([object1, object2])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should not match when relationship is different' do
|
20
|
-
expect(subject.class).to receive(:find).with(
|
20
|
+
expect(subject.class).to receive(:find).with(id).and_return(subject)
|
21
21
|
expect(subject).to receive(:relationships).with(predicate).and_return([object1,object3])
|
22
22
|
expect {
|
23
23
|
expect(subject).to have_predicate(predicate).with_objects([object1, object2])
|
24
24
|
}.to (
|
25
25
|
raise_error(
|
26
26
|
RSpec::Expectations::ExpectationNotMetError,
|
27
|
-
/expected #{subject.class}
|
27
|
+
/expected #{subject.class} ID=#{id} relationship: #{predicate.inspect}/
|
28
28
|
)
|
29
29
|
)
|
30
30
|
end
|
@@ -35,7 +35,7 @@ describe RSpec::Matchers, "have_predicate_matcher" do
|
|
35
35
|
}.to(
|
36
36
|
raise_error(
|
37
37
|
ArgumentError,
|
38
|
-
|
38
|
+
"expect(subject).to have_predicate(<predicate>).with_objects(<objects[]>)"
|
39
39
|
)
|
40
40
|
)
|
41
41
|
end
|
@@ -14,7 +14,7 @@ describe ActiveFedora::Attributes::Serializers do
|
|
14
14
|
subject { Foo.new }
|
15
15
|
it "should deserialize dates" do
|
16
16
|
subject.attributes = {'birthday(1i)' =>'2012', 'birthday(2i)' =>'10', 'birthday(3i)' => '31'}
|
17
|
-
expect(subject.birthday).to eq
|
17
|
+
expect(subject.birthday).to eq '2012-10-31'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -2,34 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::SimpleDatastream do
|
4
4
|
|
5
|
+
let(:sample_xml) { "<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>2012-01-15</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>" }
|
6
|
+
|
5
7
|
before do
|
6
|
-
@
|
7
|
-
@test_ds
|
8
|
+
@test_ds = ActiveFedora::SimpleDatastream.new
|
9
|
+
allow(@test_ds).to receive(:retrieve_content).and_return('') # DS grabs the old content to compare against the new
|
10
|
+
@test_ds.content = sample_xml
|
8
11
|
@test_ds.field :coverage
|
9
12
|
@test_ds.field :creation_date, :date
|
10
13
|
@test_ds.field :mydate
|
11
|
-
@test_ds.field :prefix
|
12
14
|
@test_ds.field :publisher
|
13
|
-
end
|
14
15
|
|
15
|
-
it "from_xml should parse everything correctly" do
|
16
|
-
expect(@test_ds.ng_xml).to be_equivalent_to @sample_xml
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
expect(@test_ds.to_solr).to eq(
|
22
|
-
{
|
23
|
-
'coverage_tesim' => ['coverage1', 'coverage2'],
|
24
|
-
'creation_date_dtsim' => '2012-01-15',
|
25
|
-
'mydate_tesim' => 'fake-date',
|
26
|
-
'prefix_tesim' => 'foobar',
|
27
|
-
'publisher_tesim' => 'publisher1'
|
28
|
-
}
|
29
|
-
)
|
30
|
-
end
|
18
|
+
it "ng_xml should parse everything correctly" do
|
19
|
+
expect(@test_ds.ng_xml).to be_equivalent_to sample_xml
|
31
20
|
end
|
32
21
|
|
22
|
+
|
33
23
|
describe '#new' do
|
34
24
|
describe "model methods" do
|
35
25
|
|
@@ -37,14 +27,14 @@ describe ActiveFedora::SimpleDatastream do
|
|
37
27
|
it "should respond to getters and setters for the string typed #{el} element" do
|
38
28
|
value = "Hey #{el}"
|
39
29
|
@test_ds.send("#{el.to_s}=", value)
|
40
|
-
expect(@test_ds.send(el).first).to eq
|
30
|
+
expect(@test_ds.send(el).first).to eq value #Looking at first because creator has 2 nodes
|
41
31
|
end
|
42
32
|
end
|
43
33
|
|
44
34
|
it "should set date elements" do
|
45
35
|
d = Date.parse('1939-05-23')
|
46
36
|
@test_ds.creation_date = d
|
47
|
-
expect(@test_ds.creation_date.first).to eq
|
37
|
+
expect(@test_ds.creation_date.first).to eq d
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
@@ -60,7 +50,6 @@ describe ActiveFedora::SimpleDatastream do
|
|
60
50
|
<coverage>20%</coverage>
|
61
51
|
<creation_date>2012-01-15</creation_date>
|
62
52
|
<mydate>fake-date</mydate>
|
63
|
-
<prefix>foobar</prefix>
|
64
53
|
<publisher>charlie</publisher>
|
65
54
|
</fields>')
|
66
55
|
end
|
@@ -69,8 +58,8 @@ describe ActiveFedora::SimpleDatastream do
|
|
69
58
|
describe "#to_solr" do
|
70
59
|
it "should have title" do
|
71
60
|
solr = @test_ds.to_solr
|
72
|
-
expect(solr[ActiveFedora::SolrService.solr_name('publisher', type: :string)]).to eq
|
73
|
-
expect(solr[ActiveFedora::SolrService.solr_name('creation_date', type: :date)]).to eq
|
61
|
+
expect(solr[ActiveFedora::SolrService.solr_name('publisher', type: :string)]).to eq "publisher1"
|
62
|
+
expect(solr[ActiveFedora::SolrService.solr_name('creation_date', type: :date)]).to eq "2012-01-15"
|
74
63
|
end
|
75
64
|
end
|
76
65
|
|
@@ -1,21 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
module SolrSpecModel
|
7
7
|
class Basic < ActiveFedora::Base
|
8
|
-
def init_with_object(inner_obj)
|
9
|
-
end
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
13
|
-
|
11
|
+
|
14
12
|
before(:each) do
|
15
13
|
@test_object = ActiveFedora::Base.new
|
16
14
|
end
|
17
|
-
|
18
|
-
|
15
|
+
|
19
16
|
describe "SOLR_DOCUMENT_ID" do
|
20
17
|
before(:all) do
|
21
18
|
SOLR_DOCUMENT_ID = "MY_SAMPLE_ID"
|
@@ -24,40 +21,40 @@ describe ActiveFedora do
|
|
24
21
|
SOLR_DOCUMENT_ID = "id"
|
25
22
|
end
|
26
23
|
it "should be used by ActiveFedora::Base.to_solr" do
|
27
|
-
allow(@test_object).to
|
24
|
+
allow(@test_object).to receive(:id).and_return('changeme:123')
|
28
25
|
SOLR_DOCUMENT_ID = "MY_SAMPLE_ID"
|
29
|
-
expect(@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym]).to eq
|
26
|
+
expect(@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym]).to eq 'changeme:123'
|
30
27
|
expect(@test_object.to_solr[:id]).to be_nil
|
31
28
|
end
|
32
29
|
|
33
30
|
it "should be used by ActiveFedora::Base#find_with_conditions" do
|
34
31
|
mock_response = double("SolrResponse")
|
35
|
-
expect(ActiveFedora::SolrService).to receive(:query).with("_query_:\"{!raw f=#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}}
|
36
|
-
|
32
|
+
expect(ActiveFedora::SolrService).to receive(:query).with("_query_:\"{!raw f=#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}}SolrSpecModel::Basic\" AND " + SOLR_DOCUMENT_ID + ':changeme\\:30', {:sort => ["#{ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)} asc"]}).and_return(mock_response)
|
33
|
+
|
37
34
|
expect(SolrSpecModel::Basic.find_with_conditions(:id=>"changeme:30")).to equal(mock_response)
|
38
35
|
end
|
39
36
|
end
|
40
|
-
|
37
|
+
|
41
38
|
describe "ENABLE_SOLR_UPDATES" do
|
42
|
-
|
39
|
+
|
43
40
|
before(:all) do
|
44
41
|
ENABLE_SOLR_UPDATES = false
|
45
42
|
end
|
46
43
|
after(:all) do
|
47
44
|
ENABLE_SOLR_UPDATES = true
|
48
45
|
end
|
49
|
-
|
46
|
+
|
50
47
|
it "should prevent Base.save from calling update_index if false" do
|
51
|
-
dirty_ds = ActiveFedora::SimpleDatastream.new
|
52
|
-
@test_object.
|
48
|
+
dirty_ds = ActiveFedora::SimpleDatastream.new
|
49
|
+
@test_object.attached_files['ds1'] = dirty_ds
|
53
50
|
allow(@test_object).to receive(:datastreams).and_return({:ds1 => dirty_ds})
|
54
51
|
expect(@test_object).to receive(:update_index).never
|
55
52
|
expect(@test_object).to receive(:refresh)
|
56
53
|
@test_object.save
|
57
54
|
end
|
58
55
|
it "should prevent Base.delete from deleting the corresponding Solr document if false" do
|
59
|
-
expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(@test_object.
|
60
|
-
expect(@test_object
|
56
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(@test_object.id).never
|
57
|
+
expect(@test_object).to receive(:delete)
|
61
58
|
@test_object.delete
|
62
59
|
end
|
63
60
|
end
|
@@ -4,12 +4,12 @@ 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
|
-
|
12
|
-
it "should take a
|
11
|
+
|
12
|
+
it "should take a n-arg 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
|
15
15
|
end
|
@@ -25,86 +25,70 @@ describe ActiveFedora::SolrService do
|
|
25
25
|
it "should set the threadlocal solr service" do
|
26
26
|
expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://localhost:8080/solr', :autocommit=>:off, :foo=>:bar)
|
27
27
|
ss = ActiveFedora::SolrService.register(nil, {:autocommit=>:off, :foo=>:bar})
|
28
|
-
expect(Thread.current[:solr_service]).to eq
|
29
|
-
expect(ActiveFedora::SolrService.instance).to eq
|
28
|
+
expect(Thread.current[:solr_service]).to eq ss
|
29
|
+
expect(ActiveFedora::SolrService.instance).to eq ss
|
30
30
|
end
|
31
31
|
it "should try to initialize if the service not initialized, and fail if it does not succeed" do
|
32
32
|
expect(Thread.current[:solr_service]).to be_nil
|
33
33
|
expect(ActiveFedora::SolrService).to receive(:register)
|
34
|
-
expect{ActiveFedora::SolrService.instance}.to raise_error(ActiveFedora::SolrNotInitialized)
|
34
|
+
expect(proc{ActiveFedora::SolrService.instance}).to raise_error(ActiveFedora::SolrNotInitialized)
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "reify solr results" do
|
38
38
|
before(:all) do
|
39
39
|
class AudioRecord
|
40
|
-
attr_accessor :
|
41
|
-
def
|
42
|
-
self.pid = inner_obj.pid
|
43
|
-
self
|
44
|
-
end
|
45
|
-
def self.connection_for_pid(pid)
|
40
|
+
attr_accessor :id
|
41
|
+
def self.connection_for_id(id)
|
46
42
|
end
|
47
43
|
end
|
48
|
-
@sample_solr_hits = [{"id"=>"my:
|
49
|
-
{"id"=>"my:
|
50
|
-
{"id"=>"my:
|
44
|
+
@sample_solr_hits = [{"id"=>"my:_ID1_", ActiveFedora::SolrService.solr_name("has_model", :symbol)=>["AudioRecord"]},
|
45
|
+
{"id"=>"my:_ID2_", ActiveFedora::SolrService.solr_name("has_model", :symbol)=>["AudioRecord"]},
|
46
|
+
{"id"=>"my:_ID3_", ActiveFedora::SolrService.solr_name("has_model", :symbol)=>["AudioRecord"]}]
|
51
47
|
end
|
52
48
|
describe ".reify_solr_result" do
|
53
49
|
it "should use .find to instantiate objects" do
|
54
|
-
expect(AudioRecord).to receive(:find).with("my:
|
50
|
+
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
55
51
|
ActiveFedora::SolrService.reify_solr_result(@sample_solr_hits.first)
|
56
52
|
end
|
57
|
-
it "should use .load_instance_from_solr when called with :load_from_solr option" do
|
58
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits.first)
|
59
|
-
expect(ActiveFedora::SolrService).not_to receive(:query)
|
60
|
-
ActiveFedora::SolrService.reify_solr_result(@sample_solr_hits.first, load_from_solr: true)
|
61
|
-
end
|
62
53
|
end
|
63
54
|
describe ".reify_solr_results" do
|
64
55
|
it "should use AudioRecord.find to instantiate objects" do
|
65
|
-
expect(AudioRecord).to receive(:find).with("my:
|
66
|
-
expect(AudioRecord).to receive(:find).with("my:
|
67
|
-
expect(AudioRecord).to receive(:find).with("my:
|
56
|
+
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
57
|
+
expect(AudioRecord).to receive(:find).with("my:_ID2_", cast: true)
|
58
|
+
expect(AudioRecord).to receive(:find).with("my:_ID3_", cast: true)
|
68
59
|
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits)
|
69
60
|
end
|
70
|
-
it "should use AudioRecord.load_instance_from_solr when called with :load_from_solr option" do
|
71
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
|
72
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
|
73
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
|
74
|
-
expect(ActiveFedora::SolrService).not_to receive(:query)
|
75
|
-
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits, load_from_solr: true)
|
76
|
-
end
|
77
61
|
end
|
78
62
|
describe ".lazy_reify_solr_results" do
|
79
63
|
it "should lazily reify solr results" do
|
80
|
-
expect(AudioRecord).to receive(:find).with("my:
|
81
|
-
expect(AudioRecord).to receive(:find).with("my:
|
82
|
-
expect(AudioRecord).to receive(:find).with("my:
|
64
|
+
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
65
|
+
expect(AudioRecord).to receive(:find).with("my:_ID2_", cast: true)
|
66
|
+
expect(AudioRecord).to receive(:find).with("my:_ID3_", cast: true)
|
83
67
|
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits).each {|r| r}
|
84
68
|
end
|
85
|
-
it "should use AudioRecord.load_instance_from_solr when called with :load_from_solr option" do
|
86
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
|
87
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
|
88
|
-
expect(AudioRecord).to receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
|
89
|
-
expect(ActiveFedora::SolrService).not_to receive(:query)
|
90
|
-
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits, load_from_solr: true).each {|r| r}
|
91
|
-
end
|
92
69
|
end
|
93
70
|
end
|
94
71
|
|
95
72
|
describe "raw_query" do
|
96
73
|
it "should generate a raw query clause" do
|
97
|
-
expect(ActiveFedora::SolrService.raw_query('id', "my:
|
74
|
+
expect(ActiveFedora::SolrService.raw_query('id', "my:_ID1_")).to eq '_query_:"{!raw f=id}my:_ID1_"'
|
98
75
|
end
|
99
76
|
end
|
100
77
|
|
101
|
-
describe '#
|
102
|
-
it "should generate a useable solr query from an array of Fedora
|
103
|
-
expect(ActiveFedora::SolrService.
|
78
|
+
describe '#construct_query_for_ids' do
|
79
|
+
it "should generate a useable solr query from an array of Fedora ids" do
|
80
|
+
expect(ActiveFedora::SolrService.construct_query_for_ids(["my:_ID1_", "my:_ID2_", "my:_ID3_"])).to eq '_query_:"{!raw f=id}my:_ID1_" OR _query_:"{!raw f=id}my:_ID2_" OR _query_:"{!raw f=id}my:_ID3_"'
|
104
81
|
|
105
82
|
end
|
106
83
|
it "should return a valid solr query even if given an empty array as input" do
|
107
|
-
expect(ActiveFedora::SolrService.
|
84
|
+
expect(ActiveFedora::SolrService.construct_query_for_ids([""])).to eq "id:NEVER_USE_THIS_ID"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#construct_query_for_pids' do
|
89
|
+
it "should generate a useable solr query from an array of Fedora ids" do
|
90
|
+
expect(Deprecation).to receive(:warn)
|
91
|
+
expect(ActiveFedora::SolrService.construct_query_for_pids(["my:_ID1_", "my:_ID2_", "my:_ID3_"])).to eq '_query_:"{!raw f=id}my:_ID1_" OR _query_:"{!raw f=id}my:_ID2_" OR _query_:"{!raw f=id}my:_ID3_"'
|
108
92
|
|
109
93
|
end
|
110
94
|
end
|
@@ -114,8 +98,8 @@ describe ActiveFedora::SolrService do
|
|
114
98
|
mock_conn = double("Connection")
|
115
99
|
stub_result = double("Result")
|
116
100
|
expect(mock_conn).to receive(:get).with('select', :params=>{:q=>'querytext', :qt=>'standard'}).and_return(stub_result)
|
117
|
-
allow(ActiveFedora::SolrService).to
|
118
|
-
expect(ActiveFedora::SolrService.query('querytext', :raw=>true)).to eq
|
101
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
102
|
+
expect(ActiveFedora::SolrService.query('querytext', :raw=>true)).to eq stub_result
|
119
103
|
end
|
120
104
|
end
|
121
105
|
describe ".count" do
|
@@ -123,15 +107,15 @@ describe ActiveFedora::SolrService do
|
|
123
107
|
mock_conn = double("Connection")
|
124
108
|
stub_result = {'response' => {'numFound'=>'7'}}
|
125
109
|
expect(mock_conn).to receive(:get).with('select', :params=>{:rows=>0, :q=>'querytext', :qt=>'standard'}).and_return(stub_result)
|
126
|
-
allow(ActiveFedora::SolrService).to
|
127
|
-
expect(ActiveFedora::SolrService.count('querytext')).to eq
|
110
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
111
|
+
expect(ActiveFedora::SolrService.count('querytext')).to eq 7
|
128
112
|
end
|
129
113
|
it "should accept query args" do
|
130
114
|
mock_conn = double("Connection")
|
131
115
|
stub_result = {'response' => {'numFound'=>'7'}}
|
132
116
|
expect(mock_conn).to receive(:get).with('select', :params=>{:rows=>0, :q=>'querytext', :qt=>'standard', :fq=>'filter'}).and_return(stub_result)
|
133
|
-
allow(ActiveFedora::SolrService).to
|
134
|
-
expect(ActiveFedora::SolrService.count('querytext', :fq=>'filter', :rows=>10)).to eq
|
117
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
118
|
+
expect(ActiveFedora::SolrService.count('querytext', :fq=>'filter', :rows=>10)).to eq 7
|
135
119
|
end
|
136
120
|
end
|
137
121
|
describe ".add" do
|
@@ -139,7 +123,7 @@ describe ActiveFedora::SolrService do
|
|
139
123
|
mock_conn = double("Connection")
|
140
124
|
doc = {'id' => '1234'}
|
141
125
|
expect(mock_conn).to receive(:add).with(doc, {:params=>{}})
|
142
|
-
allow(ActiveFedora::SolrService).to
|
126
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
143
127
|
ActiveFedora::SolrService.add(doc)
|
144
128
|
end
|
145
129
|
end
|
@@ -148,31 +132,8 @@ describe ActiveFedora::SolrService do
|
|
148
132
|
mock_conn = double("Connection")
|
149
133
|
doc = {'id' => '1234'}
|
150
134
|
expect(mock_conn).to receive(:commit)
|
151
|
-
allow(ActiveFedora::SolrService).to
|
135
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
152
136
|
ActiveFedora::SolrService.commit()
|
153
137
|
end
|
154
138
|
end
|
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
|
178
139
|
end
|