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
@@ -23,7 +23,7 @@ describe ActiveFedora::Base do
|
|
23
23
|
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
|
24
24
|
m.field "fubar", :text
|
25
25
|
end
|
26
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2"
|
26
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2" do |m|
|
27
27
|
m.field "fubar", :text
|
28
28
|
end
|
29
29
|
|
@@ -37,18 +37,18 @@ describe ActiveFedora::Base do
|
|
37
37
|
describe "attributes=" do
|
38
38
|
it "should set attributes" do
|
39
39
|
@n.attributes = {:fubar=>"baz", :duck=>"Quack"}
|
40
|
-
expect(@n.fubar).to eq
|
41
|
-
expect(@n.withText.get_values(:fubar).first).to eq
|
42
|
-
expect(@n.duck).to eq
|
43
|
-
expect(@n.xmlish.term_values(:duck).first).to eq
|
40
|
+
expect(@n.fubar).to eq "baz"
|
41
|
+
expect(@n.withText.get_values(:fubar).first).to eq 'baz'
|
42
|
+
expect(@n.duck).to eq "Quack"
|
43
|
+
expect(@n.xmlish.term_values(:duck).first).to eq 'Quack'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
describe "update_attributes" do
|
47
47
|
it "should set attributes and save " do
|
48
48
|
@n.update_attributes(:fubar=>"baz", :duck=>"Quack")
|
49
|
-
@q = BarHistory.find(@n.
|
50
|
-
expect(@q.fubar).to eq
|
51
|
-
expect(@q.duck).to eq
|
49
|
+
@q = BarHistory.find(@n.id)
|
50
|
+
expect(@q.fubar).to eq "baz"
|
51
|
+
expect(@q.duck).to eq "Quack"
|
52
52
|
end
|
53
53
|
after do
|
54
54
|
@n.delete
|
@@ -1,33 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
it "should not call Datastream.save" do
|
11
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
4
|
+
|
5
|
+
describe '.attach_file' do
|
6
|
+
let(:test_object) { ActiveFedora::Base.new }
|
7
|
+
let(:ds) { ActiveFedora::File.new(@test_object, 'ds_to_add') }
|
8
|
+
|
9
|
+
it "should not call File.save" do
|
12
10
|
expect(ds).to receive(:save).never
|
13
|
-
|
11
|
+
test_object.attach_file(ds, 'ds1')
|
14
12
|
end
|
13
|
+
|
15
14
|
it "should add the datastream to the datastreams_in_memory array" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
expect(@test_object.datastreams).to have_key(ds.dsid)
|
20
|
-
end
|
21
|
-
it "should auto-assign dsids using auto-incremented integers if dsid is nil or an empty string" do
|
22
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil)
|
23
|
-
expect(ds.dsid).to eq('DS1')
|
24
|
-
expect(@test_object.add_datastream(ds)).to eq('DS1')
|
25
|
-
ds_emptystringid = ActiveFedora::Datastream.new(@test_object.inner_object, '')
|
26
|
-
expect(@test_object.add_datastream(ds_emptystringid)).to eq('DS2')
|
27
|
-
end
|
28
|
-
it "should accept a prefix option and apply it to automatically assigned dsids" do
|
29
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil, :prefix=> "FOO")
|
30
|
-
expect(ds.dsid).to eq('FOO1')
|
15
|
+
expect(test_object.attached_files).to_not have_key(:ds_to_add)
|
16
|
+
test_object.attach_file(ds, 'ds_to_add')
|
17
|
+
expect(test_object.attached_files).to have_key(:ds_to_add)
|
31
18
|
end
|
32
19
|
end
|
33
20
|
end
|
@@ -1,75 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@test_object = ActiveFedora::Base.new
|
7
|
-
end
|
8
4
|
|
9
5
|
describe ".update_index" do
|
10
6
|
before do
|
11
7
|
mock_conn = double("SolrConnection")
|
12
8
|
expect(mock_conn).to receive(:add) do |_, opts|
|
13
|
-
expect(opts).to eq(
|
9
|
+
expect(opts).to eq(:params=>{:softCommit=>true})
|
14
10
|
end
|
15
11
|
mock_ss = double("SolrService")
|
16
12
|
allow(mock_ss).to receive(:conn).and_return(mock_conn)
|
17
13
|
allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
|
18
14
|
end
|
19
|
-
|
20
|
-
it "should call .to_solr on all SimpleDatastreams AND RelsExtDatastreams and pass the resulting document to solr" do
|
21
|
-
# Actually uses self.to_solr internally to gather solr info from all metadata datastreams
|
22
|
-
mock1 = double("ds1", :to_solr => {})
|
23
|
-
mock2 = double("ds2", :to_solr => {})
|
24
|
-
mock3 = double("RELS-EXT", :to_solr => {})
|
25
|
-
|
26
|
-
mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
|
27
|
-
expect(mock1).to receive(:solrize_profile).and_return({})
|
28
|
-
expect(mock2).to receive(:solrize_profile).and_return({})
|
29
|
-
expect(mock3).to receive(:solrize_profile).and_return({})
|
30
|
-
expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
|
31
|
-
expect(@test_object).to receive(:solrize_relationships)
|
32
|
-
@test_object.update_index
|
33
|
-
end
|
34
15
|
|
35
|
-
it "should
|
36
|
-
|
37
|
-
|
38
|
-
mock2 = double("ds2", :to_solr => {})
|
39
|
-
mock3 = double("RELS-EXT", :to_solr => {})
|
40
|
-
|
41
|
-
mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
|
42
|
-
expect(mock1).to receive(:solrize_profile).and_return({})
|
43
|
-
expect(mock2).to receive(:solrize_profile).and_return({})
|
44
|
-
expect(mock3).to receive(:solrize_profile).and_return({})
|
45
|
-
expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
|
46
|
-
expect(@test_object).to receive(:solrize_relationships)
|
47
|
-
@test_object.update_index
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should retrieve a solr Connection and call Connection.add" do
|
51
|
-
@test_object.update_index
|
16
|
+
it "should make the solr_document with to_solr and add it" do
|
17
|
+
expect(subject).to receive(:to_solr)
|
18
|
+
subject.update_index
|
52
19
|
end
|
53
20
|
|
54
21
|
end
|
55
|
-
|
22
|
+
|
56
23
|
describe ".delete" do
|
57
|
-
|
58
|
-
before
|
24
|
+
|
25
|
+
before do
|
26
|
+
allow(subject).to receive(:new_record?).and_return(false)
|
27
|
+
allow(ActiveFedora.fedora.connection).to receive(:delete)
|
59
28
|
end
|
60
|
-
|
29
|
+
|
61
30
|
it "should delete object from repository and index" do
|
62
|
-
|
63
|
-
|
64
|
-
expect(mock_conn).to receive(:delete_by_id).with(nil, {:params=>{"softCommit"=>true}})
|
65
|
-
mock_ss = double("SolrService")
|
66
|
-
allow(mock_ss).to receive(:conn).and_return(mock_conn)
|
67
|
-
allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
|
68
|
-
@test_object.delete
|
31
|
+
expect(ActiveFedora::SolrService).to receive(:delete).with(nil)
|
32
|
+
subject.delete
|
69
33
|
end
|
70
|
-
|
71
34
|
end
|
72
|
-
|
35
|
+
|
73
36
|
describe "to_class_uri" do
|
74
37
|
before :all do
|
75
38
|
module SpecModel
|
@@ -77,25 +40,12 @@ describe ActiveFedora::Base do
|
|
77
40
|
end
|
78
41
|
end
|
79
42
|
end
|
80
|
-
|
43
|
+
|
81
44
|
after :all do
|
82
45
|
SpecModel.send(:remove_const, :CamelCased)
|
83
46
|
end
|
84
|
-
subject {SpecModel::CamelCased}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
context "with the namespace declared in the model" do
|
89
|
-
before do
|
90
|
-
allow(subject).to receive(:pid_namespace).and_return("test-cModel")
|
91
|
-
end
|
92
|
-
its(:to_class_uri) {should == 'info:fedora/test-cModel:SpecModel_CamelCased' }
|
93
|
-
end
|
94
|
-
context "with the suffix declared in the model" do
|
95
|
-
before do
|
96
|
-
allow(subject).to receive(:pid_suffix).and_return("-TEST-SUFFIX")
|
97
|
-
end
|
98
|
-
its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
|
99
|
-
end
|
47
|
+
subject {SpecModel::CamelCased.to_class_uri}
|
48
|
+
|
49
|
+
it { should == 'SpecModel::CamelCased' }
|
100
50
|
end
|
101
51
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
@@
|
2
|
+
@@last_id = 0
|
3
3
|
|
4
4
|
describe ActiveFedora::Base do
|
5
5
|
it_behaves_like "An ActiveModel"
|
@@ -10,130 +10,66 @@ describe ActiveFedora::Base do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
14
|
-
it "should
|
15
|
-
|
13
|
+
describe "reindex_everything" do
|
14
|
+
it "should call update_index on every object represented in the sitemap" do
|
15
|
+
allow(ActiveFedora::Base).to receive(:get_descendent_uris) { ['http://localhost/test/XXX', 'http://localhost/test/YYY', 'http://localhost/test/ZZZ'] }
|
16
|
+
mock_update = double(:mock_obj)
|
17
|
+
expect(mock_update).to receive(:update_index).exactly(3).times
|
18
|
+
expect(ActiveFedora::Base).to receive(:find).with(instance_of ActiveFedora::LdpResource ).and_return(mock_update).exactly(3).times
|
19
|
+
ActiveFedora::Base.reindex_everything
|
16
20
|
end
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ActiveFedora::Base.
|
23
|
-
allow(ActiveFedora.config).to receive(:credentials).and_return(:url=>'myfedora')
|
24
|
-
allow_any_instance_of(Rubydora::Fc3Service).to receive(:repository_profile)
|
25
|
-
end
|
26
|
-
it { is_expected.to be_kind_of Rubydora::Repository}
|
27
|
-
it "should be the standard connection" do
|
28
|
-
expect(subject.client.url).to eq('myfedora')
|
29
|
-
end
|
30
|
-
describe "assign_pid" do
|
31
|
-
it "should use fedora to generate pids" do
|
32
|
-
# TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
|
33
|
-
# possibly wrap it all into a fedora_connection method - MZ 06-05-2012
|
34
|
-
stubfedora = double("Fedora")
|
35
|
-
expect(stubfedora).to receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
|
36
|
-
# Should use ActiveFedora.config.credentials as a single hash rather than an array of shards
|
37
|
-
expect(ActiveFedora::RubydoraConnection).to receive(:new).with(ActiveFedora.config.credentials).and_return(stubfedora)
|
38
|
-
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
describe "shard_index" do
|
42
|
-
it "should always return zero (the first and only connection)" do
|
43
|
-
expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
|
44
|
-
end
|
23
|
+
describe "get_descendent_uris" do
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
ids.each do |id|
|
27
|
+
ActiveFedora::Base.create id: id
|
45
28
|
end
|
46
29
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
ActiveFedora::Base.fedora_connection = {}
|
51
|
-
allow(ActiveFedora.config).to receive(:credentials).and_return([{:url=>'shard1'}, {:url=>'shard2'} ])
|
52
|
-
end
|
53
|
-
describe "assign_pid" do
|
54
|
-
it "should always use the first shard to generate pids" do
|
55
|
-
stubhard1 = double("Shard")
|
56
|
-
stubhard2 = double("Shard")
|
57
|
-
expect(stubhard1).to receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
|
58
|
-
expect(stubhard2).to receive(:connection).never
|
59
|
-
ActiveFedora::Base.fedora_connection = {0 => stubhard1, 1 => stubhard2}
|
60
|
-
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
describe "shard_index" do
|
64
|
-
it "should use modulo of md5 of the pid to distribute objects across shards" do
|
65
|
-
expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
|
66
|
-
expect(ActiveFedora::Base.shard_index('test:nanana')).to eq(1)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
describe "the repository" do
|
70
|
-
before do
|
71
|
-
allow_any_instance_of(Rubydora::Fc3Service).to receive(:repository_profile)
|
72
|
-
end
|
73
|
-
describe "for test:bar" do
|
74
|
-
subject {ActiveFedora::Base.connection_for_pid('test:bar')}
|
75
|
-
it "should be shard1" do
|
76
|
-
expect(subject.client.url).to eq('shard1')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
describe "for test:baz" do
|
80
|
-
subject {ActiveFedora::Base.connection_for_pid('test:nanana')}
|
81
|
-
it "should be shard1" do
|
82
|
-
expect(subject.client.url).to eq('shard2')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
30
|
+
|
31
|
+
def root_uri(ids=[])
|
32
|
+
ActiveFedora::Base.id_to_uri(ids.first)
|
86
33
|
end
|
87
34
|
|
88
|
-
|
35
|
+
context 'when there there are no descendents' do
|
89
36
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
and_yield(double(pid:'fedora-system:ServiceDefinition-3.0')).
|
96
|
-
and_yield(double(pid:'fedora-system:FedoraObject-3.0'))
|
97
|
-
|
98
|
-
mock_update = double(:mock_obj)
|
99
|
-
expect(mock_update).to receive(:update_index).exactly(3).times
|
100
|
-
expect(ActiveFedora::Base).to receive(:find).with('XXX').and_return(mock_update)
|
101
|
-
expect(ActiveFedora::Base).to receive(:find).with('YYY').and_return(mock_update)
|
102
|
-
expect(ActiveFedora::Base).to receive(:find).with('ZZZ').and_return(mock_update)
|
103
|
-
ActiveFedora::Base.reindex_everything
|
37
|
+
let(:ids) { ['foo'] }
|
38
|
+
|
39
|
+
it 'returns an array containing only the URI passed to it' do
|
40
|
+
expect(ActiveFedora::Base.get_descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
|
41
|
+
end
|
104
42
|
end
|
105
43
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect(ActiveFedora::Base).to receive(:find).with('YYY').and_return(mock_update)
|
114
|
-
expect(ActiveFedora::Base).to receive(:find).with('ZZZ').and_return(mock_update)
|
115
|
-
ActiveFedora::Base.reindex_everything(query_string)
|
44
|
+
context 'when there are > 1 descendents' do
|
45
|
+
|
46
|
+
let(:ids) { ['foo', 'foo/bar', 'foo/bar/chu'] }
|
47
|
+
|
48
|
+
it 'returns an array containing the URI passed to it, as well as all descendent URIs' do
|
49
|
+
expect(ActiveFedora::Base.get_descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
|
50
|
+
end
|
116
51
|
end
|
117
52
|
end
|
118
53
|
|
119
54
|
describe "With a test class" do
|
120
|
-
before :
|
55
|
+
before :each do
|
121
56
|
class FooHistory < ActiveFedora::Base
|
122
|
-
has_metadata :
|
57
|
+
has_metadata 'someData', type: ActiveFedora::SimpleDatastream, autocreate: true do |m|
|
123
58
|
m.field "fubar", :string
|
124
59
|
m.field "swank", :text
|
125
60
|
end
|
126
|
-
has_metadata :
|
61
|
+
has_metadata "withText", type: ActiveFedora::SimpleDatastream, autocreate: true do |m|
|
127
62
|
m.field "fubar", :text
|
128
63
|
end
|
129
|
-
has_metadata
|
64
|
+
has_metadata "withText2", type: ActiveFedora::SimpleDatastream, autocreate: true do |m|
|
130
65
|
m.field "fubar", :text
|
131
66
|
end
|
132
67
|
has_attributes :fubar, datastream: 'withText', multiple: true
|
133
68
|
has_attributes :swank, datastream: 'someData', multiple: true
|
134
69
|
end
|
70
|
+
|
135
71
|
class FooAdaptation < ActiveFedora::Base
|
136
|
-
has_metadata :
|
72
|
+
has_metadata 'someData', type: ActiveFedora::OmDatastream
|
137
73
|
end
|
138
74
|
|
139
75
|
class FooInherited < FooHistory
|
@@ -141,120 +77,98 @@ describe ActiveFedora::Base do
|
|
141
77
|
end
|
142
78
|
end
|
143
79
|
|
144
|
-
after :
|
80
|
+
after :each do
|
145
81
|
Object.send(:remove_const, :FooHistory)
|
146
82
|
Object.send(:remove_const, :FooAdaptation)
|
147
83
|
Object.send(:remove_const, :FooInherited)
|
148
84
|
end
|
149
85
|
|
150
|
-
def
|
151
|
-
@@
|
86
|
+
def increment_id
|
87
|
+
@@last_id += 1
|
152
88
|
end
|
153
89
|
|
154
|
-
before
|
155
|
-
@
|
156
|
-
stub_get(@this_pid)
|
157
|
-
allow_any_instance_of(Rubydora::Repository).to receive(:client).and_return(@mock_client)
|
158
|
-
allow(ActiveFedora::Base).to receive(:assign_pid).and_return(@this_pid)
|
159
|
-
|
90
|
+
before do
|
91
|
+
@this_id = increment_id.to_s
|
160
92
|
@test_object = ActiveFedora::Base.new
|
161
|
-
|
162
|
-
|
163
|
-
after(:each) do
|
164
|
-
begin
|
165
|
-
allow(ActiveFedora::SolrService).to receive(:instance)
|
166
|
-
#@test_object.delete
|
167
|
-
rescue
|
168
|
-
end
|
93
|
+
allow(@test_object).to receive(:assign_id).and_return(@this_id)
|
169
94
|
end
|
170
95
|
|
171
96
|
|
172
97
|
describe '#new' do
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
98
|
+
before do
|
99
|
+
allow_any_instance_of(FooHistory).to receive(:assign_id).and_return(@this_id)
|
100
|
+
end
|
101
|
+
context "with no arguments" do
|
102
|
+
it "should not get an id on init" do
|
103
|
+
expect(FooHistory.new.id).to be_nil
|
104
|
+
end
|
178
105
|
end
|
179
106
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
107
|
+
context "with an id argument" do
|
108
|
+
it "should be able to create with a custom id" do
|
109
|
+
expect(FooHistory).to receive(:id_to_uri).and_call_original
|
110
|
+
f = FooHistory.new('baz_1')
|
111
|
+
expect(f.id).to eq 'baz_1'
|
112
|
+
expect(f.id).to eq 'baz_1'
|
113
|
+
end
|
184
114
|
end
|
185
115
|
|
186
|
-
|
187
|
-
|
188
|
-
|
116
|
+
context "with a hash argument" do
|
117
|
+
context "that has an id" do
|
118
|
+
it "should be able to create with a custom id" do
|
119
|
+
expect(FooHistory).to receive(:id_to_uri).and_call_original
|
120
|
+
f = FooHistory.new(id: 'baz_1')
|
121
|
+
expect(f.id).to eq 'baz_1'
|
122
|
+
expect(f.id).to eq 'baz_1'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "that doesn't have an id" do
|
127
|
+
it "should be able to create with a custom id" do
|
128
|
+
f = FooHistory.new(fubar: ['baz_1'])
|
129
|
+
expect(f.id).to be_nil
|
130
|
+
end
|
131
|
+
end
|
189
132
|
end
|
190
133
|
end
|
191
134
|
|
192
|
-
|
193
|
-
|
194
|
-
|
135
|
+
### Methods for ActiveModel::Conversions
|
136
|
+
context "before saving" do
|
137
|
+
context "#to_param" do
|
138
|
+
subject { @test_object.to_param }
|
139
|
+
it { should be_nil }
|
195
140
|
end
|
196
|
-
|
197
|
-
|
141
|
+
context "#to_key" do
|
142
|
+
subject { @test_object.to_key }
|
143
|
+
it { should be_nil }
|
198
144
|
end
|
199
145
|
end
|
200
146
|
|
201
|
-
|
202
|
-
|
203
|
-
|
147
|
+
context "when its saved" do
|
148
|
+
before do
|
149
|
+
allow(@test_object).to receive(:new_record?).and_return(false)
|
150
|
+
allow(@test_object).to receive(:uri).and_return('http://localhost:8983/fedora/rest/test/one/two/three')
|
204
151
|
end
|
205
|
-
end
|
206
152
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
expect(@test_object.to_param).to eq('foo:123')
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should have to_key once it's saved" do
|
215
|
-
expect(@test_object.to_key).to be_nil
|
216
|
-
allow(@test_object.inner_object).to receive_messages(new_record?: false, pid: 'foo:123')
|
217
|
-
expect(@test_object.to_key).to eq(['foo:123'])
|
218
|
-
end
|
153
|
+
context "#to_param" do
|
154
|
+
subject { @test_object.to_param }
|
155
|
+
it { should eq 'one/two/three' }
|
156
|
+
end
|
219
157
|
|
220
|
-
|
221
|
-
|
158
|
+
context "#to_key" do
|
159
|
+
subject { @test_object.to_key }
|
160
|
+
it { should eq ['one/two/three'] }
|
161
|
+
end
|
222
162
|
end
|
223
163
|
### end ActiveModel::Conversions
|
224
164
|
|
225
165
|
### Methods for ActiveModel::Naming
|
226
166
|
it "Should know the model_name" do
|
227
|
-
expect(FooHistory.model_name).to eq
|
228
|
-
expect(FooHistory.model_name.human).to eq
|
167
|
+
expect(FooHistory.model_name).to eq 'FooHistory'
|
168
|
+
expect(FooHistory.model_name.human).to eq 'Foo history'
|
229
169
|
end
|
230
170
|
### End ActiveModel::Naming
|
231
171
|
|
232
|
-
|
233
|
-
describe ".datastreams" do
|
234
|
-
let(:test_history) { FooHistory.new }
|
235
|
-
it "should create accessors for datastreams declared with has_metadata" do
|
236
|
-
expect(test_history.withText).to eq(test_history.datastreams['withText'])
|
237
|
-
end
|
238
|
-
describe "dynamic accessors" do
|
239
|
-
before do
|
240
|
-
test_history.add_datastream(ds)
|
241
|
-
test_history.class.build_datastream_accessor(ds.dsid)
|
242
|
-
end
|
243
|
-
describe "when the datastream is named with dash" do
|
244
|
-
let(:ds) {double('datastream', :dsid=>'eac-cpf')}
|
245
|
-
it "should convert dashes to underscores" do
|
246
|
-
expect(test_history.eac_cpf).to eq(ds)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
describe "when the datastream is named with underscore" do
|
250
|
-
let (:ds) { double('datastream', :dsid=>'foo_bar') }
|
251
|
-
it "should preserve the underscore" do
|
252
|
-
expect(test_history.foo_bar).to eq(ds)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
172
|
it 'should provide #find' do
|
259
173
|
expect(ActiveFedora::Base).to respond_to(:find)
|
260
174
|
end
|
@@ -267,116 +181,67 @@ describe ActiveFedora::Base do
|
|
267
181
|
expect(@test_object).to respond_to(:modified_date)
|
268
182
|
end
|
269
183
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'should provide #add_relationship' do
|
283
|
-
expect(@test_object).to respond_to(:add_relationship)
|
284
|
-
end
|
285
|
-
|
286
|
-
describe '#add_relationship' do
|
287
|
-
it 'should call #add_relationship on the rels_ext datastream' do
|
288
|
-
@test_object.add_relationship("predicate", "info:fedora/object")
|
289
|
-
pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
|
290
|
-
expect(@test_object.relationships).to have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
|
294
|
-
mock_ds = double("Rels-Ext")
|
295
|
-
allow(mock_ds).to receive(:content_will_change!)
|
296
|
-
@test_object.datastreams["RELS-EXT"] = mock_ds
|
297
|
-
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
298
|
-
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should add a relationship to an object only if it does not exist already' do
|
302
|
-
next_pid = increment_pid.to_s
|
303
|
-
allow(ActiveFedora::Base).to receive(:assign_pid).and_return(next_pid)
|
304
|
-
stub_get(next_pid)
|
305
|
-
|
306
|
-
@test_object3 = ActiveFedora::Base.new
|
307
|
-
@test_object.add_relationship(:has_part,@test_object3)
|
308
|
-
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
|
309
|
-
#try adding again and make sure not there twice
|
310
|
-
@test_object.add_relationship(:has_part,@test_object3)
|
311
|
-
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'should add literal relationships if requested' do
|
315
|
-
@test_object.add_relationship(:conforms_to,"AnInterface",true)
|
316
|
-
expect(@test_object.ids_for_outbound(:conforms_to)).to eq(["AnInterface"])
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
it 'should provide #remove_relationship' do
|
321
|
-
expect(@test_object).to respond_to(:remove_relationship)
|
322
|
-
end
|
323
|
-
|
324
|
-
describe '#remove_relationship' do
|
325
|
-
it 'should remove a relationship from the relationships hash' do
|
326
|
-
@test_object3 = ActiveFedora::Base.new()
|
327
|
-
allow(@test_object3).to receive_messages(:pid=>'7')
|
328
|
-
@test_object4 = ActiveFedora::Base.new()
|
329
|
-
allow(@test_object4).to receive_messages(:pid=>'8')
|
330
|
-
@test_object.add_relationship(:has_part,@test_object3)
|
331
|
-
@test_object.add_relationship(:has_part,@test_object4)
|
332
|
-
#check both are there
|
333
|
-
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid,@test_object4.pid])
|
334
|
-
@test_object.remove_relationship(:has_part,@test_object3)
|
335
|
-
#check only one item removed
|
336
|
-
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object4.pid])
|
337
|
-
@test_object.remove_relationship(:has_part,@test_object4)
|
338
|
-
#check last item removed and predicate removed since now emtpy
|
339
|
-
expect(@test_object.relationships.size).to eq(0)
|
184
|
+
describe '.save' do
|
185
|
+
it "should create a new record" do
|
186
|
+
allow(@test_object).to receive(:new_record?).and_return(true)
|
187
|
+
expect(@test_object).to receive(:serialize_attached_files)
|
188
|
+
expect(@test_object).to receive(:assign_rdf_subject)
|
189
|
+
expect(@test_object.ldp_source).to receive(:create)
|
190
|
+
expect(@test_object).to receive(:refresh)
|
191
|
+
expect(@test_object).to receive(:update_index)
|
192
|
+
@test_object.save
|
340
193
|
end
|
341
|
-
end
|
342
194
|
|
343
|
-
|
344
|
-
expect(@test_object).to respond_to(:relationships)
|
345
|
-
end
|
195
|
+
context "on an existing record" do
|
346
196
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
197
|
+
it "should update" do
|
198
|
+
allow(@test_object).to receive(:new_record?).and_return(false)
|
199
|
+
expect(@test_object).to receive(:serialize_attached_files)
|
200
|
+
allow_any_instance_of(Ldp::Orm).to receive(:save) { true }
|
201
|
+
expect(@test_object).to receive(:refresh)
|
202
|
+
expect(@test_object).to receive(:update_index)
|
203
|
+
@test_object.save
|
204
|
+
end
|
351
205
|
end
|
352
|
-
end
|
353
206
|
|
354
|
-
|
355
|
-
|
356
|
-
stub_get(@this_pid)
|
357
|
-
stub_add_ds(@this_pid, ['RELS-EXT'])
|
358
|
-
@test_object.assert_content_model
|
359
|
-
expect(@test_object.relationships(:has_model)).to eq(["info:fedora/afmodel:ActiveFedora_Base"])
|
207
|
+
context "when assign id returns a value" do
|
208
|
+
context "an no id has been set" do
|
360
209
|
|
361
|
-
|
362
|
-
|
210
|
+
it "should set the id" do
|
211
|
+
@test_object.save
|
212
|
+
expect(@test_object.id).to eq @this_id
|
213
|
+
end
|
363
214
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
215
|
+
context "and the object has properties" do
|
216
|
+
let(:test_object) { WithProperty.new(title: 'foo') }
|
217
|
+
before do
|
218
|
+
class WithProperty < ActiveFedora::Base
|
219
|
+
property :title, predicate: ::RDF::DC.title
|
220
|
+
end
|
221
|
+
allow(test_object).to receive(:assign_id).and_return(@this_id)
|
222
|
+
test_object.save
|
223
|
+
end
|
224
|
+
after do
|
225
|
+
Object.send(:remove_const, :WithProperty)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should update the resource" do
|
229
|
+
expect(test_object.resource.rdf_subject).to eq ::RDF::URI.new("#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{@this_id}")
|
230
|
+
expect(test_object.title).to eq ['foo']
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
373
234
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
235
|
+
context "when an id is set" do
|
236
|
+
before do
|
237
|
+
@test_object = ActiveFedora::Base.new(id: '999')
|
238
|
+
allow(@test_object).to receive(:assign_id).and_return(@this_id)
|
239
|
+
end
|
240
|
+
it "should not set the id" do
|
241
|
+
@test_object.save
|
242
|
+
expect(@test_object.id).to eq '999'
|
243
|
+
end
|
244
|
+
end
|
380
245
|
end
|
381
246
|
end
|
382
247
|
|
@@ -385,155 +250,43 @@ describe ActiveFedora::Base do
|
|
385
250
|
obj = double()
|
386
251
|
expect(obj).to receive(:save)
|
387
252
|
expect(FooHistory).to receive(:new).and_return(obj)
|
388
|
-
@hist = FooHistory.create(:
|
389
|
-
end
|
390
|
-
|
391
|
-
end
|
392
|
-
|
393
|
-
describe ".adapt_to" do
|
394
|
-
it "should return an adapted object of the requested type" do
|
395
|
-
@test_object = FooHistory.new()
|
396
|
-
expect(@test_object.adapt_to(FooAdaptation).class).to eq(FooAdaptation)
|
397
|
-
end
|
398
|
-
it "should not make an additional call to fedora to create the adapted object" do
|
399
|
-
@test_object = FooHistory.new()
|
400
|
-
adapted = @test_object.adapt_to(FooAdaptation)
|
401
|
-
end
|
402
|
-
it "should propagate new datastreams to the adapted object" do
|
403
|
-
@test_object = FooHistory.new()
|
404
|
-
@test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
|
405
|
-
adapted = @test_object.adapt_to(FooAdaptation)
|
406
|
-
expect(adapted.datastreams.keys).to include 'MY_DSID'
|
407
|
-
expect(adapted.datastreams['MY_DSID'].content).to eq("XXX")
|
408
|
-
expect(adapted.datastreams['MY_DSID'].changed?).to be_truthy
|
409
|
-
end
|
410
|
-
it "should propagate modified datastreams to the adapted object" do
|
411
|
-
@test_object = FooHistory.new()
|
412
|
-
orig_ds = @test_object.datastreams['someData']
|
413
|
-
orig_ds.content="<YYY/>"
|
414
|
-
adapted = @test_object.adapt_to(FooAdaptation)
|
415
|
-
expect(adapted.datastreams.keys).to include 'someData'
|
416
|
-
expect(adapted.datastreams['someData']).to eq(orig_ds)
|
417
|
-
expect(adapted.datastreams['someData'].content.strip).to eq("<YYY/>")
|
418
|
-
expect(adapted.datastreams['someData'].changed?).to be_truthy
|
419
|
-
end
|
420
|
-
it "should use the datastream definitions from the adapted object" do
|
421
|
-
@test_object = FooHistory.new()
|
422
|
-
adapted = @test_object.adapt_to(FooAdaptation)
|
423
|
-
expect(adapted.datastreams.keys).to include 'someData'
|
424
|
-
expect(adapted.datastreams['someData'].class).to eq(ActiveFedora::OmDatastream)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe ".adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel" do
|
429
|
-
subject { FooHistory.new }
|
430
|
-
|
431
|
-
it "should raise an exception if the object class is not equal to or a subclass of any known model" do
|
432
|
-
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation])
|
433
|
-
expect { subject.adapt_to_cmodel }.to raise_error(ActiveFedora::ModelNotAsserted)
|
253
|
+
@hist = FooHistory.create(fubar: 'ta', swank: 'da')
|
434
254
|
end
|
435
|
-
it "should cast to an inherited model over a random one" do
|
436
|
-
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
|
437
|
-
expect(subject.adapt_to_cmodel).to be_kind_of FooInherited
|
438
|
-
end
|
439
|
-
it "should not cast when a cmodel is same as the class" do
|
440
|
-
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooHistory])
|
441
|
-
expect(subject.adapt_to_cmodel).to be === subject
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
describe ".adapt_to_cmodel with ActiveFedora::Base" do
|
446
|
-
subject { ActiveFedora::Base.new }
|
447
|
-
|
448
|
-
it "should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)" do
|
449
|
-
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
|
450
|
-
expect(subject.adapt_to_cmodel).to be_kind_of FooAdaptation
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
describe '#has_model' do
|
455
|
-
subject { FooHistory.new.has_model }
|
456
|
-
it { is_expected.to eq 'FooHistory' }
|
457
255
|
end
|
458
256
|
|
459
|
-
describe
|
257
|
+
describe ".to_solr" do
|
460
258
|
it "should provide .to_solr" do
|
461
259
|
expect(@test_object).to respond_to(:to_solr)
|
462
260
|
end
|
463
261
|
|
464
|
-
it "should add
|
465
|
-
expect(@test_object).to receive(:create_date).and_return("2012-03-04T03:12:02Z")
|
466
|
-
expect(@test_object).to receive(:modified_date).and_return("2012-03-07T03:12:02Z")
|
467
|
-
allow(@test_object).to
|
468
|
-
@test_object.state = "D"
|
262
|
+
it "should add id, system_create_date, system_modified_date from object attributes" do
|
263
|
+
expect(@test_object).to receive(:create_date).and_return(DateTime.parse("2012-03-04T03:12:02Z")).twice
|
264
|
+
expect(@test_object).to receive(:modified_date).and_return(DateTime.parse("2012-03-07T03:12:02Z")).twice
|
265
|
+
allow(@test_object).to receive(:id).and_return('changeme:123')
|
469
266
|
solr_doc = @test_object.to_solr
|
470
267
|
expect(solr_doc[ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)]).to eql("2012-03-04T03:12:02Z")
|
471
268
|
expect(solr_doc[ActiveFedora::SolrService.solr_name("system_modified", :stored_sortable, type: :date)]).to eql("2012-03-07T03:12:02Z")
|
472
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("object_state", :stored_sortable)]).to eql("D")
|
473
269
|
expect(solr_doc[:id]).to eql("changeme:123")
|
474
270
|
end
|
475
271
|
|
476
|
-
it "should
|
477
|
-
@
|
478
|
-
solr_doc = @
|
479
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("system_create", type: :date)]).to be_nil
|
480
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("system_modified", type: :date)]).to be_nil
|
481
|
-
expect(solr_doc["id"]).to be_nil
|
482
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)]).to be_nil
|
483
|
-
end
|
484
|
-
|
485
|
-
it "adds has_model as the :active_fedora_model" do
|
486
|
-
stub_get(@this_pid)
|
487
|
-
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
488
|
-
solr_doc = FooHistory.new.to_solr
|
272
|
+
it "should add self.class as the :active_fedora_model" do
|
273
|
+
@test_history = FooHistory.new()
|
274
|
+
solr_doc = @test_history.to_solr
|
489
275
|
expect(solr_doc[ActiveFedora::SolrService.solr_name("active_fedora_model", :stored_sortable)]).to eql("FooHistory")
|
490
276
|
end
|
491
277
|
|
492
|
-
it "should call .to_solr on all
|
493
|
-
mock1 = double("ds1"
|
494
|
-
|
495
|
-
|
496
|
-
expect(
|
497
|
-
expect(mock1).to receive(:solrize_profile)
|
498
|
-
expect(mock2).to receive(:solrize_profile)
|
499
|
-
|
500
|
-
expect(@test_object).to receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
|
501
|
-
expect(@test_object).to receive(:solrize_relationships)
|
502
|
-
@test_object.to_solr
|
503
|
-
end
|
504
|
-
it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
|
505
|
-
mock = double("ds1", :to_solr => {})
|
506
|
-
expect(mock).to receive(:solrize_profile)
|
278
|
+
it "should call .to_solr on all datastreams, passing the resulting document to solr" do
|
279
|
+
mock1 = double("ds1")
|
280
|
+
expect(mock1).to receive(:to_solr).and_return({})
|
281
|
+
mock2 = double("ds2")
|
282
|
+
expect(mock2).to receive(:to_solr).and_return({})
|
507
283
|
|
508
|
-
|
509
|
-
expect(@test_object).to receive(:solrize_relationships)
|
284
|
+
allow(@test_object).to receive(:attached_files).and_return(ds1: mock1, ds2: mock2)
|
285
|
+
expect(@test_object.indexing_service).to receive(:solrize_relationships)
|
510
286
|
@test_object.to_solr
|
511
287
|
end
|
512
|
-
|
513
|
-
it "should call .to_solr on the relationships rels-ext is dirty" do
|
514
|
-
@test_object.add_relationship(:has_collection_member, "info:fedora/test:member")
|
515
|
-
rels_ext = @test_object.rels_ext
|
516
|
-
expect(rels_ext).to be_changed
|
517
|
-
expect(@test_object).to receive(:solrize_relationships)
|
518
|
-
@test_object.to_solr
|
519
|
-
end
|
520
|
-
|
521
288
|
end
|
522
289
|
|
523
|
-
describe ".label" do
|
524
|
-
it "should return the label of the inner object" do
|
525
|
-
expect(@test_object.inner_object).to receive(:label).and_return("foo label")
|
526
|
-
expect(@test_object.label).to eq("foo label")
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
describe ".label=" do
|
531
|
-
it "should set the label of the inner object" do
|
532
|
-
expect(@test_object.label).not_to eq("foo label")
|
533
|
-
@test_object.label = "foo label"
|
534
|
-
expect(@test_object.label).to eq("foo label")
|
535
|
-
end
|
536
|
-
end
|
537
290
|
describe "update_attributes" do
|
538
291
|
it "should set the attributes and save" do
|
539
292
|
m = FooHistory.new
|
@@ -557,23 +310,5 @@ describe ActiveFedora::Base do
|
|
557
310
|
m.update(att)
|
558
311
|
end
|
559
312
|
end
|
560
|
-
|
561
|
-
describe ".solrize_relationships" do
|
562
|
-
it "should serialize the relationships into a Hash" do
|
563
|
-
graph = RDF::Graph.new
|
564
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
565
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
566
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
567
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
568
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
|
569
|
-
|
570
|
-
expect(@test_object).to receive(:relationships).and_return(graph)
|
571
|
-
solr_doc = @test_object.solrize_relationships
|
572
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("is_member_of", :symbol)]).to eq("info:fedora/demo:10")
|
573
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("is_part_of", :symbol)]).to eq("info:fedora/demo:11")
|
574
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)]).to eq("info:fedora/demo:12")
|
575
|
-
expect(solr_doc[ActiveFedora::SolrService.solr_name("conforms_to", :symbol)]).to eq("AnInterface")
|
576
|
-
end
|
577
|
-
end
|
578
313
|
end
|
579
314
|
end
|