active-fedora 10.0.0 → 11.0.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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -7
  4. data/.rubocop_todo.yml +55 -0
  5. data/.solr_wrapper +6 -0
  6. data/README.md +1 -3
  7. data/active-fedora.gemspec +6 -11
  8. data/lib/active_fedora/aggregation/list_source.rb +2 -0
  9. data/lib/active_fedora/associations/association_scope.rb +1 -1
  10. data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
  11. data/lib/active_fedora/associations/builder/association.rb +1 -1
  12. data/lib/active_fedora/associations/builder/orders.rb +11 -3
  13. data/lib/active_fedora/associations/collection_association.rb +3 -3
  14. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  15. data/lib/active_fedora/associations/has_many_association.rb +2 -2
  16. data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
  17. data/lib/active_fedora/associations/orders_association.rb +4 -0
  18. data/lib/active_fedora/associations/rdf.rb +2 -0
  19. data/lib/active_fedora/attribute_assignment.rb +0 -1
  20. data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
  21. data/lib/active_fedora/attributes.rb +1 -1
  22. data/lib/active_fedora/base.rb +4 -8
  23. data/lib/active_fedora/change_set.rb +6 -2
  24. data/lib/active_fedora/containers/container.rb +1 -1
  25. data/lib/active_fedora/core.rb +22 -25
  26. data/lib/active_fedora/fedora_attributes.rb +1 -1
  27. data/lib/active_fedora/file/streaming.rb +1 -1
  28. data/lib/active_fedora/file.rb +1 -9
  29. data/lib/active_fedora/indexing.rb +0 -15
  30. data/lib/active_fedora/indexing_service.rb +0 -9
  31. data/lib/active_fedora/loadable_from_json.rb +12 -1
  32. data/lib/active_fedora/nested_attributes.rb +2 -2
  33. data/lib/active_fedora/orders/list_node.rb +2 -2
  34. data/lib/active_fedora/orders/ordered_list.rb +7 -3
  35. data/lib/active_fedora/orders/target_proxy.rb +4 -0
  36. data/lib/active_fedora/querying.rb +1 -1
  37. data/lib/active_fedora/railtie.rb +2 -2
  38. data/lib/active_fedora/rake_support.rb +1 -1
  39. data/lib/active_fedora/rdf/persistence.rb +1 -0
  40. data/lib/active_fedora/rdf.rb +0 -2
  41. data/lib/active_fedora/relation/delegation.rb +4 -0
  42. data/lib/active_fedora/relation/finder_methods.rb +3 -3
  43. data/lib/active_fedora/scoping/named.rb +1 -0
  44. data/lib/active_fedora/solr_hit.rb +0 -13
  45. data/lib/active_fedora/solr_query_builder.rb +24 -13
  46. data/lib/active_fedora/version.rb +1 -1
  47. data/lib/active_fedora.rb +0 -12
  48. data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
  49. data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
  50. data/lib/generators/active_fedora/model/model_generator.rb +1 -1
  51. data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
  52. data/lib/tasks/active_fedora_dev.rake +1 -9
  53. data/spec/config_helper.rb +1 -1
  54. data/spec/integration/associations_spec.rb +23 -24
  55. data/spec/integration/attached_files_spec.rb +18 -8
  56. data/spec/integration/attributes_spec.rb +12 -16
  57. data/spec/integration/autosave_association_spec.rb +6 -6
  58. data/spec/integration/base_spec.rb +3 -3
  59. data/spec/integration/basic_contains_association_spec.rb +1 -1
  60. data/spec/integration/clean_connection_spec.rb +1 -1
  61. data/spec/integration/collection_association_spec.rb +2 -5
  62. data/spec/integration/date_time_properties_spec.rb +1 -16
  63. data/spec/integration/direct_container_spec.rb +12 -12
  64. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  65. data/spec/integration/eradicate_spec.rb +1 -1
  66. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  67. data/spec/integration/file_fixity_spec.rb +6 -8
  68. data/spec/integration/file_spec.rb +32 -34
  69. data/spec/integration/generators/solr_generator_spec.rb +7 -10
  70. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
  71. data/spec/integration/has_many_associations_spec.rb +9 -11
  72. data/spec/integration/indexing_spec.rb +2 -2
  73. data/spec/integration/indirect_container_spec.rb +11 -12
  74. data/spec/integration/json_serialization_spec.rb +4 -4
  75. data/spec/integration/query_result_builder_spec.rb +9 -21
  76. data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
  77. data/spec/integration/relation_delegation_spec.rb +8 -10
  78. data/spec/integration/relation_spec.rb +13 -16
  79. data/spec/integration/scoped_query_spec.rb +4 -3
  80. data/spec/integration/solr_hit_spec.rb +4 -15
  81. data/spec/integration/versionable_spec.rb +73 -327
  82. data/spec/integration/with_metadata_spec.rb +1 -1
  83. data/spec/spec_helper.rb +52 -4
  84. data/spec/unit/active_fedora_spec.rb +1 -1
  85. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  86. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  87. data/spec/unit/association_hash_spec.rb +17 -31
  88. data/spec/unit/attached_files_spec.rb +35 -32
  89. data/spec/unit/attributes_spec.rb +25 -25
  90. data/spec/unit/base_active_model_spec.rb +8 -8
  91. data/spec/unit/base_cma_spec.rb +1 -1
  92. data/spec/unit/base_extra_spec.rb +7 -22
  93. data/spec/unit/base_spec.rb +16 -22
  94. data/spec/unit/callback_spec.rb +2 -2
  95. data/spec/unit/change_set_spec.rb +5 -5
  96. data/spec/unit/checksum_spec.rb +2 -2
  97. data/spec/unit/code_configurator_spec.rb +1 -1
  98. data/spec/unit/core_spec.rb +62 -26
  99. data/spec/unit/default_model_mapper_spec.rb +6 -6
  100. data/spec/unit/fedora_spec.rb +3 -4
  101. data/spec/unit/file_configurator_spec.rb +96 -96
  102. data/spec/unit/file_path_builder_spec.rb +1 -1
  103. data/spec/unit/file_spec.rb +61 -61
  104. data/spec/unit/files_hash_spec.rb +9 -9
  105. data/spec/unit/filter_spec.rb +3 -3
  106. data/spec/unit/finder_methods_spec.rb +5 -5
  107. data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
  108. data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
  109. data/spec/unit/has_many_association_spec.rb +28 -13
  110. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  111. data/spec/unit/indexing_service_spec.rb +5 -5
  112. data/spec/unit/indexing_spec.rb +6 -6
  113. data/spec/unit/inheritance_spec.rb +11 -7
  114. data/spec/unit/loadable_from_json_spec.rb +4 -4
  115. data/spec/unit/logger_spec.rb +1 -1
  116. data/spec/unit/model_classifier_spec.rb +5 -5
  117. data/spec/unit/ordered_spec.rb +144 -146
  118. data/spec/unit/orders/list_node_spec.rb +22 -22
  119. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  120. data/spec/unit/orders/reflection_spec.rb +4 -4
  121. data/spec/unit/pathing_spec.rb +4 -4
  122. data/spec/unit/persistence_spec.rb +28 -28
  123. data/spec/unit/property_spec.rb +2 -2
  124. data/spec/unit/query_spec.rb +20 -20
  125. data/spec/unit/rdf/indexing_service_spec.rb +29 -29
  126. data/spec/unit/readonly_spec.rb +5 -4
  127. data/spec/unit/reflection_spec.rb +3 -3
  128. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  129. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  130. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  131. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  132. data/spec/unit/serializers_spec.rb +3 -4
  133. data/spec/unit/solr_config_options_spec.rb +13 -16
  134. data/spec/unit/solr_hit_spec.rb +9 -9
  135. data/spec/unit/solr_service_spec.rb +4 -10
  136. data/spec/unit/sparql_insert_spec.rb +2 -2
  137. data/spec/unit/validations_spec.rb +9 -9
  138. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  139. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  140. metadata +18 -122
  141. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  142. data/lib/active_fedora/datastreams.rb +0 -6
  143. data/lib/active_fedora/nom_datastream.rb +0 -67
  144. data/lib/active_fedora/om_datastream.rb +0 -126
  145. data/lib/active_fedora/profile_indexing_service.rb +0 -11
  146. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  147. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -43
  148. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -9
  149. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -158
  150. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  151. data/lib/active_fedora/solr_instance_loader.rb +0 -47
  152. data/solr/config/_rest_managed.json +0 -3
  153. data/solr/config/admin-extra.html +0 -31
  154. data/solr/config/elevate.xml +0 -36
  155. data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
  156. data/solr/config/protwords.txt +0 -21
  157. data/solr/config/schema.xml +0 -372
  158. data/solr/config/scripts.conf +0 -24
  159. data/solr/config/solrconfig.xml +0 -311
  160. data/solr/config/spellings.txt +0 -2
  161. data/solr/config/stopwords.txt +0 -58
  162. data/solr/config/stopwords_en.txt +0 -58
  163. data/solr/config/synonyms.txt +0 -31
  164. data/solr/config/xslt/example.xsl +0 -132
  165. data/solr/config/xslt/example_atom.xsl +0 -67
  166. data/solr/config/xslt/example_rss.xsl +0 -66
  167. data/solr/config/xslt/luke.xsl +0 -337
  168. data/spec/fixtures/damsObjectModel.xml +0 -38
  169. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  170. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  171. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  172. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  173. data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
  174. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
  175. data/spec/integration/ntriples_datastream_spec.rb +0 -203
  176. data/spec/integration/om_datastream_spec.rb +0 -78
  177. data/spec/integration/solr_instance_loader_spec.rb +0 -155
  178. data/spec/samples/hydra-mods_article_datastream.rb +0 -517
  179. data/spec/samples/models/mods_article.rb +0 -9
  180. data/spec/samples/oral_history_sample.xml +0 -38
  181. data/spec/samples/oral_history_xml.xml +0 -35
  182. data/spec/samples/samples.rb +0 -2
  183. data/spec/unit/nom_datastream_spec.rb +0 -60
  184. data/spec/unit/ntriples_datastream_spec.rb +0 -170
  185. data/spec/unit/om_datastream_spec.rb +0 -325
  186. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  187. data/spec/unit/rdf_datastream_spec.rb +0 -84
  188. data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
  189. 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(subject.head).to eq nil
