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
@@ -1,67 +1,83 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'active_fedora'
|
4
|
-
|
5
3
|
describe ActiveFedora::SolrInstanceLoader do
|
6
|
-
before
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
let(:context) { ActiveFedora::Base }
|
12
|
-
let(:pid) { nil }
|
13
|
-
let(:solr_doc) { nil }
|
14
|
-
let(:active_fedora_object) { ActiveFedora::Base.find(pid) }
|
15
|
-
subject { ActiveFedora::SolrInstanceLoader.new(context, pid, solr_doc) }
|
16
|
-
|
17
|
-
describe 'existing pid' do
|
18
|
-
let(:pid) { @test_object.pid }
|
19
|
-
describe 'without a solr document' do
|
20
|
-
it 'it finds the SOLR document and casts into an AF::Base object' do
|
21
|
-
expect(subject.object).to eq(active_fedora_object)
|
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
|
22
9
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
let(:mismatching_pid) { @test_object2.pid }
|
32
|
-
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>mismatching_pid).first }
|
33
|
-
it 'it raise ObjectNotFoundError' do
|
34
|
-
expect {
|
35
|
-
subject
|
36
|
-
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
10
|
+
has_attributes :foo, datastream: 'descMetadata', multiple: true
|
11
|
+
has_attributes :bar, datastream: 'descMetadata', multiple: false
|
12
|
+
property :title, predicate: ::RDF::DC.title
|
13
|
+
property :description, predicate: ::RDF::DC.description
|
14
|
+
belongs_to :another, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'Foo'
|
15
|
+
|
16
|
+
def title
|
17
|
+
super.first
|
37
18
|
end
|
38
19
|
end
|
39
20
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
21
|
+
|
22
|
+
let(:another) { Foo.create }
|
23
|
+
|
24
|
+
let!(:obj) { Foo.create!(id: 'test-123', foo: ["baz"], bar: 'quix', title: 'My Title',
|
25
|
+
description: ['first desc', 'second desc'], another_id: another.id) }
|
26
|
+
|
27
|
+
after do
|
28
|
+
Object.send(:remove_const, :Foo)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
context "without a solr doc" do
|
33
|
+
subject { loader.object }
|
34
|
+
|
35
|
+
context "with context" do
|
36
|
+
let(:loader) { ActiveFedora::SolrInstanceLoader.new(Foo, obj.id) }
|
37
|
+
|
38
|
+
it "should find the document in solr" do
|
39
|
+
expect(subject).to be_instance_of Foo
|
40
|
+
expect(subject.title).to eq 'My Title'
|
41
|
+
expect(subject.description).to match_array ['first desc', 'second desc']
|
42
|
+
expect(subject.another_id).to eq another.id
|
47
43
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
it 'it raise ObjectNotFoundError' do
|
52
|
-
expect {
|
53
|
-
subject.object
|
54
|
-
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
44
|
+
|
45
|
+
it "should not be mutable" do
|
46
|
+
expect { subject.title = 'Foo' }.to raise_error ActiveFedora::ReadOnlyRecord
|
55
47
|
end
|
56
48
|
end
|
57
|
-
|
58
|
-
|
59
|
-
let(:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
49
|
+
|
50
|
+
context "without context" do
|
51
|
+
let(:loader) { ActiveFedora::SolrInstanceLoader.new(ActiveFedora::Base, obj.id) }
|
52
|
+
|
53
|
+
it "should find the document in solr" do
|
54
|
+
expect_any_instance_of(ActiveFedora::Datastream).to_not receive(:retrieve_content)
|
55
|
+
expect_any_instance_of(Ldp::Client).to_not receive(:get)
|
56
|
+
object = loader.object
|
57
|
+
expect(object).to be_instance_of Foo
|
58
|
+
expect(object.title).to eq 'My Title' # object assertion
|
59
|
+
expect(object.foo).to eq ['baz'] # datastream assertion
|
60
|
+
|
61
|
+
# and it's frozen
|
62
|
+
expect { object.title = ['changed'] }.to raise_error ActiveFedora::ReadOnlyRecord
|
63
|
+
expect(object.title).to eq 'My Title'
|
64
|
+
|
65
|
+
expect { object.foo = ['changed'] }.to raise_error ActiveFedora::ReadOnlyRecord
|
66
|
+
expect(object.foo).to eq ['baz']
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
70
|
+
|
71
|
+
context "with a solr doc" do
|
72
|
+
let(:profile) { { "foo"=>["baz"], "bar"=>"quix", "title"=>["My Title"]}.to_json }
|
73
|
+
let(:doc) { { 'id' => 'test-123', 'has_model_ssim'=>['Foo'], 'object_profile_ssm' => profile } }
|
74
|
+
let(:loader) { ActiveFedora::SolrInstanceLoader.new(Foo, obj.id, doc) }
|
75
|
+
|
76
|
+
subject { loader.object }
|
77
|
+
|
78
|
+
it "should find the document in solr" do
|
79
|
+
expect(subject).to be_instance_of Foo
|
80
|
+
expect(subject.title).to eq 'My Title'
|
81
|
+
end
|
82
|
+
end
|
67
83
|
end
|
@@ -1,21 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'active_fedora'
|
4
|
-
|
5
3
|
describe ActiveFedora::SolrService do
|
6
4
|
describe "#reify_solr_results" do
|
7
|
-
before(:
|
5
|
+
before(:each) do
|
8
6
|
class FooObject < ActiveFedora::Base
|
9
|
-
def self.
|
7
|
+
def self.id_namespace
|
10
8
|
"foo"
|
11
9
|
end
|
12
10
|
|
13
11
|
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream
|
14
12
|
end
|
15
13
|
@test_object = ActiveFedora::Base.new
|
16
|
-
@test_object.label = 'test_object'
|
17
14
|
@foo_object = FooObject.new
|
18
|
-
@foo_object.label = 'foo_object'
|
19
15
|
attributes = {"language"=>{0=>"Italian"},
|
20
16
|
"creator"=>{0=>"Linguist, A."},
|
21
17
|
"geography"=>{0=>"Italy"},
|
@@ -24,89 +20,32 @@ describe ActiveFedora::SolrService do
|
|
24
20
|
@test_object.save
|
25
21
|
@foo_object.save
|
26
22
|
@profiles = {
|
27
|
-
'test' => @test_object.
|
28
|
-
'foo' => @foo_object.
|
29
|
-
'foo_descMetadata' => @foo_object.datastreams['descMetadata'].profile
|
23
|
+
# 'test' => @test_object.profile,
|
24
|
+
# 'foo' => @foo_object.profile,
|
25
|
+
# 'foo_descMetadata' => @foo_object.datastreams['descMetadata'].profile
|
30
26
|
}
|
31
|
-
@foo_content = @foo_object.
|
27
|
+
@foo_content = @foo_object.attached_files['descMetadata'].content
|
32
28
|
end
|
33
|
-
after(:
|
29
|
+
after(:each) do
|
34
30
|
@test_object.delete
|
35
31
|
@foo_object.delete
|
36
32
|
Object.send(:remove_const, :FooObject)
|
37
33
|
end
|
38
34
|
it "should return an array of objects that are of the class stored in active_fedora_model_s" do
|
39
|
-
query = "id\:#{RSolr.
|
35
|
+
query = "id\:#{RSolr.escape(@test_object.id)} OR id\:#{RSolr.escape(@foo_object.id)}"
|
40
36
|
solr_result = ActiveFedora::SolrService.query(query)
|
41
37
|
result = ActiveFedora::SolrService.reify_solr_results(solr_result)
|
42
|
-
expect(result.length).to eq
|
38
|
+
expect(result.length).to eq 2
|
43
39
|
result.each do |r|
|
44
|
-
expect(r.class == ActiveFedora::Base || r.class == FooObject).to
|
40
|
+
expect((r.class == ActiveFedora::Base || r.class == FooObject)).to be true
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
|
-
it 'should load objects from solr data if a :load_from_solr option is passed in' do
|
49
|
-
query = "id\:#{RSolr.solr_escape(@test_object.pid)} OR id\:#{RSolr.solr_escape(@foo_object.pid)}"
|
50
|
-
solr_result = ActiveFedora::SolrService.query(query)
|
51
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
52
|
-
expect(result.length).to eq(2)
|
53
|
-
result.each do |r|
|
54
|
-
expect(r.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
55
|
-
expect([ActiveFedora::Base, FooObject]).to include(r.class)
|
56
|
-
expect(['test_object','foo_object']).to include(r.label)
|
57
|
-
expect(@test_object.inner_object.profile).to eq(@profiles['test'])
|
58
|
-
expect(@foo_object.inner_object.profile).to eq(@profiles['foo'])
|
59
|
-
expect(@foo_object.datastreams['descMetadata'].profile).to eq(@profiles['foo_descMetadata'])
|
60
|
-
expect(@foo_object.datastreams['descMetadata'].content).to be_equivalent_to(@foo_content)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should instantiate all datastreams in the solr doc, even ones undeclared by the class' do
|
65
|
-
obj = ActiveFedora::Base.load_instance_from_solr @foo_object.pid
|
66
|
-
expect(obj.datastreams.keys).to include('descMetadata')
|
67
|
-
end
|
68
|
-
|
69
44
|
it 'should #reify a lightweight object as a new instance' do
|
70
|
-
query = "id\:#{RSolr.
|
71
|
-
solr_result = ActiveFedora::SolrService.query(query)
|
72
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
73
|
-
solr_foo = result.first
|
74
|
-
real_foo = solr_foo.reify
|
75
|
-
expect(solr_foo.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
76
|
-
expect(real_foo.inner_object).to be_a(ActiveFedora::DigitalObject)
|
77
|
-
expect(solr_foo.label).to eq('foo_object')
|
78
|
-
expect(real_foo.label).to eq('foo_object')
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should #reify! a lightweight object within the same instance' do
|
82
|
-
query = "id\:#{RSolr.solr_escape(@foo_object.pid)}"
|
83
|
-
solr_result = ActiveFedora::SolrService.query(query)
|
84
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
85
|
-
solr_foo = result.first
|
86
|
-
expect(solr_foo.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
87
|
-
solr_foo.reify!
|
88
|
-
expect(solr_foo.inner_object).to be_a(ActiveFedora::DigitalObject)
|
89
|
-
expect(solr_foo.label).to eq('foo_object')
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should raise an exception when attempting to reify a first-class object' do
|
93
|
-
query = "id\:#{RSolr.solr_escape(@foo_object.pid)}"
|
45
|
+
query = "id\:#{RSolr.escape(@foo_object.id)}"
|
94
46
|
solr_result = ActiveFedora::SolrService.query(query)
|
95
47
|
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
96
|
-
|
97
|
-
expect {solr_foo.reify}.not_to raise_exception
|
98
|
-
expect {solr_foo.reify!}.not_to raise_exception
|
99
|
-
expect {solr_foo.reify!}.to raise_exception(/already a full/)
|
100
|
-
expect {solr_foo.reify}.to raise_exception(/already a full/)
|
48
|
+
expect(result.first).to be_instance_of FooObject
|
101
49
|
end
|
102
|
-
|
103
|
-
it 'should call load_instance_from_solr if :load_from_solr option passed in' do
|
104
|
-
query = "id\:#{RSolr.solr_escape(@test_object.pid)} OR id\:#{RSolr.solr_escape(@foo_object.pid)}"
|
105
|
-
solr_result = ActiveFedora::SolrService.query(query)
|
106
|
-
expect(ActiveFedora::Base).to receive(:load_instance_from_solr).once
|
107
|
-
expect(FooObject).to receive(:load_instance_from_solr).once
|
108
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
109
|
-
end
|
110
|
-
|
111
50
|
end
|
112
51
|
end
|
@@ -0,0 +1,477 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "a versionable class" do
|
4
|
+
before do
|
5
|
+
class WithVersions < ActiveFedora::Base
|
6
|
+
has_many_versions
|
7
|
+
property :title, predicate: ::RDF::DC.title
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Object.send(:remove_const, :WithVersions)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { WithVersions.new }
|
16
|
+
|
17
|
+
it { is_expected.to be_versionable }
|
18
|
+
|
19
|
+
context "after saving" do
|
20
|
+
before do
|
21
|
+
subject.title = "Greetings Earthlings"
|
22
|
+
subject.save
|
23
|
+
subject.create_version
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set model_type to versionable" do
|
27
|
+
expect(subject.reload.model_type).to include ::RDF::URI.new('http://www.jcp.org/jcr/mix/1.0versionable')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have one version" do
|
31
|
+
expect(subject.versions.size).to eq 1
|
32
|
+
expect(subject.versions.first).to be_kind_of ::RDF::Literal
|
33
|
+
end
|
34
|
+
|
35
|
+
context "two times" do
|
36
|
+
before do
|
37
|
+
subject.title = "Surrender and prepare to be boarded"
|
38
|
+
subject.save
|
39
|
+
subject.create_version
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have two versions" do
|
43
|
+
expect(subject.versions.size).to eq 2
|
44
|
+
subject.versions.each do |version|
|
45
|
+
expect(version).to be_kind_of ::RDF::Literal
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "then restoring" do
|
50
|
+
let(:first_version) { "version1" }
|
51
|
+
before do
|
52
|
+
subject.restore_version(first_version)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "will return to the first version's values" do
|
56
|
+
expect(subject.title).to eql(["Greetings Earthlings"])
|
57
|
+
end
|
58
|
+
|
59
|
+
context "and creating additional versions" do
|
60
|
+
before do
|
61
|
+
subject.title = "Now, surrender and prepare to be boarded"
|
62
|
+
subject.save!
|
63
|
+
subject.create_version
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have three versions" do
|
67
|
+
expect(subject.versions.size).to eq 3
|
68
|
+
expect(subject.title).to eql(["Now, surrender and prepare to be boarded"])
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "a versionable rdf datastream" do
|
78
|
+
before(:all) do
|
79
|
+
class VersionableDatastream < ActiveFedora::NtriplesRDFDatastream
|
80
|
+
has_many_versions
|
81
|
+
property :title, predicate: ::RDF::DC.title
|
82
|
+
end
|
83
|
+
|
84
|
+
class MockAFBase < ActiveFedora::Base
|
85
|
+
has_metadata "descMetadata", type: VersionableDatastream, autocreate: true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
after(:all) do
|
90
|
+
Object.send(:remove_const, :MockAFBase)
|
91
|
+
Object.send(:remove_const, :VersionableDatastream)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should create the object" do
|
95
|
+
MockAFBase.create
|
96
|
+
end
|
97
|
+
|
98
|
+
subject { test_object.descMetadata }
|
99
|
+
|
100
|
+
context "that exists in the repository" do
|
101
|
+
let(:test_object) { MockAFBase.create }
|
102
|
+
|
103
|
+
it "should be versionable" do
|
104
|
+
expect(subject).to be_versionable
|
105
|
+
end
|
106
|
+
|
107
|
+
context "before creating the datastream" do
|
108
|
+
it "should not have versions" do
|
109
|
+
expect(subject.versions).to be_empty
|
110
|
+
end
|
111
|
+
it "should not have a title" do
|
112
|
+
expect(subject.title).to be_empty
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "after creating the datastream" do
|
117
|
+
before do
|
118
|
+
subject.title = "Greetings Earthlings"
|
119
|
+
subject.save
|
120
|
+
subject.create_version
|
121
|
+
@original_size = subject.size
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should set model_type to versionable" do
|
125
|
+
expect(subject.model_type).to include RDF::URI.new('http://www.jcp.org/jcr/mix/1.0versionable')
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should have one version" do
|
129
|
+
expect(subject.versions.first).to be_kind_of ::RDF::Literal
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should have a title" do
|
133
|
+
expect(subject.title).to eql(["Greetings Earthlings"])
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should have a size" do
|
137
|
+
expect(subject.size).to_not be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
context "two times" do
|
141
|
+
before do
|
142
|
+
subject.title = "Surrender and prepare to be boarded"
|
143
|
+
subject.save
|
144
|
+
subject.create_version
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should have two versions" do
|
148
|
+
expect(subject.versions.size).to eq 2
|
149
|
+
subject.versions.each do |version|
|
150
|
+
expect(version).to be_kind_of ::RDF::Literal
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should have the new title" do
|
155
|
+
expect(subject.title).to eql(["Surrender and prepare to be boarded"])
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should have a new size" do
|
159
|
+
expect(subject.size).to_not be_nil
|
160
|
+
expect(subject.size).to_not eq(@original_size)
|
161
|
+
end
|
162
|
+
|
163
|
+
context "then restoring" do
|
164
|
+
let(:first_version) { "version1" }
|
165
|
+
before do
|
166
|
+
subject.restore_version(first_version)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should have two unique versions" do
|
170
|
+
expect(subject.versions.size).to eq 2
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should load the restored datastream's content" do
|
174
|
+
expect(subject.title).to eql(["Greetings Earthlings"])
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should be the same size as the original datastream" do
|
178
|
+
expect(subject.size).to eq @original_size
|
179
|
+
end
|
180
|
+
|
181
|
+
context "and creating additional versions" do
|
182
|
+
before do
|
183
|
+
subject.title = "Now, surrender and prepare to be boarded"
|
184
|
+
subject.save
|
185
|
+
subject.create_version
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should have three unique versions" do
|
189
|
+
expect(subject.versions.size).to eq 3
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should have a new title" do
|
193
|
+
expect(subject.title).to eql(["Now, surrender and prepare to be boarded"])
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should have a new size" do
|
197
|
+
expect(subject.size).to_not eq @original_size
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "a versionable OM datastream" do
|
208
|
+
before(:all) do
|
209
|
+
class VersionableDatastream < ActiveFedora::OmDatastream
|
210
|
+
has_many_versions
|
211
|
+
set_terminology do |t|
|
212
|
+
t.root(path: "foo")
|
213
|
+
t.title
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
class MockAFBase < ActiveFedora::Base
|
218
|
+
has_metadata "descMetadata", type: VersionableDatastream, autocreate: true
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
after(:all) do
|
223
|
+
Object.send(:remove_const, :MockAFBase)
|
224
|
+
Object.send(:remove_const, :VersionableDatastream)
|
225
|
+
end
|
226
|
+
|
227
|
+
subject { test_object.descMetadata }
|
228
|
+
|
229
|
+
context "that exists in the repository" do
|
230
|
+
let(:test_object) { MockAFBase.create }
|
231
|
+
|
232
|
+
it "should be versionable" do
|
233
|
+
expect(subject).to be_versionable
|
234
|
+
end
|
235
|
+
|
236
|
+
context "before creating the datastream" do
|
237
|
+
it "should not have versions" do
|
238
|
+
expect(subject.versions).to be_empty
|
239
|
+
end
|
240
|
+
it "should not have a title" do
|
241
|
+
expect(subject.title).to be_empty
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context "after creating the datastream" do
|
246
|
+
before do
|
247
|
+
subject.title = "Greetings Earthlings"
|
248
|
+
subject.save
|
249
|
+
subject.create_version
|
250
|
+
@original_size = subject.size
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should set model_type to versionable" do
|
254
|
+
expect(subject.model_type).to include RDF::URI.new('http://www.jcp.org/jcr/mix/1.0versionable')
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should have one version" do
|
258
|
+
expect(subject.versions.size).to eq 1
|
259
|
+
expect(subject.versions.first).to be_kind_of ::RDF::Literal
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should have a title" do
|
263
|
+
expect(subject.title).to eql(["Greetings Earthlings"])
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should have a size" do
|
267
|
+
expect(subject.size).to_not be_nil
|
268
|
+
end
|
269
|
+
|
270
|
+
context "two times" do
|
271
|
+
|
272
|
+
before do
|
273
|
+
subject.title = "Surrender and prepare to be boarded"
|
274
|
+
subject.save
|
275
|
+
subject.create_version
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should have two unique versions" do
|
279
|
+
expect(subject.versions.size).to eq 2
|
280
|
+
subject.versions.each do |version|
|
281
|
+
expect(version).to be_kind_of ::RDF::Literal
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should have the new title" do
|
286
|
+
expect(subject.title).to eql(["Surrender and prepare to be boarded"])
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should have a new size" do
|
290
|
+
expect(subject.size).to_not be_nil
|
291
|
+
expect(subject.size).to_not eq(@original_size)
|
292
|
+
end
|
293
|
+
|
294
|
+
context "then restoring" do
|
295
|
+
let(:first_version) { "version1" }
|
296
|
+
before do
|
297
|
+
subject.restore_version(first_version)
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should still have two unique versions" do
|
301
|
+
expect(subject.versions.size).to eq 2
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should load the restored datastream's content" do
|
305
|
+
expect(subject.title).to eql(["Greetings Earthlings"])
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should be the same size as the original datastream" do
|
309
|
+
expect(subject.size).to eq @original_size
|
310
|
+
end
|
311
|
+
|
312
|
+
context "and creating additional versions" do
|
313
|
+
before do
|
314
|
+
subject.title = "Now, surrender and prepare to be boarded"
|
315
|
+
subject.save
|
316
|
+
subject.create_version
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should have three unique versions" do
|
320
|
+
expect(subject.versions.size).to eq 3
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should have a new title" do
|
324
|
+
expect(subject.title).to eql(["Now, surrender and prepare to be boarded"])
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should have a new size" do
|
328
|
+
expect(subject.size).to_not eq @original_size
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
describe "a versionable binary datastream" do
|
339
|
+
before(:all) do
|
340
|
+
class BinaryDatastream < ActiveFedora::File
|
341
|
+
has_many_versions
|
342
|
+
end
|
343
|
+
|
344
|
+
class MockAFBase < ActiveFedora::Base
|
345
|
+
has_file_datastream "content", type: BinaryDatastream, autocreate: true
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
after(:all) do
|
350
|
+
Object.send(:remove_const, :MockAFBase)
|
351
|
+
Object.send(:remove_const, :BinaryDatastream)
|
352
|
+
end
|
353
|
+
|
354
|
+
subject { test_object.content }
|
355
|
+
|
356
|
+
context "that exists in the repository" do
|
357
|
+
let(:test_object) { MockAFBase.create }
|
358
|
+
|
359
|
+
it "should be versionable" do
|
360
|
+
expect(subject).to be_versionable
|
361
|
+
end
|
362
|
+
|
363
|
+
context "before creating the datastream" do
|
364
|
+
it "should not have versions" do
|
365
|
+
expect(subject.versions).to be_empty
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
context "after creating the datastream" do
|
370
|
+
let(:first_file) { File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" )) }
|
371
|
+
let(:first_name) { "dino.jpg" }
|
372
|
+
before do
|
373
|
+
subject.content = first_file
|
374
|
+
subject.original_name = first_name
|
375
|
+
subject.save
|
376
|
+
subject.create_version
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should set model_type to versionable" do
|
380
|
+
expect(subject.model_type).to include RDF::URI.new('http://www.jcp.org/jcr/mix/1.0versionable')
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should have one version" do
|
384
|
+
expect(subject.versions.size).to eq 1
|
385
|
+
expect(subject.original_name).to eql(first_name)
|
386
|
+
expect(subject.content.size).to eq first_file.size
|
387
|
+
expect(subject.versions.first).to be_kind_of ::RDF::Literal
|
388
|
+
end
|
389
|
+
|
390
|
+
context "two times" do
|
391
|
+
let(:second_file) { File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" )) }
|
392
|
+
let(:second_name) { "minivan.jpg" }
|
393
|
+
before do
|
394
|
+
subject.content = second_file
|
395
|
+
subject.original_name = second_name
|
396
|
+
subject.save
|
397
|
+
subject.create_version
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should have two unique versions" do
|
401
|
+
expect(subject.versions.size).to eq 2
|
402
|
+
expect(subject.original_name).to eql(second_name)
|
403
|
+
expect(subject.content.size).to eq second_file.size
|
404
|
+
subject.versions.each do |version|
|
405
|
+
expect(version).to be_kind_of ::RDF::Literal
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
context "then restoring" do
|
410
|
+
let(:first_version) { "version1" }
|
411
|
+
before do
|
412
|
+
subject.restore_version(first_version)
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should still have two unique versions" do
|
416
|
+
expect(subject.versions.size).to eq 2
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should load the restored datastream's content" do
|
420
|
+
expect(subject.content.size).to eq first_file.size
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should load the restored datastream's original name" do
|
424
|
+
expect(subject.original_name).to eql(first_name)
|
425
|
+
end
|
426
|
+
|
427
|
+
context "and creating additional versions" do
|
428
|
+
before do
|
429
|
+
subject.content = first_file
|
430
|
+
subject.original_name = first_name
|
431
|
+
subject.save
|
432
|
+
subject.create_version
|
433
|
+
end
|
434
|
+
|
435
|
+
it "should have three unique versions" do
|
436
|
+
expect(subject.versions.size).to eq 3
|
437
|
+
expect(subject.original_name).to eql(first_name)
|
438
|
+
expect(subject.content.size).to eq first_file.size
|
439
|
+
expect(subject.versions.first).to be_kind_of ::RDF::Literal
|
440
|
+
end
|
441
|
+
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
describe "a non-versionable resource" do
|
450
|
+
before(:all) do
|
451
|
+
class NotVersionableWithVersions < ActiveFedora::Base
|
452
|
+
# explicitly don't call has_many_versions
|
453
|
+
property :title, predicate: ::RDF::DC.title
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
after(:all) do
|
458
|
+
Object.send(:remove_const, :NotVersionableWithVersions)
|
459
|
+
end
|
460
|
+
|
461
|
+
subject { NotVersionableWithVersions.new }
|
462
|
+
|
463
|
+
context "saved with no versions" do
|
464
|
+
it "should not have versions" do
|
465
|
+
subject.update(title: "Greetings Earthlings")
|
466
|
+
expect(subject).not_to have_versions
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
context "saved with versions" do
|
471
|
+
it "should have versions" do
|
472
|
+
subject.update(title: "Greetings Earthlings")
|
473
|
+
subject.create_version
|
474
|
+
expect(subject).to have_versions
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|