active-fedora 10.1.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -7
- data/.rubocop_todo.yml +55 -0
- data/.solr_wrapper +6 -0
- data/.travis.yml +6 -9
- data/Gemfile +1 -0
- data/History.txt +34 -0
- data/README.md +1 -3
- data/active-fedora.gemspec +7 -13
- data/lib/active_fedora/aggregation/list_source.rb +2 -0
- data/lib/active_fedora/associations/association_scope.rb +1 -1
- data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
- data/lib/active_fedora/associations/builder/association.rb +1 -1
- data/lib/active_fedora/associations/builder/orders.rb +11 -3
- data/lib/active_fedora/associations/collection_association.rb +5 -5
- data/lib/active_fedora/associations/collection_proxy.rb +10 -10
- data/lib/active_fedora/associations/contained_finder.rb +2 -2
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +2 -2
- data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
- data/lib/active_fedora/associations/orders_association.rb +4 -0
- data/lib/active_fedora/associations/rdf.rb +2 -0
- data/lib/active_fedora/attribute_assignment.rb +0 -1
- data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
- data/lib/active_fedora/attribute_methods.rb +1 -1
- data/lib/active_fedora/attributes.rb +1 -1
- data/lib/active_fedora/base.rb +4 -8
- data/lib/active_fedora/change_set.rb +6 -2
- data/lib/active_fedora/cleaner.rb +1 -1
- data/lib/active_fedora/containers/container.rb +1 -1
- data/lib/active_fedora/core.rb +33 -30
- data/lib/active_fedora/fedora.rb +6 -2
- data/lib/active_fedora/fedora_attributes.rb +1 -1
- data/lib/active_fedora/file/streaming.rb +1 -1
- data/lib/active_fedora/file.rb +2 -1
- data/lib/active_fedora/file_configurator.rb +3 -3
- data/lib/active_fedora/indexing.rb +1 -18
- data/lib/active_fedora/indexing_service.rb +0 -9
- data/lib/active_fedora/initializing_connection.rb +1 -1
- data/lib/active_fedora/loadable_from_json.rb +12 -1
- data/lib/active_fedora/model_classifier.rb +1 -1
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_logger.rb +10 -0
- data/lib/active_fedora/orders/list_node.rb +2 -2
- data/lib/active_fedora/orders/ordered_list.rb +8 -4
- data/lib/active_fedora/orders/target_proxy.rb +4 -0
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/railtie.rb +2 -2
- data/lib/active_fedora/rake_support.rb +1 -1
- data/lib/active_fedora/rdf/field_map_entry.rb +6 -0
- data/lib/active_fedora/rdf/persistence.rb +1 -0
- data/lib/active_fedora/rdf/value_caster.rb +15 -0
- data/lib/active_fedora/rdf.rb +1 -1
- data/lib/active_fedora/relation/delegation.rb +4 -0
- data/lib/active_fedora/relation/finder_methods.rb +3 -1
- data/lib/active_fedora/solr_hit.rb +1 -14
- data/lib/active_fedora/solr_query_builder.rb +17 -13
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +1 -12
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
- data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +1 -1
- data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
- data/lib/tasks/active_fedora_dev.rake +1 -1
- data/spec/config_helper.rb +1 -1
- data/spec/integration/associations_spec.rb +23 -24
- data/spec/integration/attached_files_spec.rb +19 -9
- data/spec/integration/attributes_spec.rb +12 -16
- data/spec/integration/autosave_association_spec.rb +6 -6
- data/spec/integration/base_spec.rb +8 -8
- data/spec/integration/basic_contains_association_spec.rb +1 -1
- data/spec/integration/clean_connection_spec.rb +1 -1
- data/spec/integration/collection_association_spec.rb +2 -5
- data/spec/integration/date_time_properties_spec.rb +1 -17
- data/spec/integration/direct_container_spec.rb +12 -12
- data/spec/integration/directly_contains_one_association_spec.rb +11 -13
- data/spec/integration/eradicate_spec.rb +1 -1
- data/spec/integration/fedora_solr_sync_spec.rb +2 -2
- data/spec/integration/file_fixity_spec.rb +6 -8
- data/spec/integration/file_spec.rb +37 -39
- data/spec/integration/generators/solr_generator_spec.rb +7 -10
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +7 -7
- data/spec/integration/has_many_associations_spec.rb +9 -11
- data/spec/integration/indexing_spec.rb +2 -2
- data/spec/integration/indirect_container_spec.rb +11 -12
- data/spec/integration/json_serialization_spec.rb +4 -4
- data/spec/integration/query_result_builder_spec.rb +9 -21
- data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
- data/spec/integration/relation_delegation_spec.rb +8 -10
- data/spec/integration/relation_spec.rb +13 -16
- data/spec/integration/scoped_query_spec.rb +3 -3
- data/spec/integration/scoping_spec.rb +3 -3
- data/spec/integration/solr_hit_spec.rb +4 -15
- data/spec/integration/versionable_spec.rb +73 -327
- data/spec/integration/with_metadata_spec.rb +1 -1
- data/spec/spec_helper.rb +52 -10
- data/spec/unit/active_fedora_spec.rb +1 -1
- data/spec/unit/aggregation/list_source_spec.rb +37 -37
- data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
- data/spec/unit/association_hash_spec.rb +17 -31
- data/spec/unit/attached_files_spec.rb +35 -32
- data/spec/unit/attributes_spec.rb +25 -25
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_cma_spec.rb +1 -1
- data/spec/unit/base_extra_spec.rb +7 -22
- data/spec/unit/base_spec.rb +21 -27
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/unit/callback_spec.rb +2 -2
- data/spec/unit/change_set_spec.rb +5 -5
- data/spec/unit/checksum_spec.rb +2 -2
- data/spec/unit/code_configurator_spec.rb +1 -1
- data/spec/unit/core/fedora_id_translator_spec.rb +2 -2
- data/spec/unit/core/fedora_uri_translator_spec.rb +2 -2
- data/spec/unit/core/logger_spec.rb +18 -0
- data/spec/unit/core_spec.rb +68 -32
- data/spec/unit/default_model_mapper_spec.rb +6 -6
- data/spec/unit/fedora_spec.rb +3 -4
- data/spec/unit/file_configurator_spec.rb +96 -96
- data/spec/unit/file_path_builder_spec.rb +3 -3
- data/spec/unit/file_spec.rb +93 -61
- data/spec/unit/files_hash_spec.rb +9 -9
- data/spec/unit/filter_spec.rb +3 -3
- data/spec/unit/finder_methods_spec.rb +3 -3
- data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
- data/spec/unit/has_many_association_spec.rb +28 -13
- data/spec/unit/indexers/global_indexer_spec.rb +6 -6
- data/spec/unit/indexing_service_spec.rb +5 -5
- data/spec/unit/indexing_spec.rb +8 -8
- data/spec/unit/inheritance_spec.rb +11 -7
- data/spec/unit/loadable_from_json_spec.rb +4 -4
- data/spec/unit/logger_spec.rb +1 -1
- data/spec/unit/model_classifier_spec.rb +5 -5
- data/spec/unit/ordered_spec.rb +144 -147
- data/spec/unit/orders/list_node_spec.rb +22 -22
- data/spec/unit/orders/ordered_list_spec.rb +96 -96
- data/spec/unit/orders/reflection_spec.rb +4 -4
- data/spec/unit/pathing_spec.rb +4 -4
- data/spec/unit/persistence_spec.rb +28 -28
- data/spec/unit/property_spec.rb +2 -2
- data/spec/unit/query_spec.rb +12 -12
- data/spec/unit/rdf/indexing_service_spec.rb +29 -29
- data/spec/unit/readonly_spec.rb +5 -4
- data/spec/unit/reflection_spec.rb +3 -3
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
- data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
- data/spec/unit/serializers_spec.rb +3 -4
- data/spec/unit/solr_config_options_spec.rb +13 -16
- data/spec/unit/solr_hit_spec.rb +9 -9
- data/spec/unit/solr_service_spec.rb +4 -10
- data/spec/unit/sparql_insert_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +12 -12
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
- data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
- metadata +30 -130
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
- data/lib/active_fedora/datastreams.rb +0 -6
- data/lib/active_fedora/nom_datastream.rb +0 -73
- data/lib/active_fedora/om_datastream.rb +0 -118
- data/lib/active_fedora/profile_indexing_service.rb +0 -11
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
- data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf/rdf_datastream.rb +0 -167
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
- data/lib/active_fedora/solr_instance_loader.rb +0 -47
- data/solr/config/_rest_managed.json +0 -3
- data/solr/config/admin-extra.html +0 -31
- data/solr/config/elevate.xml +0 -36
- data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
- data/solr/config/protwords.txt +0 -21
- data/solr/config/schema.xml +0 -372
- data/solr/config/scripts.conf +0 -24
- data/solr/config/solrconfig.xml +0 -311
- data/solr/config/spellings.txt +0 -2
- data/solr/config/stopwords.txt +0 -58
- data/solr/config/stopwords_en.txt +0 -58
- data/solr/config/synonyms.txt +0 -31
- data/solr/config/xslt/example.xsl +0 -132
- data/solr/config/xslt/example_atom.xsl +0 -67
- data/solr/config/xslt/example_rss.xsl +0 -66
- data/solr/config/xslt/luke.xsl +0 -337
- data/spec/fixtures/damsObjectModel.xml +0 -38
- data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
- data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
- data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
- data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
- data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
- data/spec/integration/ntriples_datastream_spec.rb +0 -203
- data/spec/integration/om_datastream_spec.rb +0 -78
- data/spec/integration/solr_instance_loader_spec.rb +0 -156
- data/spec/samples/hydra-mods_article_datastream.rb +0 -517
- data/spec/samples/models/mods_article.rb +0 -9
- data/spec/samples/oral_history_sample.xml +0 -38
- data/spec/samples/oral_history_xml.xml +0 -35
- data/spec/samples/samples.rb +0 -2
- data/spec/unit/nom_datastream_spec.rb +0 -60
- data/spec/unit/ntriples_datastream_spec.rb +0 -170
- data/spec/unit/om_datastream_spec.rb +0 -294
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
- data/spec/unit/rdf_datastream_spec.rb +0 -84
- data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
- data/spec/unit/rdfxml_datastream_spec.rb +0 -106
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe ActiveFedora::Aggregation::ListSource do
|
|
4
|
-
subject { described_class.new }
|
|
4
|
+
subject(:list_source) { described_class.new }
|
|
5
5
|
|
|
6
6
|
describe "#head" do
|
|
7
7
|
it "is nil by default" do
|
|
8
|
-
expect(
|
|
8
|
+
expect(list_source.head).to eq nil
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "is settable" do
|
|
12
|
-
|
|
12
|
+
list_source.head = RDF::URI("test.org")
|
|
13
13
|
|
|
14
|
-
expect(
|
|
14
|
+
expect(list_source.head_id.first).to eq RDF::URI("test.org")
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "maps to IANA.first" do
|
|
18
|
-
expect(
|
|
18
|
+
expect(list_source.class.properties["head"].predicate).to eq ::RDF::Vocab::IANA["first"]
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe "#order_will_change!" do
|
|
23
23
|
it "marks it as changed" do
|
|
24
|
-
expect(
|
|
25
|
-
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
24
|
+
expect(list_source).not_to be_changed
|
|
25
|
+
list_source.order_will_change!
|
|
26
|
+
expect(list_source).to be_changed
|
|
27
|
+
expect(list_source.ordered_self).to be_changed
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
describe "#tail" do
|
|
32
32
|
it "is nil by default" do
|
|
33
|
-
expect(
|
|
33
|
+
expect(list_source.tail).to eq nil
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "is settable" do
|
|
37
|
-
|
|
37
|
+
list_source.tail = RDF::URI("test.org")
|
|
38
38
|
|
|
39
|
-
expect(
|
|
39
|
+
expect(list_source.tail_id.first).to eq RDF::URI("test.org")
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "maps to IANA.last" do
|
|
43
|
-
expect(
|
|
43
|
+
expect(list_source.class.properties["tail"].predicate).to eq ::RDF::Vocab::IANA["last"]
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
describe "#changed?" do
|
|
48
48
|
context "when nothing has changed" do
|
|
49
49
|
it "is false" do
|
|
50
|
-
expect(
|
|
50
|
+
expect(list_source).not_to be_changed
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
context "when the ordered list is changed" do
|
|
54
54
|
it "is true" do
|
|
55
|
-
allow(
|
|
55
|
+
allow(list_source.ordered_self).to receive(:changed?).and_return(true)
|
|
56
56
|
|
|
57
|
-
expect(
|
|
57
|
+
expect(list_source).to be_changed
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
context "when the ordered list is not changed" do
|
|
61
61
|
it "is false" do
|
|
62
|
-
allow(
|
|
62
|
+
allow(list_source.ordered_self).to receive(:changed?).and_return(false)
|
|
63
63
|
|
|
64
|
-
expect(
|
|
64
|
+
expect(list_source).not_to be_changed
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -69,50 +69,50 @@ RSpec.describe ActiveFedora::Aggregation::ListSource do
|
|
|
69
69
|
describe "#save" do
|
|
70
70
|
context "when nothing has changed" do
|
|
71
71
|
it "does not persist ordered_self" do
|
|
72
|
-
allow(
|
|
72
|
+
allow(list_source.ordered_self).to receive(:to_graph)
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
list_source.save
|
|
75
75
|
|
|
76
|
-
expect(
|
|
76
|
+
expect(list_source.ordered_self).not_to have_received(:to_graph)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
context "when attributes have changed, but not ordered list" do
|
|
80
80
|
it "does not persist ordered self" do
|
|
81
|
-
allow(
|
|
82
|
-
|
|
81
|
+
allow(list_source.ordered_self).to receive(:to_graph)
|
|
82
|
+
list_source.nodes += [RDF::URI("http://test.org")]
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
list_source.save
|
|
85
85
|
|
|
86
|
-
expect(
|
|
86
|
+
expect(list_source.ordered_self).not_to have_received(:to_graph)
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
context "when ordered list has changed" do
|
|
90
90
|
it "persists it" do
|
|
91
|
-
allow(
|
|
92
|
-
allow(
|
|
91
|
+
allow(list_source.ordered_self).to receive(:to_graph).and_call_original
|
|
92
|
+
allow(list_source.ordered_self).to receive(:changed?).and_return(true)
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
list_source.save
|
|
95
95
|
|
|
96
|
-
expect(
|
|
96
|
+
expect(list_source.ordered_self).to have_received(:to_graph)
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
describe "#serializable_hash" do
|
|
102
102
|
it "does not serialize nodes" do
|
|
103
|
-
|
|
103
|
+
list_source.nodes += [RDF::URI("http://test.org")]
|
|
104
104
|
|
|
105
|
-
expect(
|
|
105
|
+
expect(list_source.serializable_hash).not_to have_key "nodes"
|
|
106
106
|
end
|
|
107
107
|
it "does not serialize head" do
|
|
108
|
-
|
|
108
|
+
list_source.head = RDF::URI("http://test.org")
|
|
109
109
|
|
|
110
|
-
expect(
|
|
110
|
+
expect(list_source.serializable_hash).not_to have_key "head"
|
|
111
111
|
end
|
|
112
112
|
it "does not serialize tail" do
|
|
113
|
-
|
|
113
|
+
list_source.tail = RDF::URI("http://test.org")
|
|
114
114
|
|
|
115
|
-
expect(
|
|
115
|
+
expect(list_source.serializable_hash).not_to have_key "tail"
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -127,8 +127,8 @@ RSpec.describe ActiveFedora::Aggregation::ListSource do
|
|
|
127
127
|
it "can index" do
|
|
128
128
|
m = Member.create
|
|
129
129
|
proxy_in = RDF::URI(ActiveFedora::Base.translate_id_to_uri.call("banana"))
|
|
130
|
-
|
|
131
|
-
expect(
|
|
130
|
+
list_source.ordered_self.append_target m, proxy_in: proxy_in
|
|
131
|
+
expect(list_source.to_solr).to include ordered_targets_ssim: [m.id], proxy_in_ssi: "banana"
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe ActiveFedora::Aggregation::OrderedReader do
|
|
4
|
-
subject { described_class.new(root) }
|
|
4
|
+
subject(:ordered_reader) { described_class.new(root) }
|
|
5
5
|
let(:root) { instance_double(ActiveFedora::Aggregation::ListSource) }
|
|
6
6
|
|
|
7
7
|
describe "#each" do
|
|
@@ -10,14 +10,14 @@ RSpec.describe ActiveFedora::Aggregation::OrderedReader do
|
|
|
10
10
|
tail = build_node(prev_node: head)
|
|
11
11
|
allow(head).to receive(:next).and_return(tail)
|
|
12
12
|
allow(root).to receive(:head).and_return(head)
|
|
13
|
-
expect(
|
|
13
|
+
expect(ordered_reader.to_a).to eq [head, tail]
|
|
14
14
|
end
|
|
15
15
|
it "only goes as deep as necessary" do
|
|
16
16
|
head = build_node
|
|
17
17
|
tail = build_node(prev_node: head)
|
|
18
18
|
allow(head).to receive(:next).and_return(tail)
|
|
19
19
|
allow(root).to receive(:head).and_return(head)
|
|
20
|
-
expect(
|
|
20
|
+
expect(ordered_reader.first).to eq head
|
|
21
21
|
expect(head).not_to have_received(:next)
|
|
22
22
|
end
|
|
23
23
|
context "when the prev is wrong" do
|
|
@@ -28,7 +28,7 @@ RSpec.describe ActiveFedora::Aggregation::OrderedReader do
|
|
|
28
28
|
allow(head).to receive(:next).and_return(tail)
|
|
29
29
|
allow(root).to receive(:head).and_return(head)
|
|
30
30
|
allow(tail).to receive(:prev=)
|
|
31
|
-
expect(
|
|
31
|
+
expect(ordered_reader.to_a).to eq [head, tail]
|
|
32
32
|
expect(tail).to have_received(:prev=).with(head)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -1,78 +1,64 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::AssociationHash do
|
|
4
|
-
subject { described_class.new(model, reflections) }
|
|
4
|
+
subject(:association_hash) { described_class.new(model, reflections) }
|
|
5
5
|
|
|
6
|
-
let(:model) {
|
|
7
|
-
let(:reflections) {
|
|
6
|
+
let(:model) { instance_double(ActiveFedora::Base, association: nil) }
|
|
7
|
+
let(:reflections) { { foo: association } }
|
|
8
8
|
let(:reader) { double("reader") }
|
|
9
9
|
let(:writer) { double("writer") }
|
|
10
10
|
let(:association) { double(reader: reader, writer: writer) }
|
|
11
11
|
|
|
12
|
+
before do
|
|
13
|
+
allow(model).to receive(:association).with(:foo).and_return(association)
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
describe "key reader" do
|
|
13
17
|
describe "when the association exists" do
|
|
14
|
-
before do
|
|
15
|
-
allow(subject).to receive(:association).with("foo") { association }
|
|
16
|
-
end
|
|
17
18
|
it "calls the association reader" do
|
|
18
|
-
expect(
|
|
19
|
+
expect(association_hash["foo"]).to eq(reader)
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
22
|
describe "when the association does not exist" do
|
|
22
|
-
before do
|
|
23
|
-
allow(subject).to receive(:association).with("foo") { nil }
|
|
24
|
-
end
|
|
25
23
|
it "returns nil" do
|
|
26
|
-
expect(
|
|
24
|
+
expect(association_hash["bar"]).to be_nil
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
end
|
|
30
28
|
|
|
31
29
|
describe "key setter" do
|
|
32
30
|
let(:obj) { double }
|
|
33
|
-
before do
|
|
34
|
-
allow(association).to receive(:writer).with(obj) { writer }
|
|
35
|
-
end
|
|
36
31
|
describe "when the association exists" do
|
|
37
|
-
before do
|
|
38
|
-
allow(subject).to receive(:association).with("foo") { association }
|
|
39
|
-
end
|
|
40
32
|
it "calls the association writer" do
|
|
41
33
|
expect(association).to receive(:writer).with(obj)
|
|
42
|
-
|
|
34
|
+
association_hash["foo"] = obj
|
|
43
35
|
end
|
|
44
36
|
end
|
|
45
37
|
describe "when the association does not exist" do
|
|
46
|
-
before do
|
|
47
|
-
allow(subject).to receive(:association).with("foo") { nil }
|
|
48
|
-
end
|
|
49
38
|
it "doesn't call the association writer" do
|
|
50
39
|
expect(association).not_to receive(:writer).with(obj)
|
|
51
|
-
|
|
40
|
+
association_hash["bar"] = obj
|
|
52
41
|
end
|
|
53
42
|
end
|
|
54
43
|
end
|
|
55
44
|
|
|
56
45
|
describe "#association" do
|
|
57
|
-
before do
|
|
58
|
-
allow(model).to receive(:association).with(:foo) { association }
|
|
59
|
-
end
|
|
60
46
|
it "works with a string key" do
|
|
61
|
-
expect(
|
|
47
|
+
expect(association_hash.association("foo")).to eq(association)
|
|
62
48
|
end
|
|
63
49
|
it "works with a symbol key" do
|
|
64
|
-
expect(
|
|
50
|
+
expect(association_hash.association(:foo)).to eq(association)
|
|
65
51
|
end
|
|
66
52
|
end
|
|
67
53
|
|
|
68
54
|
describe "#key?" do
|
|
69
55
|
it "works with a string" do
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
56
|
+
expect(association_hash.key?("foo")).to be true
|
|
57
|
+
expect(association_hash.key?("bar")).to be false
|
|
72
58
|
end
|
|
73
59
|
it "works with a symbol" do
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
60
|
+
expect(association_hash.key?(:foo)).to be true
|
|
61
|
+
expect(association_hash.key?(:bar)).to be false
|
|
76
62
|
end
|
|
77
63
|
end
|
|
78
64
|
end
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::AttachedFiles do
|
|
4
|
-
subject { ActiveFedora::Base.new }
|
|
4
|
+
subject(:af_base) { ActiveFedora::Base.new }
|
|
5
5
|
describe "has_subresource" do
|
|
6
6
|
before do
|
|
7
|
-
class
|
|
7
|
+
class Sample1 < ActiveFedora::File
|
|
8
|
+
end
|
|
9
|
+
class Sample2 < ActiveFedora::File
|
|
8
10
|
end
|
|
9
11
|
class FooHistory < ActiveFedora::Base
|
|
10
|
-
has_subresource 'dsid', class_name: '
|
|
11
|
-
has_subresource 'complex_ds', autocreate: true, class_name: '
|
|
12
|
+
has_subresource 'dsid', class_name: 'Sample2'
|
|
13
|
+
has_subresource 'complex_ds', autocreate: true, class_name: 'Sample1'
|
|
12
14
|
has_subresource 'thumbnail'
|
|
13
15
|
has_subresource 'child_resource', class_name: 'ActiveFedora::Base'
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
after do
|
|
17
|
-
Object.send(:remove_const, :
|
|
19
|
+
Object.send(:remove_const, :Sample1)
|
|
20
|
+
Object.send(:remove_const, :Sample2)
|
|
18
21
|
Object.send(:remove_const, :FooHistory)
|
|
19
22
|
end
|
|
20
23
|
|
|
@@ -26,12 +29,12 @@ describe ActiveFedora::AttachedFiles do
|
|
|
26
29
|
|
|
27
30
|
it "lets you override defaults" do
|
|
28
31
|
expect(FooHistory.child_resource_reflections[:complex_ds].options).to include(autocreate: true)
|
|
29
|
-
expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq '
|
|
32
|
+
expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Sample1'
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
it "raises an error if you don't give a dsid" do
|
|
33
|
-
expect { FooHistory.has_subresource nil, type:
|
|
34
|
-
|
|
36
|
+
expect { FooHistory.has_subresource nil, type: Sample2 }.to raise_error ArgumentError,
|
|
37
|
+
"You must provide a path name (f.k.a. dsid) for the resource"
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
|
|
@@ -96,38 +99,38 @@ describe ActiveFedora::AttachedFiles do
|
|
|
96
99
|
|
|
97
100
|
describe "#serialize_attached_files" do
|
|
98
101
|
it "touches each file" do
|
|
99
|
-
m1 =
|
|
100
|
-
m2 =
|
|
102
|
+
m1 = instance_double(ActiveFedora::File)
|
|
103
|
+
m2 = instance_double(ActiveFedora::File)
|
|
101
104
|
|
|
102
105
|
expect(m1).to receive(:serialize!)
|
|
103
106
|
expect(m2).to receive(:serialize!)
|
|
104
|
-
allow(
|
|
105
|
-
|
|
107
|
+
allow(af_base).to receive(:declared_attached_files).and_return(m1: m1, m2: m2)
|
|
108
|
+
af_base.serialize_attached_files
|
|
106
109
|
end
|
|
107
110
|
end
|
|
108
111
|
|
|
109
112
|
describe "#accessor_name" do
|
|
110
113
|
it "uses the name" do
|
|
111
|
-
expect(
|
|
114
|
+
expect(af_base.send(:accessor_name, 'abc')).to eq 'abc'
|
|
112
115
|
end
|
|
113
116
|
|
|
114
117
|
it "uses the name" do
|
|
115
|
-
expect(
|
|
118
|
+
expect(af_base.send(:accessor_name, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
|
|
116
119
|
end
|
|
117
120
|
|
|
118
121
|
it "uses the name" do
|
|
119
|
-
expect(
|
|
122
|
+
expect(af_base.send(:accessor_name, 'descMetadata')).to eq 'descMetadata'
|
|
120
123
|
end
|
|
121
124
|
|
|
122
125
|
it "hash-erizes underscores" do
|
|
123
|
-
expect(
|
|
126
|
+
expect(af_base.send(:accessor_name, 'a-b')).to eq 'a_b'
|
|
124
127
|
end
|
|
125
128
|
end
|
|
126
129
|
|
|
127
130
|
describe "#attached_files" do
|
|
128
131
|
it "returns the datastream hash proxy" do
|
|
129
|
-
allow(
|
|
130
|
-
expect(
|
|
132
|
+
allow(af_base).to receive(:load_datastreams)
|
|
133
|
+
expect(af_base.attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
|
|
131
134
|
end
|
|
132
135
|
end
|
|
133
136
|
|
|
@@ -136,37 +139,37 @@ describe ActiveFedora::AttachedFiles do
|
|
|
136
139
|
|
|
137
140
|
it "does not call save on the file" do
|
|
138
141
|
expect(file).to receive(:save).never
|
|
139
|
-
|
|
142
|
+
af_base.attach_file(file, 'part1')
|
|
140
143
|
end
|
|
141
144
|
|
|
142
145
|
it "adds the file to the attached_files hash" do
|
|
143
146
|
expect {
|
|
144
|
-
|
|
145
|
-
}.to change {
|
|
147
|
+
af_base.attach_file(file, 'part1')
|
|
148
|
+
}.to change { af_base.attached_files.key?(:part1) }.from(false).to(true)
|
|
146
149
|
end
|
|
147
150
|
|
|
148
151
|
context "after attaching the file" do
|
|
149
152
|
let(:dsid) { 'Abc' }
|
|
150
153
|
before do
|
|
151
|
-
|
|
154
|
+
af_base.attach_file(file, dsid)
|
|
152
155
|
end
|
|
153
156
|
|
|
154
157
|
it "adds the datastream to the object" do
|
|
155
|
-
expect(
|
|
158
|
+
expect(af_base.attached_files['Abc']).to eq file
|
|
156
159
|
end
|
|
157
160
|
|
|
158
161
|
describe "dynamic accessors" do
|
|
159
162
|
context "when the file is named with dash" do
|
|
160
163
|
let(:dsid) { 'eac-cpf' }
|
|
161
164
|
it "converts dashes to underscores" do
|
|
162
|
-
expect(
|
|
165
|
+
expect(af_base.eac_cpf).to eq file
|
|
163
166
|
end
|
|
164
167
|
end
|
|
165
168
|
|
|
166
169
|
context "when the file is named with underscore" do
|
|
167
170
|
let(:dsid) { 'foo_bar' }
|
|
168
171
|
it "preserves the underscore" do
|
|
169
|
-
expect(
|
|
172
|
+
expect(af_base.foo_bar).to eq file
|
|
170
173
|
end
|
|
171
174
|
end
|
|
172
175
|
end
|
|
@@ -175,13 +178,13 @@ describe ActiveFedora::AttachedFiles do
|
|
|
175
178
|
|
|
176
179
|
describe "#metadata_streams" do
|
|
177
180
|
it "only is metadata datastreams" do
|
|
178
|
-
ds1 =
|
|
179
|
-
ds2 =
|
|
180
|
-
ds3 =
|
|
181
|
-
file_ds =
|
|
182
|
-
allow(
|
|
183
|
-
expect(
|
|
184
|
-
expect(
|
|
181
|
+
ds1 = instance_double(ActiveFedora::File, metadata?: true)
|
|
182
|
+
ds2 = instance_double(ActiveFedora::File, metadata?: true)
|
|
183
|
+
ds3 = instance_double(ActiveFedora::File, metadata?: true)
|
|
184
|
+
file_ds = instance_double(ActiveFedora::File, metadata?: false)
|
|
185
|
+
allow(af_base).to receive(:attached_files).and_return(a: ds1, b: ds2, c: ds3, e: file_ds)
|
|
186
|
+
expect(af_base.metadata_streams).to include(ds1, ds2, ds3)
|
|
187
|
+
expect(af_base.metadata_streams).to_not include(file_ds)
|
|
185
188
|
end
|
|
186
189
|
end
|
|
187
190
|
end
|
|
@@ -16,12 +16,12 @@ describe ActiveFedora::Base do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
let(:obj) { BarHistory4.new(title: ['test1']) }
|
|
19
|
-
subject { obj }
|
|
19
|
+
subject(:history) { obj }
|
|
20
20
|
|
|
21
21
|
describe "#attribute_names" do
|
|
22
22
|
context "on an instance" do
|
|
23
23
|
it "lists the attributes" do
|
|
24
|
-
expect(
|
|
24
|
+
expect(history.attribute_names).to eq ["title", "abstract"]
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -34,21 +34,21 @@ describe ActiveFedora::Base do
|
|
|
34
34
|
|
|
35
35
|
describe "#inspect" do
|
|
36
36
|
it "shows the attributes" do
|
|
37
|
-
expect(
|
|
37
|
+
expect(history.inspect).to eq "#<BarHistory4 id: nil, title: [\"test1\"], abstract: nil>"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
describe "with a id" do
|
|
41
|
-
before { allow(
|
|
41
|
+
before { allow(history).to receive(:id).and_return('test:123') }
|
|
42
42
|
|
|
43
43
|
it "shows a id" do
|
|
44
|
-
expect(
|
|
44
|
+
expect(history.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
describe "with no attributes" do
|
|
49
|
-
subject { described_class.new }
|
|
49
|
+
subject(:object) { described_class.new }
|
|
50
50
|
it "shows a id" do
|
|
51
|
-
expect(
|
|
51
|
+
expect(object.inspect).to eq "#<ActiveFedora::Base id: nil>"
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -57,18 +57,18 @@ describe ActiveFedora::Base do
|
|
|
57
57
|
class BarHistory2 < BarHistory4
|
|
58
58
|
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent, class_name: 'BarHistory4'
|
|
59
59
|
end
|
|
60
|
-
|
|
60
|
+
history.library = library
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
let(:library) { BarHistory4.create }
|
|
64
|
-
subject { BarHistory2.new }
|
|
64
|
+
subject(:history) { BarHistory2.new }
|
|
65
65
|
|
|
66
66
|
after do
|
|
67
67
|
Object.send(:remove_const, :BarHistory2)
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "shows the library_id" do
|
|
71
|
-
expect(
|
|
71
|
+
expect(history.inspect).to eq "#<BarHistory2 id: nil, title: [], abstract: nil, library_id: \"#{library.id}\">"
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -83,36 +83,36 @@ describe ActiveFedora::Base do
|
|
|
83
83
|
describe "accessing attributes" do
|
|
84
84
|
context "using generated methods" do
|
|
85
85
|
it "returns values" do
|
|
86
|
-
expect(
|
|
86
|
+
expect(history.title).to eq ['test1']
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
context "using hash accessors" do
|
|
91
91
|
context "on single value fields" do
|
|
92
92
|
it "has a default value" do
|
|
93
|
-
expect(
|
|
93
|
+
expect(history[:abstract]).to be_nil
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
context "when there are two assertions for the predicate" do
|
|
97
97
|
before do
|
|
98
|
-
|
|
98
|
+
history.resource[:abstract] = ['foo', 'bar']
|
|
99
99
|
end
|
|
100
100
|
it "raises an error if just returning the first value would cause data loss" do
|
|
101
|
-
expect {
|
|
101
|
+
expect { history[:abstract] }.to raise_error ActiveFedora::ConstraintError, "Expected \"abstract\" to have 0-1 statements, but there are 2"
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
context "multiple values" do
|
|
107
107
|
it "returns values" do
|
|
108
|
-
expect(
|
|
108
|
+
expect(history[:title]).to eq ['test1']
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
context "on Fedora attributes" do
|
|
113
113
|
it "return values" do
|
|
114
|
-
expect(
|
|
115
|
-
expect(
|
|
114
|
+
expect(history[:type]).to be_empty
|
|
115
|
+
expect(history[:rdf_label]).to contain_exactly("test1")
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
end
|
|
@@ -121,8 +121,8 @@ describe ActiveFedora::Base do
|
|
|
121
121
|
describe 'change tracking' do
|
|
122
122
|
it "is able to track change status" do
|
|
123
123
|
expect {
|
|
124
|
-
|
|
125
|
-
}.to change {
|
|
124
|
+
history.abstract = "Moo"
|
|
125
|
+
}.to change { history.abstract_changed? }.from(false).to(true)
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
128
|
|
|
@@ -136,16 +136,16 @@ describe ActiveFedora::Base do
|
|
|
136
136
|
|
|
137
137
|
describe "when an object of the wrong cardinality is set" do
|
|
138
138
|
it "does not allow passing a string to a multiple property writer" do
|
|
139
|
-
expect {
|
|
140
|
-
expect {
|
|
141
|
-
expect {
|
|
139
|
+
expect { history.title = "Quack" }.to raise_error ArgumentError
|
|
140
|
+
expect { history.title = ["Quack"] }.not_to raise_error
|
|
141
|
+
expect { history.title = nil }.not_to raise_error
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
it "does not allow an enumerable to a unique attribute writer" do
|
|
145
|
-
expect {
|
|
146
|
-
expect {
|
|
145
|
+
expect { history.abstract = "Low" }.not_to raise_error
|
|
146
|
+
expect { history.abstract = ["Low"]
|
|
147
147
|
}.to raise_error ArgumentError, "You attempted to set the property `abstract' to an enumerable value. However, this property is declared as singular."
|
|
148
|
-
expect {
|
|
148
|
+
expect { history.abstract = nil }.not_to raise_error
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
end
|
|
@@ -6,22 +6,22 @@ describe ActiveFedora::Base do
|
|
|
6
6
|
property :fubar, predicate: ::RDF::URI('http://example.com/fubar'), multiple: false
|
|
7
7
|
property :duck, predicate: ::RDF::URI('http://example.com/duck'), multiple: false
|
|
8
8
|
end
|
|
9
|
-
subject { BarHistory.new }
|
|
9
|
+
subject(:history) { BarHistory.new }
|
|
10
10
|
|
|
11
11
|
describe "attributes=" do
|
|
12
12
|
it "sets attributes" do
|
|
13
|
-
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
13
|
+
history.attributes = { fubar: "baz", duck: "Quack" }
|
|
14
|
+
expect(history.fubar).to eq "baz"
|
|
15
|
+
expect(history.duck).to eq "Quack"
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
describe "update_attributes" do
|
|
20
20
|
it "sets attributes and save" do
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
21
|
+
history.update_attributes(fubar: "baz", duck: "Quack")
|
|
22
|
+
history.reload
|
|
23
|
+
expect(history.fubar).to eq "baz"
|
|
24
|
+
expect(history.duck).to eq "Quack"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|