8
+ expect(list_source.head).to eq nil
9
9
  end
10
10
 
11
11
  it "is settable" do
12
- subject.head = RDF::URI("test.org")
12
+ list_source.head = RDF::URI("test.org")
13
13
 
14
- expect(subject.head_id.first).to eq RDF::URI("test.org")
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(subject.class.properties["head"].predicate).to eq ::RDF::Vocab::IANA["first"]
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(subject).not_to be_changed
25
- subject.order_will_change!
26
- expect(subject).to be_changed
27
- expect(subject.ordered_self).to be_changed
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(subject.tail).to eq nil
33
+ expect(list_source.tail).to eq nil
34
34
  end
35
35
 
36
36
  it "is settable" do
37
- subject.tail = RDF::URI("test.org")
37
+ list_source.tail = RDF::URI("test.org")
38
38
 
39
- expect(subject.tail_id.first).to eq RDF::URI("test.org")
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(subject.class.properties["tail"].predicate).to eq ::RDF::Vocab::IANA["last"]
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(subject).not_to be_changed
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(subject.ordered_self).to receive(:changed?).and_return(true)
55
+ allow(list_source.ordered_self).to receive(:changed?).and_return(true)
56
56
 
57
- expect(subject).to be_changed
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(subject.ordered_self).to receive(:changed?).and_return(false)
62
+ allow(list_source.ordered_self).to receive(:changed?).and_return(false)
63
63
 
