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,281 +1,322 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
t
|
8
|
-
|
9
|
-
t.
|
10
|
-
t.
|
4
|
+
context "with an om datastream" do
|
5
|
+
before :all do
|
6
|
+
class BarStream2 < ActiveFedora::OmDatastream
|
7
|
+
set_terminology do |t|
|
8
|
+
t.root(path: "animals", xmlns: "urn:zoobar")
|
9
|
+
t.waterfowl do
|
10
|
+
t.ducks do
|
11
|
+
t.duck
|
12
|
+
end
|
11
13
|
end
|
14
|
+
t.donkey()
|
15
|
+
t.cow()
|
16
|
+
t.pig()
|
17
|
+
t.horse()
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.xml_template
|
21
|
+
Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
|
22
|
+
<waterfowl>
|
23
|
+
<ducks>
|
24
|
+
<duck/>
|
25
|
+
</ducks>
|
26
|
+
</waterfowl>
|
27
|
+
<cow></cow>
|
28
|
+
</animals>'
|
12
29
|
end
|
13
|
-
t.donkey()
|
14
|
-
t.cow()
|
15
|
-
t.pig()
|
16
|
-
t.horse()
|
17
30
|
end
|
31
|
+
end
|
32
|
+
after :all do
|
33
|
+
Object.send(:remove_const, :BarStream2)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "first level delegation" do
|
37
|
+
before :all do
|
38
|
+
class BarHistory2 < ActiveFedora::Base
|
39
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
40
|
+
m.field "fubar", :string
|
41
|
+
m.field "bandana", :string
|
42
|
+
m.field "swank", :text
|
43
|
+
m.field "animal_id", :string
|
44
|
+
end
|
45
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
|
46
|
+
m.field "fubar", :text
|
47
|
+
end
|
48
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2" do |m|
|
49
|
+
m.field "fubar", :text
|
50
|
+
end
|
51
|
+
|
52
|
+
has_metadata :type=>BarStream2, :name=>"xmlish"
|
53
|
+
has_attributes :cow, datastream: 'xmlish' # for testing the default value of multiple
|
54
|
+
has_attributes :fubar, datastream: 'withText', multiple: true # test alternate datastream
|
55
|
+
has_attributes :pig, datastream: 'xmlish', multiple: false
|
56
|
+
has_attributes :horse, datastream: 'xmlish', multiple: true
|
57
|
+
has_attributes :duck, datastream: 'xmlish', :at=>[:waterfowl, :ducks, :duck], multiple: true
|
58
|
+
has_attributes :animal_id, datastream: 'someData', multiple: false
|
59
|
+
|
60
|
+
property :goose, predicate: ::RDF::URI.new('http://example.com#hasGoose')
|
18
61
|
|
19
|
-
def self.xml_template
|
20
|
-
Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
|
21
|
-
<waterfowl>
|
22
|
-
<ducks>
|
23
|
-
<duck/>
|
24
|
-
</ducks>
|
25
|
-
</waterfowl>
|
26
|
-
<cow></cow>
|
27
|
-
</animals>'
|
28
62
|
end
|
29
63
|
end
|
30
|
-
end
|
31
|
-
after :all do
|
32
|
-
Object.send(:remove_const, :BarStream2)
|
33
|
-
end
|
34
64
|
|
35
|
-
|
36
|
-
|
37
|
-
class BarHistory2 < ActiveFedora::Base
|
38
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
39
|
-
m.field "fubar", :string
|
40
|
-
m.field "bandana", :string
|
41
|
-
m.field "swank", :text
|
42
|
-
m.field "animal_id", :string
|
43
|
-
end
|
44
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
|
45
|
-
m.field "fubar", :text
|
46
|
-
end
|
47
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
48
|
-
m.field "fubar", :text
|
49
|
-
end
|
50
|
-
|
51
|
-
has_metadata :type=>BarStream2, :name=>"xmlish"
|
52
|
-
has_attributes :cow, datastream: 'xmlish' # for testing the default value of multiple
|
53
|
-
has_attributes :fubar, datastream: 'withText', multiple: true # test alternate datastream
|
54
|
-
has_attributes :pig, datastream: 'xmlish', multiple: false
|
55
|
-
has_attributes :horse, datastream: 'xmlish', multiple: true
|
56
|
-
has_attributes :duck, datastream: 'xmlish', :at=>[:waterfowl, :ducks, :duck], multiple: true
|
57
|
-
has_attributes :animal_id, datastream: 'someData', multiple: false
|
65
|
+
after :all do
|
66
|
+
Object.send(:remove_const, :BarHistory2)
|
58
67
|
end
|
59
|
-
end
|
60
68
|
|
61
|
-
|
62
|
-
Object.send(:remove_const, :BarHistory2)
|
63
|
-
end
|
69
|
+
subject { BarHistory2.new }
|
64
70
|
|
65
|
-
|
71
|
+
describe "#attribute_names" do
|
72
|
+
context "on an instance" do
|
73
|
+
it "should list the attributes" do
|
74
|
+
expect(subject.attribute_names).to eq ["cow", "fubar", "pig", "horse", "duck", "animal_id", "goose"]
|
75
|
+
end
|
76
|
+
end
|
66
77
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
describe "with a pid" do
|
72
|
-
before { allow(subject).to receive_messages(pid: 'test:123') }
|
73
|
-
it "should show a pid" do
|
74
|
-
expect(subject.inspect).to eq "#<BarHistory2 pid: \"test:123\", cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil>"
|
78
|
+
context "on a class" do
|
79
|
+
it "should list the attributes" do
|
80
|
+
expect(BarHistory2.attribute_names).to eq ["cow", "fubar", "pig", "horse", "duck", "animal_id", "goose"]
|
81
|
+
end
|
75
82
|
end
|
76
83
|
end
|
77
|
-
|
78
|
-
|
79
|
-
it "should show
|
80
|
-
expect(subject.inspect).to eq "#<
|
84
|
+
|
85
|
+
describe "inspect" do
|
86
|
+
it "should show the attributes" do
|
87
|
+
expect(subject.inspect).to eq "#<BarHistory2 id: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: []>"
|
81
88
|
end
|
82
|
-
end
|
83
89
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
90
|
+
describe "with a id" do
|
91
|
+
before { allow(subject).to receive(:id).and_return('test:123') }
|
92
|
+
|
93
|
+
it "should show a id" do
|
94
|
+
expect(subject.inspect).to eq "#<BarHistory2 id: \"test:123\", cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: []>"
|
88
95
|
end
|
89
|
-
subject.library = library
|
90
96
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
97
|
+
|
98
|
+
describe "with no attributes" do
|
99
|
+
subject { ActiveFedora::Base.new }
|
100
|
+
it "should show a id" do
|
101
|
+
expect(subject.inspect).to eq "#<ActiveFedora::Base id: nil>"
|
102
|
+
end
|
95
103
|
end
|
96
|
-
|
97
|
-
|
104
|
+
|
105
|
+
describe "with relationships" do
|
106
|
+
before do
|
107
|
+
class BarHistory3 < BarHistory2
|
108
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasConstituent, class_name: 'BarHistory2'
|
109
|
+
end
|
110
|
+
subject.library = library
|
111
|
+
end
|
112
|
+
|
113
|
+
let (:library) { BarHistory2.create }
|
114
|
+
subject { BarHistory3.new }
|
115
|
+
|
116
|
+
after do
|
117
|
+
Object.send(:remove_const, :BarHistory3)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should show the library_id" do
|
121
|
+
expect(subject.inspect).to eq "#<BarHistory3 id: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: [], library_id: \"#{library.id}\">"
|
122
|
+
end
|
98
123
|
end
|
99
124
|
end
|
100
|
-
end
|
101
125
|
|
102
|
-
|
103
|
-
|
104
|
-
|
126
|
+
it "should reveal the unique properties" do
|
127
|
+
expect(BarHistory2.unique?(:horse)).to be false
|
128
|
+
expect(BarHistory2.unique?(:pig)).to be true
|
129
|
+
expect(BarHistory2.unique?(:cow)).to be true
|
130
|
+
end
|
105
131
|
|
106
|
-
|
107
|
-
|
108
|
-
|
132
|
+
it "should save a delegated property" do
|
133
|
+
subject.fubar= ["Quack"]
|
134
|
+
expect(subject.fubar).to eq ["Quack"]
|
135
|
+
expect(subject.withText.get_values(:fubar).first).to eq 'Quack'
|
136
|
+
subject.cow="Low"
|
137
|
+
expect(subject.cow).to eq "Low"
|
138
|
+
expect(subject.xmlish.term_values(:cow).first).to eq 'Low'
|
109
139
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect(BarHistory2.unique?(:cow)).to be true
|
114
|
-
end
|
140
|
+
subject.pig="Oink"
|
141
|
+
expect(subject.pig).to eq "Oink"
|
142
|
+
end
|
115
143
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
subject.cow = "Low"
|
121
|
-
expect(subject.cow).to eq("Low")
|
122
|
-
expect(subject.xmlish.term_values(:cow).first).to eq('Low')
|
144
|
+
it "should allow passing parameters to the delegate accessor" do
|
145
|
+
subject.fubar = ["one", "two"]
|
146
|
+
expect(subject.fubar(1)).to eq ['two']
|
147
|
+
end
|
123
148
|
|
124
|
-
|
125
|
-
|
126
|
-
|
149
|
+
describe "asigning wrong cardinality" do
|
150
|
+
it "should not allow passing a string to a multiple attribute writer" do
|
151
|
+
expect { subject.fubar = "Quack" }.to raise_error ArgumentError
|
152
|
+
expect { subject.fubar = ["Quack"] }.not_to raise_error
|
153
|
+
expect { subject.fubar = nil }.not_to raise_error
|
154
|
+
end
|
155
|
+
it "should deprecate passing an enumerable to a unique attribute writer" do
|
156
|
+
expect { subject.cow = "Low" }.not_to raise_error
|
157
|
+
expect { subject.cow = ["Low"]
|
158
|
+
}.to raise_error ArgumentError, "You attempted to set the attribute `cow' on `BarHistory2' to an enumerable value. However, this attribute is declared as being singular."
|
159
|
+
expect { subject.cow = nil }.not_to raise_error
|
160
|
+
end
|
161
|
+
end
|
127
162
|
|
128
|
-
it "should allow passing parameters to the delegate accessor" do
|
129
|
-
subject.fubar = ["one", "two"]
|
130
|
-
expect(subject.fubar(1)).to eq(['two'])
|
131
|
-
end
|
132
163
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
164
|
+
it "should return an array if marked as multiple" do
|
165
|
+
subject.horse=["neigh", "whinny"]
|
166
|
+
expect(subject.horse).to eq ["neigh", "whinny"]
|
167
|
+
end
|
137
168
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
169
|
+
it "should be able to delegate deeply into the terminology" do
|
170
|
+
subject.duck=["Quack", "Peep"]
|
171
|
+
expect(subject.duck).to eq ["Quack", "Peep"]
|
172
|
+
end
|
142
173
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
174
|
+
context "change tracking" do
|
175
|
+
it "should work for delegated attributes" do
|
176
|
+
expect {
|
177
|
+
subject.fubar = ["Meow"]
|
178
|
+
}.to change { subject.fubar_changed? }.from(false).to(true)
|
179
|
+
end
|
148
180
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
181
|
+
it "should work for properties" do
|
182
|
+
expect {
|
183
|
+
subject.goose = ["honk!"]
|
184
|
+
}.to change { subject.goose_changed? }.from(false).to(true)
|
185
|
+
end
|
153
186
|
end
|
154
187
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
188
|
+
describe "array getters and setters" do
|
189
|
+
it "should accept symbol keys" do
|
190
|
+
subject[:duck]= ["Cluck", "Gobble"]
|
191
|
+
expect(subject[:duck]).to eq ["Cluck", "Gobble"]
|
192
|
+
end
|
159
193
|
|
160
|
-
|
161
|
-
|
162
|
-
|
194
|
+
it "should accept string keys" do
|
195
|
+
subject['duck']= ["Cluck", "Gobble"]
|
196
|
+
expect(subject['duck']).to eq ["Cluck", "Gobble"]
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should accept field names with _id that are not associations" do
|
200
|
+
subject['animal_id'] = "lemur"
|
201
|
+
expect(subject['animal_id']).to eq "lemur"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should raise an error on the reader when the field isn't delegated" do
|
205
|
+
expect {subject['donkey'] }.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `donkey'"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should raise an error on the setter when the field isn't delegated" do
|
209
|
+
expect {subject['donkey']="bray" }.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `donkey'"
|
210
|
+
end
|
163
211
|
end
|
164
212
|
|
165
|
-
|
166
|
-
|
213
|
+
describe "attributes=" do
|
214
|
+
it "should raise an error on an invalid attribute" do
|
215
|
+
expect {subject.attributes = {'donkey'=>"bray" }}.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `donkey'"
|
216
|
+
end
|
167
217
|
end
|
168
218
|
|
169
|
-
|
170
|
-
|
219
|
+
describe "attributes" do
|
220
|
+
let(:vals) { {'cow'=>"moo", 'pig' => 'oink', 'horse' =>['neigh'], "fubar"=>[], 'duck'=>['quack'], 'animal_id'=>'', 'goose' => [] } }
|
221
|
+
before { subject.attributes = vals }
|
222
|
+
it "should return a hash" do
|
223
|
+
expect(subject.attributes).to eq(vals.merge('id' => nil))
|
224
|
+
end
|
171
225
|
end
|
172
|
-
end
|
173
226
|
|
174
|
-
|
175
|
-
|
176
|
-
|
227
|
+
describe '.multiple?', focus: true do
|
228
|
+
it 'returns false if attribute has not been defined as multi-valued' do
|
229
|
+
expect(BarHistory2.multiple?(:pig)).to be false
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'returns true if attribute is a ActiveTriples property' do
|
233
|
+
expect(BarHistory2.multiple?(:goose)).to be true
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'returns true if attribute has been defined as multi-valued' do
|
237
|
+
expect(BarHistory2.multiple?(:horse)).to be true
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'raises an error if the attribute does not exist' do
|
241
|
+
expect{BarHistory2.multiple?(:arbitrary_nonexistent_attribute)}.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `arbitrary_nonexistent_attribute'"
|
242
|
+
end
|
177
243
|
end
|
178
|
-
end
|
179
244
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
expect(subject.attributes).to eq(vals.merge('id' => nil))
|
245
|
+
describe ".datastream_class_for_name" do
|
246
|
+
it "should return the specifed class" do
|
247
|
+
expect(BarHistory2.send(:datastream_class_for_name, 'someData')).to eq ActiveFedora::SimpleDatastream
|
248
|
+
end
|
185
249
|
end
|
186
250
|
end
|
187
251
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
252
|
+
describe "with a superclass" do
|
253
|
+
before :all do
|
254
|
+
class BarHistory2 < ActiveFedora::Base
|
255
|
+
has_metadata 'xmlish', :type=>BarStream2
|
256
|
+
has_attributes :donkey, :cow, datastream: 'xmlish', multiple: true
|
257
|
+
end
|
258
|
+
class BarHistory3 < BarHistory2
|
259
|
+
end
|
195
260
|
end
|
196
|
-
|
261
|
+
|
262
|
+
after :all do
|
263
|
+
Object.send(:remove_const, :BarHistory3)
|
264
|
+
Object.send(:remove_const, :BarHistory2)
|
197
265
|
end
|
198
|
-
end
|
199
266
|
|
200
|
-
|
201
|
-
Object.send(:remove_const, :BarHistory3)
|
202
|
-
Object.send(:remove_const, :BarHistory2)
|
203
|
-
end
|
267
|
+
subject { BarHistory3.new }
|
204
268
|
|
205
|
-
|
269
|
+
it "should be able to delegate deeply into the terminology" do
|
270
|
+
subject.donkey=["Bray", "Hee-haw"]
|
271
|
+
expect(subject.donkey).to eq ["Bray", "Hee-haw"]
|
272
|
+
end
|
206
273
|
|
207
|
-
|
208
|
-
|
209
|
-
|
274
|
+
it "should be able to track change status" do
|
275
|
+
expect {
|
276
|
+
subject.cow = ["Moo"]
|
277
|
+
}.to change { subject.cow_changed? }.from(false).to(true)
|
278
|
+
end
|
210
279
|
end
|
211
|
-
|
212
|
-
it "should be able to track change status" do
|
213
|
-
expect(subject.cow_changed?).to be false
|
214
|
-
subject.cow = ["Moo"]
|
215
|
-
expect(subject.cow_changed?).to be true
|
216
|
-
end
|
217
280
|
end
|
218
281
|
|
219
|
-
|
282
|
+
context "with a RDF datastream" do
|
220
283
|
before :all do
|
221
284
|
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
222
|
-
property :title, :
|
223
|
-
property :description, :
|
224
|
-
property :author, :predicate => RDF::FOAF.Person
|
225
|
-
property :editor, :predicate => RDF::FOAF.Person
|
285
|
+
property :title, predicate: ::RDF::DC.title
|
286
|
+
property :description, predicate: ::RDF::DC.description
|
226
287
|
end
|
227
288
|
class BarHistory4 < ActiveFedora::Base
|
228
289
|
has_metadata 'rdfish', :type=>BarRdfDatastream
|
229
290
|
has_attributes :title, datastream: 'rdfish', multiple: true
|
230
291
|
has_attributes :description, datastream: 'rdfish', multiple: false
|
231
|
-
has_attributes :author, datastream: 'rdfish', multiple: false
|
232
|
-
has_attributes :editor, datastream: 'rdfish', multiple: true
|
233
|
-
end
|
234
|
-
class PersonResource < ActiveTriples::Resource
|
235
|
-
configure type: RDF::FOAF.Person
|
236
|
-
property :person_name, predicate: RDF::FOAF.name
|
237
292
|
end
|
238
293
|
end
|
239
294
|
|
240
295
|
after :all do
|
241
296
|
Object.send(:remove_const, :BarHistory4)
|
242
297
|
Object.send(:remove_const, :BarRdfDatastream)
|
243
|
-
Object.send(:remove_const, :PersonResource)
|
244
298
|
end
|
245
299
|
|
246
300
|
subject { BarHistory4.new }
|
247
301
|
|
248
|
-
|
302
|
+
context "with a multivalued field" do
|
249
303
|
it "should be able to track change status" do
|
250
|
-
expect
|
251
|
-
|
252
|
-
|
253
|
-
end
|
254
|
-
it "should not accept a single literal value" do
|
255
|
-
expect { subject.title = "Title1" }.to raise_error
|
256
|
-
end
|
257
|
-
it "should not accept a single ActiveTriples::Resource" do
|
258
|
-
editor = PersonResource.new.tap { |p| p.person_name = "Sally" }
|
259
|
-
expect { subject.editor = editor }.to raise_error
|
304
|
+
expect {
|
305
|
+
subject.title = ["Title1", "Title2"]
|
306
|
+
}.to change { subject.title_changed? }.from(false).to(true)
|
260
307
|
end
|
261
308
|
end
|
262
|
-
|
309
|
+
|
310
|
+
context "with a single-valued field" do
|
263
311
|
it "should be able to track change status" do
|
264
|
-
expect
|
265
|
-
|
266
|
-
|
267
|
-
end
|
268
|
-
it "should not accept an array of literal values" do
|
269
|
-
expect { subject.description = ["A brief description", "A longer description"] }.to raise_error
|
270
|
-
end
|
271
|
-
it "should accept an ActiveTriples::Resource" do
|
272
|
-
author = PersonResource.new.tap { |p| p.person_name = "Bob" }
|
273
|
-
expect { subject.author = author }.not_to raise_error
|
312
|
+
expect {
|
313
|
+
subject.description = "A brief description"
|
314
|
+
}.to change { subject.description_changed? }.from(false).to(true)
|
274
315
|
end
|
275
316
|
end
|
276
|
-
end
|
317
|
+
end
|
277
318
|
|
278
|
-
|
319
|
+
context "without a datastream" do
|
279
320
|
before :all do
|
280
321
|
class BarHistory4 < ActiveFedora::Base
|
281
322
|
end
|
@@ -285,14 +326,17 @@ describe ActiveFedora::Base do
|
|
285
326
|
Object.send(:remove_const, :BarHistory4)
|
286
327
|
end
|
287
328
|
|
288
|
-
subject { BarHistory4
|
329
|
+
subject { BarHistory4}
|
289
330
|
|
290
|
-
|
291
|
-
|
331
|
+
describe "has_attributes" do
|
332
|
+
it "should raise an error" do
|
333
|
+
expect {subject.has_attributes :title, :description, multiple: true}.to raise_error
|
334
|
+
end
|
292
335
|
end
|
293
336
|
end
|
294
337
|
|
295
|
-
|
338
|
+
|
339
|
+
context "when an unknown datastream is specified" do
|
296
340
|
before :all do
|
297
341
|
class BarHistory4 < ActiveFedora::Base
|
298
342
|
has_attributes :description, datastream: 'rdfish', multiple: true
|
@@ -310,15 +354,21 @@ describe ActiveFedora::Base do
|
|
310
354
|
end
|
311
355
|
|
312
356
|
it "should raise an error on set" do
|
313
|
-
expect {subject.description = ['Neat']}.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
|
357
|
+
expect { subject.description = ['Neat'] }.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
|
358
|
+
end
|
359
|
+
|
360
|
+
describe ".datastream_class_for_name" do
|
361
|
+
it "should return the default class" do
|
362
|
+
expect(BarHistory4.send(:datastream_class_for_name, 'content')).to eq ActiveFedora::File
|
363
|
+
end
|
314
364
|
end
|
315
365
|
end
|
316
366
|
|
317
|
-
|
367
|
+
context "when a datastream is specified as a symbol" do
|
318
368
|
before :all do
|
319
369
|
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
320
|
-
property :title, :
|
321
|
-
property :description, :
|
370
|
+
property :title, predicate: ::RDF::DC.title
|
371
|
+
property :description, predicate: ::RDF::DC.description
|
322
372
|
end
|
323
373
|
class BarHistory4 < ActiveFedora::Base
|
324
374
|
has_metadata 'rdfish', :type=>BarRdfDatastream
|
@@ -337,6 +387,35 @@ describe ActiveFedora::Base do
|
|
337
387
|
expect(subject.description).to eq 'test1'
|
338
388
|
end
|
339
389
|
end
|
390
|
+
|
391
|
+
context "when properties are defined on an object" do
|
392
|
+
before :all do
|
393
|
+
class BarHistory4 < ActiveFedora::Base
|
394
|
+
property :title, predicate: ::RDF::DC.title do |index|
|
395
|
+
index.as :symbol
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
after :all do
|
401
|
+
Object.send(:remove_const, :BarHistory4)
|
402
|
+
end
|
403
|
+
|
404
|
+
let(:obj) { BarHistory4.new(title: ['test1']) }
|
405
|
+
subject { obj }
|
406
|
+
|
407
|
+
it "should be able to access the attributes" do
|
408
|
+
expect(subject.title).to eq ['test1']
|
409
|
+
end
|
410
|
+
|
411
|
+
context "indexing" do
|
412
|
+
let(:solr_doc) { obj.to_solr }
|
413
|
+
|
414
|
+
it "should index the attributes" do
|
415
|
+
expect(solr_doc['title_ssim']).to eq ['test1']
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
340
419
|
end
|
341
420
|
|
342
421
|
|