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
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
before do
|
5
|
-
class Library < ActiveFedora::Base
|
5
|
+
class Library < ActiveFedora::Base
|
6
6
|
has_many :books
|
7
7
|
end
|
8
8
|
|
9
|
-
class Book < ActiveFedora::Base
|
10
|
-
belongs_to :library,
|
9
|
+
class Book < ActiveFedora::Base
|
10
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasConstituent
|
11
11
|
end
|
12
12
|
class SpecialInheritedBook < Book
|
13
13
|
end
|
@@ -25,12 +25,19 @@ describe ActiveFedora::Base do
|
|
25
25
|
describe "setting the id property" do
|
26
26
|
it "should store it" do
|
27
27
|
book.library_id = library.id
|
28
|
-
expect(book.library_id).to eq
|
28
|
+
expect(book.library_id).to eq library.id
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should mark it as changed" do
|
32
|
+
expect {
|
33
|
+
book.library_id = library.id
|
34
|
+
}.to change { book.changed? }.from(false).to(true)
|
29
35
|
end
|
30
36
|
|
31
37
|
describe "reassigning the parent_id" do
|
32
38
|
let(:library2) { Library.create}
|
33
39
|
before { book.library = library2 }
|
40
|
+
|
34
41
|
it "should update the object" do
|
35
42
|
expect(book.library).to eq library2 # cause the association to set @loaded
|
36
43
|
library_proxy = book.send(:association_instance_get, :library)
|
@@ -43,19 +50,14 @@ describe ActiveFedora::Base do
|
|
43
50
|
|
44
51
|
it "should be settable via []=" do
|
45
52
|
book[:library_id] = library.id
|
46
|
-
expect(book.library_id).to eq
|
47
|
-
end
|
48
|
-
|
49
|
-
it "safely handles invalid data" do
|
50
|
-
book[:library_id] = 'bad:identifier'
|
51
|
-
expect(book.library).to be_nil
|
53
|
+
expect(book.library_id).to eq library.id
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
57
|
describe "getting the id property" do
|
56
58
|
it "should be accessable via []" do
|
57
59
|
book[:library_id] = library.id
|
58
|
-
expect(book[:library_id]).to eq
|
60
|
+
expect(book[:library_id]).to eq library.id
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
@@ -84,19 +86,23 @@ describe ActiveFedora::Base do
|
|
84
86
|
describe "casting inheritance detailed test cases" do
|
85
87
|
before :all do
|
86
88
|
class SimpleObject < ActiveFedora::Base
|
87
|
-
belongs_to :simple_collection,
|
88
|
-
belongs_to :complex_collection,
|
89
|
+
belongs_to :simple_collection, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'SimpleCollection'
|
90
|
+
belongs_to :complex_collection, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ComplexCollection'
|
89
91
|
end
|
90
92
|
|
91
93
|
class ComplexObject < SimpleObject
|
94
|
+
belongs_to :simple_collection, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'SimpleCollection'
|
95
|
+
belongs_to :complex_collection, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ComplexCollection'
|
92
96
|
end
|
93
97
|
|
94
98
|
class SimpleCollection < ActiveFedora::Base
|
95
|
-
has_many :objects,
|
96
|
-
has_many :complex_objects,
|
99
|
+
has_many :objects, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'SimpleObject', autosave: true
|
100
|
+
has_many :complex_objects, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ComplexObject', autosave: true
|
97
101
|
end
|
98
102
|
|
99
103
|
class ComplexCollection < SimpleCollection
|
104
|
+
has_many :objects, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'SimpleObject', autosave: true
|
105
|
+
has_many :complex_objects, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ComplexObject', autosave: true
|
100
106
|
end
|
101
107
|
|
102
108
|
end
|
@@ -108,73 +114,77 @@ describe ActiveFedora::Base do
|
|
108
114
|
end
|
109
115
|
|
110
116
|
describe "saving between the before and after hooks" do
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@complex_collection.add_relationship(:has_model, @complex_collection.class.superclass.to_class_uri)
|
125
|
-
|
126
|
-
@simple_collection.objects = [@simple_object, @simple_object_second, @complex_object]
|
127
|
-
@simple_collection.save!
|
128
|
-
@complex_collection.objects = [@simple_object_third, @complex_object_second]
|
129
|
-
@complex_collection.save!
|
130
|
-
@complex_object.save!
|
131
|
-
@simple_object.save!
|
132
|
-
@simple_object_second.save!
|
117
|
+
context "Add a complex_object into a simple_collection" do
|
118
|
+
before do
|
119
|
+
@simple_collection = SimpleCollection.create
|
120
|
+
@complex_collection = ComplexCollection.create
|
121
|
+
@complex_object = ComplexObject.create
|
122
|
+
@simple_collection.objects = [@complex_object]
|
123
|
+
@simple_collection.save!
|
124
|
+
@complex_collection.save!
|
125
|
+
end
|
126
|
+
it "should have added the inverse relationship for the correct class" do
|
127
|
+
expect(@complex_object.simple_collection).to be_instance_of SimpleCollection
|
128
|
+
expect(@complex_object.complex_collection).to be_nil
|
129
|
+
end
|
133
130
|
end
|
134
131
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
expect(@simple_object_second.simple_collection).to be_instance_of SimpleCollection
|
148
|
-
expect(@simple_object_second.complex_collection).to be_nil
|
149
|
-
|
150
|
-
expect(@simple_object_third.simple_collection).to be_instance_of ComplexCollection
|
151
|
-
expect(@simple_object_third.complex_collection).to be_instance_of ComplexCollection
|
152
|
-
|
153
|
-
expect(@simple_collection.objects.size).to eq(3)
|
154
|
-
expect(@simple_collection.objects[0]).to be_instance_of SimpleObject
|
155
|
-
expect(@simple_collection.objects[1]).to be_instance_of SimpleObject
|
156
|
-
expect(@simple_collection.objects[2]).to be_instance_of ComplexObject
|
157
|
-
|
158
|
-
expect(@complex_collection.objects.size).to eq(2)
|
159
|
-
expect(@complex_collection.objects[0]).to be_instance_of SimpleObject
|
160
|
-
expect(@complex_collection.objects[1]).to be_instance_of ComplexObject
|
161
|
-
|
132
|
+
context "Add a complex_object into a complex_collection" do
|
133
|
+
before do
|
134
|
+
@complex_collection = ComplexCollection.create
|
135
|
+
@complex_object = ComplexObject.create
|
136
|
+
@complex_collection.objects = [@complex_object] # this sticks it into the :objects association, but since it is a ComplexObject it should also be fetched by :complex_collection association
|
137
|
+
@complex_collection.save
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should have added the inverse relationship for the correct class" do
|
141
|
+
expect(@complex_object.complex_collection).to be_instance_of ComplexCollection
|
142
|
+
expect(@complex_object.reload.simple_collection).to be_instance_of ComplexCollection
|
143
|
+
end
|
162
144
|
end
|
163
145
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
146
|
+
context "Adding mixed types on a base class with a filtered has_many relationship" do
|
147
|
+
before do
|
148
|
+
@simple_collection = SimpleCollection.create
|
149
|
+
@complex_object = ComplexObject.create
|
150
|
+
@simple_object = SimpleObject.create
|
151
|
+
@simple_collection.objects = [@complex_object, @simple_object]
|
152
|
+
@simple_collection.save!
|
153
|
+
end
|
154
|
+
it "ignores objects who's classes aren't specified" do
|
155
|
+
expect(@simple_collection.complex_objects.size).to eq 1
|
156
|
+
expect(@simple_collection.complex_objects[0]).to be_instance_of ComplexObject
|
157
|
+
expect(@simple_collection.complex_objects[1]).to be_nil
|
158
|
+
|
159
|
+
expect(@simple_collection.objects.size).to eq 2
|
160
|
+
expect(@simple_collection.objects[0]).to be_instance_of ComplexObject
|
161
|
+
expect(@simple_collection.objects[1]).to be_instance_of SimpleObject
|
162
|
+
|
163
|
+
expect(@simple_object.simple_collection).to be_instance_of SimpleCollection
|
164
|
+
expect(@simple_object.complex_collection).to be_nil
|
165
|
+
end
|
172
166
|
end
|
173
167
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
168
|
+
context "Adding mixed types on a subclass with a filtered has_many relationship" do
|
169
|
+
before do
|
170
|
+
@complex_collection = ComplexCollection.create
|
171
|
+
@complex_object = ComplexObject.create
|
172
|
+
@simple_object = SimpleObject.create
|
173
|
+
@complex_collection.objects = [@complex_object, @simple_object]
|
174
|
+
@complex_collection.save!
|
175
|
+
end
|
176
|
+
it "ignores objects who's classes aren't specified" do
|
177
|
+
expect(@complex_collection.complex_objects.size).to eq 1
|
178
|
+
expect(@complex_collection.complex_objects[0]).to be_instance_of ComplexObject
|
179
|
+
expect(@complex_collection.complex_objects[1]).to be_nil
|
180
|
+
|
181
|
+
expect(@complex_collection.objects.size).to eq 2
|
182
|
+
expect(@complex_collection.objects[0]).to be_instance_of ComplexObject
|
183
|
+
expect(@complex_collection.objects[1]).to be_instance_of SimpleObject
|
184
|
+
|
185
|
+
expect(@simple_object.complex_collection).to be_instance_of ComplexCollection
|
186
|
+
expect(@simple_object.reload.simple_collection).to be_instance_of ComplexCollection
|
187
|
+
end
|
178
188
|
end
|
179
189
|
end
|
180
190
|
end
|
@@ -30,13 +30,13 @@ describe 'bugs' do
|
|
30
30
|
@test_object.someData.fubar=['initial']
|
31
31
|
@test_object.save!
|
32
32
|
|
33
|
-
x = FooHistory.find(@test_object.
|
33
|
+
x = FooHistory.find(@test_object.id)
|
34
34
|
x.someData.fubar = ["replacement"] # set a new value
|
35
35
|
x.save!
|
36
36
|
|
37
37
|
|
38
|
-
x = FooHistory.find(@test_object.
|
39
|
-
expect(x.someData.fubar).to eq
|
38
|
+
x = FooHistory.find(@test_object.id)
|
39
|
+
expect(x.someData.fubar).to eq ["replacement"] # recall the value
|
40
40
|
x.save
|
41
41
|
end
|
42
42
|
end
|
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
before do
|
5
|
-
class Library < ActiveFedora::Base
|
5
|
+
class Library < ActiveFedora::Base
|
6
6
|
has_many :books
|
7
7
|
end
|
8
8
|
class Book < ActiveFedora::Base
|
9
|
-
belongs_to :library,
|
9
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasMember
|
10
10
|
end
|
11
11
|
end
|
12
12
|
let(:library) { Library.create! }
|
@@ -20,10 +20,10 @@ describe ActiveFedora::Base do
|
|
20
20
|
end
|
21
21
|
describe "load_from_solr" do
|
22
22
|
it "should set rows to count, if not specified" do
|
23
|
-
expect(library.books(response_format: :solr).size).to eq
|
23
|
+
expect(library.books(response_format: :solr).size).to eq 2
|
24
24
|
end
|
25
25
|
it "should limit rows returned if option passed" do
|
26
|
-
expect(library.books(response_format: :solr, rows: 1).size).to eq
|
26
|
+
expect(library.books(response_format: :solr, rows: 1).size).to eq 1
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -2,24 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Nested Rdf Objects" do
|
4
4
|
describe "without type" do
|
5
|
-
before
|
5
|
+
before do
|
6
6
|
class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
|
7
|
-
property :parts, predicate: RDF::DC.hasPart, class_name: 'Component'
|
7
|
+
property :parts, predicate: ::RDF::DC.hasPart, class_name: 'Component'
|
8
8
|
|
9
9
|
class Component < ActiveTriples::Resource
|
10
|
-
property :label, predicate: RDF::DC.title
|
10
|
+
property :label, predicate: ::RDF::DC.title
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
-
after
|
16
|
+
after do
|
17
17
|
Object.send(:remove_const, :SpecDatastream)
|
18
18
|
end
|
19
19
|
|
20
|
-
let
|
21
|
-
|
22
|
-
ds = SpecDatastream.new(test_obj, 'descMd')
|
20
|
+
let(:ds) do
|
21
|
+
ds = SpecDatastream.new('http://localhost:8983/fedora/rest/test/test:124/descMd')
|
23
22
|
end
|
24
23
|
|
25
24
|
describe "#new_record?" do
|
@@ -30,9 +29,9 @@ describe "Nested Rdf Objects" do
|
|
30
29
|
|
31
30
|
it "should not be new when it's loaded from fedora" do
|
32
31
|
ds.content = '_:g70324142325120 <http://purl.org/dc/terms/title> "Alternator" .
|
33
|
-
<
|
32
|
+
<http://localhost:8983/fedora/rest/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70324142325120 .'
|
34
33
|
ds.resource.persist!
|
35
|
-
expect(ds.parts.first).
|
34
|
+
expect(ds.parts.first).to_not be_new_record
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -40,24 +39,24 @@ describe "Nested Rdf Objects" do
|
|
40
39
|
comp = SpecDatastream::Component.new(ds.graph)
|
41
40
|
comp.label = ["Alternator"]
|
42
41
|
ds.parts = comp
|
43
|
-
expect(ds.parts.first.label).to eq
|
42
|
+
expect(ds.parts.first.label).to eq ["Alternator"]
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should be able to replace attributes" do
|
47
46
|
v = ds.parts.build(label: 'Alternator')
|
48
|
-
expect(ds.parts.first.label).to eq
|
47
|
+
expect(ds.parts.first.label).to eq ['Alternator']
|
49
48
|
ds.parts.first.label = ['Distributor']
|
50
|
-
expect(ds.parts.first.label).to eq
|
49
|
+
expect(ds.parts.first.label).to eq ['Distributor']
|
51
50
|
end
|
52
51
|
|
53
52
|
it "should be able to replace objects" do
|
54
53
|
ds.parts.build(label: 'Alternator')
|
55
54
|
ds.parts.build(label: 'Distributor')
|
56
|
-
expect(ds.parts.size).to eq
|
55
|
+
expect(ds.parts.size).to eq 2
|
57
56
|
comp = SpecDatastream::Component.new(ds.graph)
|
58
57
|
comp.label = "Injector port"
|
59
58
|
ds.parts = [comp]
|
60
|
-
expect(ds.parts.size).to eq
|
59
|
+
expect(ds.parts.size).to eq 1
|
61
60
|
end
|
62
61
|
|
63
62
|
it "should be able to nest many complex objects" do
|
@@ -66,8 +65,8 @@ describe "Nested Rdf Objects" do
|
|
66
65
|
comp2 = SpecDatastream::Component.new ds.graph
|
67
66
|
comp2.label = ["Crankshaft"]
|
68
67
|
ds.parts = [comp1, comp2]
|
69
|
-
expect(ds.parts.first.label).to eq
|
70
|
-
expect(ds.parts.last.label).to eq
|
68
|
+
expect(ds.parts.first.label).to eq ["Alternator"]
|
69
|
+
expect(ds.parts.last.label).to eq ["Crankshaft"]
|
71
70
|
end
|
72
71
|
|
73
72
|
it "should be able to clear complex objects" do
|
@@ -77,51 +76,51 @@ describe "Nested Rdf Objects" do
|
|
77
76
|
comp2.label = ["Crankshaft"]
|
78
77
|
ds.parts = [comp1, comp2]
|
79
78
|
ds.parts = []
|
80
|
-
expect(ds.parts).to eq
|
79
|
+
expect(ds.parts).to eq []
|
81
80
|
end
|
82
81
|
|
83
82
|
it "should load complex objects" do
|
84
83
|
ds.content = <<END
|
85
84
|
_:g70350851837440 <http://purl.org/dc/terms/title> "Alternator" .
|
86
|
-
<
|
87
|
-
<
|
85
|
+
<http://localhost:8983/fedora/rest/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851837440 .
|
86
|
+
<http://localhost:8983/fedora/rest/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851833380 .
|
88
87
|
_:g70350851833380 <http://purl.org/dc/terms/title> "Crankshaft" .
|
89
88
|
END
|
90
|
-
expect(ds.parts.first.label).to eq
|
89
|
+
expect(ds.parts.first.label).to eq ["Alternator"]
|
91
90
|
end
|
92
91
|
|
93
92
|
it "should build complex objects when a parent node doesn't exist" do
|
94
93
|
part = ds.parts.build
|
95
94
|
expect(part).to be_kind_of SpecDatastream::Component
|
96
95
|
part.label = "Wheel bearing"
|
97
|
-
expect(ds.parts.first.label).to eq
|
96
|
+
expect(ds.parts.first.label).to eq ['Wheel bearing']
|
98
97
|
end
|
99
98
|
|
100
99
|
it "should not create a child node when hitting the accessor" do
|
101
100
|
ds.parts
|
102
101
|
expect(ds.parts.first).to be_nil
|
103
|
-
expect(ds.serialize).to eq
|
102
|
+
expect(ds.serialize).to eq ''
|
104
103
|
end
|
105
104
|
|
106
105
|
it "should build complex objects when a parent node exists" do
|
107
106
|
part = ds.parts.build
|
108
107
|
expect(part).to be_kind_of SpecDatastream::Component
|
109
108
|
part.label = "Wheel bearing"
|
110
|
-
expect(ds.parts.first.label).to eq
|
109
|
+
expect(ds.parts.first.label).to eq ['Wheel bearing']
|
111
110
|
end
|
112
111
|
|
113
112
|
describe "#first_or_create" do
|
114
113
|
it "should return a result if the predicate exists" do
|
115
114
|
part1 = ds.parts.build
|
116
115
|
part2 = ds.parts.build
|
117
|
-
expect(ds.parts.first_or_create).to eq
|
116
|
+
expect(ds.parts.first_or_create).to eq part1
|
118
117
|
end
|
119
118
|
|
120
119
|
it "should create a new result if the predicate doesn't exist" do
|
121
|
-
expect(ds.parts).to eq
|
120
|
+
expect(ds.parts).to eq []
|
122
121
|
part = ds.parts.first_or_create(label: 'Front control arm bushing')
|
123
|
-
expect(part.label).to eq
|
124
|
-
expect(ds.parts).to eq
|
122
|
+
expect(part.label).to eq ['Front control arm bushing']
|
123
|
+
expect(ds.parts).to eq [part]
|
125
124
|
end
|
126
125
|
|
127
126
|
end
|
@@ -132,11 +131,11 @@ END
|
|
132
131
|
describe "one class per assertion" do
|
133
132
|
before(:each) do
|
134
133
|
class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
|
135
|
-
property :mediator, predicate: RDF::DC.mediator, class_name: 'MediatorUser'
|
134
|
+
property :mediator, predicate: ::RDF::DC.mediator, class_name: 'MediatorUser'
|
136
135
|
|
137
136
|
class MediatorUser < ActiveTriples::Resource
|
138
|
-
configure type: RDF::DC.AgentClass
|
139
|
-
property :title, predicate: RDF::DC.title
|
137
|
+
configure type: ::RDF::DC.AgentClass
|
138
|
+
property :title, predicate: ::RDF::DC.title
|
140
139
|
end
|
141
140
|
end
|
142
141
|
end
|
@@ -144,37 +143,33 @@ END
|
|
144
143
|
after(:each) do
|
145
144
|
Object.send(:remove_const, :SpecDatastream)
|
146
145
|
end
|
147
|
-
|
148
|
-
let (:ds) do
|
149
|
-
mock_obj = double(:mock_obj, pid: 'test:124', :new_record? => true)
|
150
|
-
ds = SpecDatastream.new(mock_obj, 'descMd')
|
151
|
-
end
|
146
|
+
let (:ds) { SpecDatastream.new('http://localhost:8983/fedora/rest/test/test:124/descMd') }
|
152
147
|
|
153
148
|
|
154
149
|
it "should store the type of complex objects when type is specified" do
|
155
150
|
comp = SpecDatastream::MediatorUser.new ds.graph
|
156
151
|
comp.title = ["Doctor"]
|
157
152
|
ds.mediator = comp
|
158
|
-
expect(ds.mediator.first.type.first).to be_instance_of RDF::URI
|
159
|
-
expect(ds.mediator.first.type.first.to_s).to eq
|
160
|
-
expect(ds.mediator.first.title.first).to eq
|
153
|
+
expect(ds.mediator.first.type.first).to be_instance_of ::RDF::URI
|
154
|
+
expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
|
155
|
+
expect(ds.mediator.first.title.first).to eq 'Doctor'
|
161
156
|
end
|
162
157
|
|
163
158
|
it "should add the type of complex object when it is not provided" do
|
164
159
|
ds.content = <<END
|
165
160
|
_:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Person" .
|
166
|
-
<
|
161
|
+
<http://localhost:8983/fedora/rest/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
|
167
162
|
END
|
168
|
-
expect(ds.mediator.first.type.first.to_s).to eq
|
163
|
+
expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
|
169
164
|
end
|
170
165
|
|
171
166
|
it "should add load the type of complex objects when provided (superceeding what is specified by the class)" do
|
172
167
|
ds.content = <<END
|
173
168
|
_:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Orgainzation" .
|
174
169
|
_:g70350851837440 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ebu.ch/metadata/ontologies/ebucore#Organisation> .
|
175
|
-
<
|
170
|
+
<http://localhost:8983/fedora/rest/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
|
176
171
|
END
|
177
|
-
expect(ds.mediator.first.type.first.to_s).to eq
|
172
|
+
expect(ds.mediator.first.type.first.to_s).to eq "http://www.ebu.ch/metadata/ontologies/ebucore#Organisation"
|
178
173
|
end
|
179
174
|
end
|
180
175
|
|
@@ -185,6 +180,10 @@ END
|
|
185
180
|
property :title
|
186
181
|
end
|
187
182
|
|
183
|
+
class Container < ActiveFedora::Base
|
184
|
+
contains :info, class_name: 'SpecDatastream'
|
185
|
+
end
|
186
|
+
|
188
187
|
class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
|
189
188
|
property :series, predicate: EbuCore.isEpisodeOf, class_name: 'Series'
|
190
189
|
property :program, predicate: EbuCore.isEpisodeOf, class_name: 'Program'
|
@@ -204,32 +203,31 @@ END
|
|
204
203
|
|
205
204
|
after(:each) do
|
206
205
|
Object.send(:remove_const, :SpecDatastream)
|
206
|
+
Object.send(:remove_const, :Container)
|
207
207
|
end
|
208
208
|
|
209
|
-
let
|
210
|
-
|
211
|
-
ds = SpecDatastream.new(mock_obj, 'descMd')
|
212
|
-
end
|
209
|
+
let(:parent) { Container.new id: '124' }
|
210
|
+
let (:file) { parent.info }
|
213
211
|
|
214
212
|
|
215
213
|
it "should store the type of complex objects when type is specified" do
|
216
|
-
series = SpecDatastream::Series.new
|
214
|
+
series = SpecDatastream::Series.new file.graph
|
217
215
|
series.title = ["renovating bathrooms"]
|
218
|
-
|
216
|
+
file.series = series
|
219
217
|
|
220
|
-
program = SpecDatastream::Program.new
|
218
|
+
program = SpecDatastream::Program.new file.graph
|
221
219
|
program.title = ["This old House"]
|
222
|
-
|
220
|
+
file.program = program
|
223
221
|
|
224
|
-
expect(
|
225
|
-
expect(
|
226
|
-
expect(
|
227
|
-
expect(
|
222
|
+
expect(file.program.first.type.size).to eq 1
|
223
|
+
expect(file.program.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
|
224
|
+
expect(file.series.first.type.size).to eq 1
|
225
|
+
expect(file.series.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
|
228
226
|
end
|
229
227
|
|
230
228
|
it "should create an object of the correct type" do
|
231
|
-
expect(
|
232
|
-
expect(
|
229
|
+
expect(file.program.build).to be_kind_of SpecDatastream::Program
|
230
|
+
expect(file.series.build).to be_kind_of SpecDatastream::Series
|
233
231
|
end
|
234
232
|
end
|
235
233
|
end
|