64
- expect(subject).not_to be_changed
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(subject.ordered_self).to receive(:to_graph)
72
+ allow(list_source.ordered_self).to receive(:to_graph)
73
73
 
74
- subject.save
74
+ list_source.save
75
75
 
76
- expect(subject.ordered_self).not_to have_received(:to_graph)
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(subject.ordered_self).to receive(:to_graph)
82
- subject.nodes += [RDF::URI("http://test.org")]
81
+ allow(list_source.ordered_self).to receive(:to_graph)
82
+ list_source.nodes += [RDF::URI("http://test.org")]
83
83
 
84
- subject.save
84
+ list_source.save
85
85
 
86
- expect(subject.ordered_self).not_to have_received(:to_graph)
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(subject.ordered_self).to receive(:to_graph).and_call_original
92
- allow(subject.ordered_self).to receive(:changed?).and_return(true)
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
- subject.save
94
+ list_source.save
95
95
 
96
- expect(subject.ordered_self).to have_received(:to_graph)
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
- subject.nodes += [RDF::URI("http://test.org")]
103
+ list_source.nodes += [RDF::URI("http://test.org")]
104
104
 
105
- expect(subject.serializable_hash).not_to have_key "nodes"
105
+ expect(list_source.serializable_hash).not_to have_key "nodes"
106
106
  end
107
107
  it "does not serialize head" do
108
- subject.head = RDF::URI("http://test.org")
108
+ list_source.head = RDF::URI("http://test.org")
109
109
 
110
- expect(subject.serializable_hash).not_to have_key "head"
110
+ expect(list_source.serializable_hash).not_to have_key "head"
111
111
  end
112
112
  it "does not serialize tail" do
113
- subject.tail = RDF::URI("http://test.org")
113
+ list_source.tail = RDF::URI("http://test.org")
114
114
 
115
- expect(subject.serializable_hash).not_to have_key "tail"
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
- subject.ordered_self.append_target m, proxy_in: proxy_in
131
- expect(subject.to_solr).to include ordered_targets_ssim: [m.id], proxy_in_ssi: "banana"
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(subject.to_a).to eq [head, tail]
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(subject.first).to eq head
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(subject.to_a).to eq [head, tail]
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) { double(association: nil) }
7
- let(:reflections) { double(keys: [:foo]) }
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(subject["foo"]).to eq(reader)
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(subject["foo"]).to be_nil
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
- subject["foo"] = obj
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
- subject["foo"] = obj
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(subject.association("foo")).to eq(association)
47
+ expect(association_hash.association("foo")).to eq(association)
62
48
  end
63
49
  it "works with a symbol key" do
64
- expect(subject.association(:foo)).to eq(association)
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(subject.key?("foo")).to be true
71
- expect(subject.key?("bar")).to be false
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(subject.key?(:foo)).to be true
75
- expect(subject.key?(:bar)).to be false
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 Z < ActiveFedora::File
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: 'ActiveFedora::QualifiedDublinCoreDatastream'
11
- has_subresource 'complex_ds', autocreate: true, class_name: 'Z'
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, :Z)
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 'Z'
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: ActiveFedora::QualifiedDublinCoreDatastream }.to raise_error ArgumentError,
34
- "You must provide a path name (f.k.a. dsid) for the resource"
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 = double
100
- m2 = double
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(subject).to receive(:declared_attached_files).and_return(m1: m1, m2: m2)
105
- subject.serialize_attached_files
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(subject.send(:accessor_name, 'abc')).to eq 'abc'
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(subject.send(:accessor_name, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
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(subject.send(:accessor_name, 'descMetadata')).to eq 'descMetadata'
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(subject.send(:accessor_name, 'a-b')).to eq 'a_b'
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(subject).to receive(:load_datastreams)
130
- expect(subject.attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
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
- subject.attach_file(file, 'part1')
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
- subject.attach_file(file, 'part1')
145
- }.to change { subject.attached_files.key?(:part1) }.from(false).to(true)
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
- subject.attach_file(file, dsid)
154
+ af_base.attach_file(file, dsid)
152
155
  end
153
156
 
154
157
  it "adds the datastream to the object" do
155
- expect(subject.attached_files['Abc']).to eq file
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(subject.eac_cpf).to eq file
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(subject.foo_bar).to eq file
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 = double(metadata?: true)
179
- ds2 = double(metadata?: true)
180
- ds3 = double(metadata?: true)
181
- file_ds = double(metadata?: false)
182
- allow(subject).to receive(:attached_files).and_return(a: ds1, b: ds2, c: ds3, e: file_ds)
183
- expect(subject.metadata_streams).to include(ds1, ds2, ds3)
184
- expect(subject.metadata_streams).to_not include(file_ds)
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(subject.attribute_names).to eq ["title", "abstract"]
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(subject.inspect).to eq "#<BarHistory4 id: nil, title: [\"test1\"], abstract: nil>"
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(subject).to receive(:id).and_return('test:123') }
41
+ before { allow(history).to receive(:id).and_return('test:123') }
42
42
 
43
43
  it "shows a id" do
44
- expect(subject.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
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(subject.inspect).to eq "#<ActiveFedora::Base id: nil>"
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
- subject.library = library
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(subject.inspect).to eq "#<BarHistory2 id: nil, title: [], abstract: nil, library_id: \"#{library.id}\">"
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(subject.title).to eq ['test1']
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(subject[:abstract]).to be_nil
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
- subject.resource[:abstract] = ['foo', 'bar']
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 { subject[:abstract] }.to raise_error ActiveFedora::ConstraintError, "Expected \"abstract\" to have 0-1 statements, but there are 2"
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(subject[:title]).to eq ['test1']
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(subject[:type]).to be_empty
115
- expect(subject[:rdf_label]).to contain_exactly("test1")
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
- subject.abstract = "Moo"
125
- }.to change { subject.abstract_changed? }.from(false).to(true)
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 { subject.title = "Quack" }.to raise_error ArgumentError
140
- expect { subject.title = ["Quack"] }.not_to raise_error
141
- expect { subject.title = nil }.not_to raise_error
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 { subject.abstract = "Low" }.not_to raise_error
146
- expect { subject.abstract = ["Low"]
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 { subject.abstract = nil }.not_to raise_error
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
- subject.attributes = { fubar: "baz", duck: "Quack" }
14
- expect(subject.fubar).to eq "baz"
15
- expect(subject.duck).to eq "Quack"
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
- subject.update_attributes(fubar: "baz", duck: "Quack")
22
- subject.reload
23
- expect(subject.fubar).to eq "baz"
24
- expect(subject.duck).to eq "Quack"
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
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
- before(:each) do
4
+ before do
5
5
  @test_object = described_class.new
6
6
  end
7
7