active-fedora 11.0.0 → 12.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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -2
  3. data/.rubocop_todo.yml +73 -18
  4. data/.travis.yml +8 -9
  5. data/CONTRIBUTING.md +66 -20
  6. data/History.txt +51 -0
  7. data/README.md +11 -14
  8. data/active-fedora.gemspec +14 -13
  9. data/lib/active_fedora/aggregation/base_extension.rb +3 -1
  10. data/lib/active_fedora/aggregation/list_source.rb +1 -1
  11. data/lib/active_fedora/associations/association.rb +1 -2
  12. data/lib/active_fedora/associations/basic_contains_association.rb +12 -0
  13. data/lib/active_fedora/associations/builder/association.rb +1 -2
  14. data/lib/active_fedora/associations/collection_association.rb +3 -3
  15. data/lib/active_fedora/associations/collection_proxy.rb +10 -10
  16. data/lib/active_fedora/associations/contained_finder.rb +2 -1
  17. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
  18. data/lib/active_fedora/associations/null_validator.rb +1 -2
  19. data/lib/active_fedora/associations/rdf.rb +1 -1
  20. data/lib/active_fedora/attached_files.rb +4 -0
  21. data/lib/active_fedora/attribute_methods.rb +1 -1
  22. data/lib/active_fedora/attributes/property_builder.rb +7 -5
  23. data/lib/active_fedora/caching_connection.rb +1 -1
  24. data/lib/active_fedora/cleaner.rb +1 -1
  25. data/lib/active_fedora/common.rb +10 -0
  26. data/lib/active_fedora/containers/container.rb +1 -2
  27. data/lib/active_fedora/core.rb +12 -5
  28. data/lib/active_fedora/errors.rb +4 -0
  29. data/lib/active_fedora/fedora.rb +19 -5
  30. data/lib/active_fedora/file/attributes.rb +5 -0
  31. data/lib/active_fedora/file.rb +3 -3
  32. data/lib/active_fedora/file_configurator.rb +5 -5
  33. data/lib/active_fedora/file_io.rb +120 -0
  34. data/lib/active_fedora/fixity_service.rb +36 -5
  35. data/lib/active_fedora/indexers/null_indexer.rb +1 -2
  36. data/lib/active_fedora/indexing/default_descriptors.rb +128 -0
  37. data/lib/active_fedora/indexing/descendant_fetcher.rb +105 -0
  38. data/lib/active_fedora/indexing/descriptor.rb +44 -0
  39. data/lib/active_fedora/indexing/field_mapper.rb +146 -0
  40. data/lib/active_fedora/indexing/inserter.rb +40 -0
  41. data/lib/active_fedora/indexing/map.rb +11 -3
  42. data/lib/active_fedora/indexing/suffix.rb +81 -0
  43. data/lib/active_fedora/indexing.rb +39 -15
  44. data/lib/active_fedora/indexing_service.rb +8 -3
  45. data/lib/active_fedora/inheritance.rb +1 -1
  46. data/lib/active_fedora/initializing_connection.rb +1 -1
  47. data/lib/active_fedora/ldp_resource.rb +1 -2
  48. data/lib/active_fedora/model_classifier.rb +1 -1
  49. data/lib/active_fedora/null_logger.rb +13 -0
  50. data/lib/active_fedora/orders/ordered_list.rb +1 -1
  51. data/lib/active_fedora/persistence.rb +16 -3
  52. data/lib/active_fedora/property.rb +1 -2
  53. data/lib/active_fedora/railtie.rb +6 -2
  54. data/lib/active_fedora/rake_support.rb +1 -1
  55. data/lib/active_fedora/rdf/field_map.rb +2 -2
  56. data/lib/active_fedora/rdf/field_map_entry.rb +15 -7
  57. data/lib/active_fedora/rdf/indexing_service.rb +15 -13
  58. data/lib/active_fedora/rdf/value_caster.rb +15 -0
  59. data/lib/active_fedora/rdf.rb +1 -0
  60. data/lib/active_fedora/relation/finder_methods.rb +28 -40
  61. data/lib/active_fedora/solr_hit.rb +1 -1
  62. data/lib/active_fedora/solr_service.rb +20 -2
  63. data/lib/active_fedora/type/value.rb +2 -4
  64. data/lib/active_fedora/version.rb +1 -1
  65. data/lib/active_fedora/with_metadata/metadata_node.rb +4 -1
  66. data/lib/active_fedora.rb +23 -9
  67. data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +1 -1
  68. data/lib/generators/active_fedora/config/solr/templates/solr/config/schema.xml +0 -6
  69. data/lib/generators/active_fedora/config/solr/templates/solr.yml +3 -3
  70. data/spec/integration/associations_spec.rb +8 -8
  71. data/spec/integration/attached_files_spec.rb +2 -3
  72. data/spec/integration/base_spec.rb +43 -39
  73. data/spec/integration/basic_contains_association_spec.rb +16 -3
  74. data/spec/integration/collection_association_spec.rb +1 -1
  75. data/spec/integration/direct_container_spec.rb +2 -2
  76. data/spec/integration/fedora_solr_sync_spec.rb +1 -1
  77. data/spec/integration/file_spec.rb +46 -13
  78. data/spec/integration/generators/fedora_generator_spec.rb +1 -1
  79. data/spec/integration/generators/solr_generator_spec.rb +1 -1
  80. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +2 -2
  81. data/spec/integration/has_many_associations_spec.rb +4 -5
  82. data/spec/integration/indexing/descendant_fetcher_spec.rb +64 -0
  83. data/spec/integration/indexing_spec.rb +22 -2
  84. data/spec/integration/indirect_container_spec.rb +2 -2
  85. data/spec/integration/query_result_builder_spec.rb +2 -2
  86. data/spec/integration/scoping_spec.rb +20 -14
  87. data/spec/integration/solr_hit_spec.rb +1 -1
  88. data/spec/integration/versionable_spec.rb +2 -2
  89. data/spec/lib/active_fedora/null_logger_spec.rb +10 -0
  90. data/spec/unit/active_fedora/indexing/inserter_spec.rb +30 -0
  91. data/spec/unit/attached_files_spec.rb +36 -8
  92. data/spec/unit/attributes_spec.rb +8 -14
  93. data/spec/unit/base_spec.rb +7 -7
  94. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +1 -1
  95. data/spec/unit/callback_spec.rb +2 -2
  96. data/spec/unit/change_set_spec.rb +1 -2
  97. data/spec/unit/collection_proxy_spec.rb +2 -1
  98. data/spec/unit/core/fedora_id_translator_spec.rb +2 -2
  99. data/spec/unit/core/fedora_uri_translator_spec.rb +2 -2
  100. data/spec/unit/core/logger_spec.rb +18 -0
  101. data/spec/unit/core_spec.rb +46 -12
  102. data/spec/unit/default_model_mapper_spec.rb +1 -1
  103. data/spec/unit/fedora_spec.rb +12 -0
  104. data/spec/unit/file_configurator_spec.rb +0 -9
  105. data/spec/unit/file_io_spec.rb +137 -0
  106. data/spec/unit/file_path_builder_spec.rb +3 -3
  107. data/spec/unit/file_spec.rb +70 -26
  108. data/spec/unit/files_hash_spec.rb +1 -2
  109. data/spec/unit/filter_spec.rb +2 -2
  110. data/spec/unit/finder_methods_spec.rb +1 -1
  111. data/spec/unit/fixity_service_spec.rb +65 -5
  112. data/spec/unit/has_and_belongs_to_many_association_spec.rb +1 -2
  113. data/spec/unit/has_many_association_spec.rb +2 -2
  114. data/spec/unit/indexing/map/index_object_spec.rb +25 -0
  115. data/spec/unit/indexing/map_spec.rb +27 -0
  116. data/spec/unit/indexing_spec.rb +3 -4
  117. data/spec/unit/inheritance_spec.rb +28 -1
  118. data/spec/unit/model_classifier_spec.rb +1 -1
  119. data/spec/unit/pathing_spec.rb +1 -2
  120. data/spec/unit/query_result_builder_spec.rb +1 -2
  121. data/spec/unit/query_spec.rb +4 -4
  122. data/spec/unit/rdf/indexing_service_spec.rb +18 -4
  123. data/spec/unit/reflection_spec.rb +2 -2
  124. data/spec/unit/solr_hit_spec.rb +1 -2
  125. data/spec/unit/solr_service_spec.rb +52 -4
  126. data/spec/unit/sparql_insert_spec.rb +1 -1
  127. data/spec/unit/validations_spec.rb +27 -4
  128. data/spec/unit/with_metadata/metadata_node_spec.rb +26 -1
  129. metadata +99 -29
@@ -19,7 +19,7 @@ describe ActiveFedora::QueryResultBuilder do
19
19
 
20
20
  it "returns an array of objects that are of the class stored in active_fedora_model_s" do
21
21
  query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([test_object.id, foo_object.id])
22
- solr_result = ActiveFedora::SolrService.query(query)
22
+ solr_result = ActiveFedora::SolrService.query(query, rows: 10)
23
23
  result = described_class.reify_solr_results(solr_result)
24
24
  expect(result.length).to eq 2
25
25
  result.each do |r|
@@ -29,7 +29,7 @@ describe ActiveFedora::QueryResultBuilder do
29
29
 
30
30
  it '#reifies a lightweight object as a new instance' do
31
31
  query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([foo_object.id])
32
- solr_result = ActiveFedora::SolrService.query(query)
32
+ solr_result = ActiveFedora::SolrService.query(query, rows: 10)
33
33
  result = described_class.reify_solr_results(solr_result, load_from_solr: true)
34
34
  expect(result.first).to be_instance_of FooObject
35
35
  end
@@ -1,17 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Scoping::Named do
4
- before do
5
- class TestClass < ActiveFedora::Base
6
- end
4
+ before(:all) do
5
+ class TestClass < ActiveFedora::Base; end
6
+ class OtherClass < ActiveFedora::Base; end
7
7
  end
8
- let!(:test_instance) { TestClass.create! }
9
-
10
- after do
11
- test_instance.delete
8
+ after(:all) do
12
9
  Object.send(:remove_const, :TestClass)
10
+ Object.send(:remove_const, :OtherClass)
13
11
  end
14
12
 
13
+ let!(:test_instance) { TestClass.create! }
14
+ after { test_instance.delete }
15
+
15
16
  describe "#all" do
16
17
  it "returns an array of instances of the calling Class" do
17
18
  result = TestClass.all.to_a
@@ -25,18 +26,23 @@ describe ActiveFedora::Scoping::Named do
25
26
  end
26
27
 
27
28
  describe '#find' do
28
- describe "#find with a valid id without cast" do
29
+ describe "a valid id without cast" do
29
30
  subject { ActiveFedora::Base.find(test_instance.id) }
30
- it { should be_instance_of TestClass }
31
+ it { is_expected.to be_instance_of TestClass }
31
32
  end
32
- describe "#find with a valid id with cast of false" do
33
+ describe "a valid id with cast of false" do
33
34
  subject { ActiveFedora::Base.find(test_instance.id, cast: false) }
34
- it { should be_instance_of ActiveFedora::Base }
35
+ it { is_expected.to be_instance_of ActiveFedora::Base }
35
36
  end
36
-
37
- describe "#find with a valid id without cast on a model extending Base" do
37
+ describe "a valid id without cast on a model extending Base" do
38
38
  subject { TestClass.find(test_instance.id) }
39
- it { should be_instance_of TestClass }
39
+ it { is_expected.to be_instance_of TestClass }
40
+ end
41
+ it "a valid id on an incompatible class raises ModelMismatch" do
42
+ expect { OtherClass.find(test_instance.id) }.to raise_error(ActiveFedora::ModelMismatch)
43
+ end
44
+ it "invalid id raises ObjectNotFoundError" do
45
+ expect { TestClass.find('some_unused_identifier') }.to raise_error(ActiveFedora::ObjectNotFoundError)
40
46
  end
41
47
  end
42
48
  end
@@ -11,6 +11,7 @@ describe ActiveFedora::SolrHit do
11
11
  Object.send(:remove_const, :Foo)
12
12
  end
13
13
 
14
+ subject(:solr_hit) { described_class.new(doc) }
14
15
  let(:another) { Foo.create }
15
16
 
16
17
  let!(:obj) { Foo.create!(
@@ -19,7 +20,6 @@ describe ActiveFedora::SolrHit do
19
20
  ) }
20
21
 
21
22
  let(:doc) { obj.to_solr }
22
- subject(:solr_hit) { described_class.new(doc) }
23
23
 
24
24
  describe "#reify" do
25
25
  let(:solr_reified) { solr_hit.reify }
@@ -32,6 +32,8 @@ describe ActiveFedora::Versionable do
32
32
  end
33
33
 
34
34
  describe 'sorting versions' do
35
+ subject(:graph) { ActiveFedora::VersionsGraph.new }
36
+
35
37
  before do
36
38
  allow(graph).to receive(:fedora_versions) { versions }
37
39
  end
@@ -40,8 +42,6 @@ describe ActiveFedora::Versionable do
40
42
  let(:version2) { instance_double(ActiveFedora::VersionsGraph::ResourceVersion, uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2', created: '2015-04-02T19:54:45.96Z') }
41
43
  let(:versions) { [version1, version2] }
42
44
 
43
- subject(:graph) { ActiveFedora::VersionsGraph.new }
44
-
45
45
  it 'sorts by DateTime' do
46
46
  expect(graph.first).to eq version2
47
47
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::NullLogger do
4
+ [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
5
+ describe "##{method_name}" do
6
+ subject { described_class.new.public_send(method_name) }
7
+ it { is_expected.to be_falsey }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::Indexing::Inserter do
4
+ let(:solr_doc) { {} }
5
+
6
+ it "handles many field types" do
7
+ described_class.create_and_insert_terms('my_name', 'value', [:displayable, :searchable, :sortable], solr_doc)
8
+ expect(solr_doc).to eq('my_name_ssm' => ['value'], 'my_name_si' => 'value', 'my_name_teim' => ['value'])
9
+ end
10
+
11
+ it "handles dates that are searchable" do
12
+ described_class.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_searchable], solr_doc)
13
+ expect(solr_doc).to eq('my_name_dtsim' => ['2013-01-10T00:00:00Z'])
14
+ end
15
+
16
+ it "handles dates that are stored_sortable" do
17
+ described_class.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_sortable], solr_doc)
18
+ expect(solr_doc).to eq('my_name_dtsi' => '2013-01-10T00:00:00Z')
19
+ end
20
+
21
+ it "handles dates that are displayable" do
22
+ described_class.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:displayable], solr_doc)
23
+ expect(solr_doc).to eq('my_name_ssm' => ['2013-01-10'])
24
+ end
25
+
26
+ it "handles dates that are sortable" do
27
+ described_class.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:sortable], solr_doc)
28
+ expect(solr_doc).to eq('my_name_dti' => '2013-01-10T00:00:00Z')
29
+ end
30
+ end
@@ -110,20 +110,25 @@ describe ActiveFedora::AttachedFiles do
110
110
  end
111
111
 
112
112
  describe "#accessor_name" do
113
- it "uses the name" do
114
- expect(af_base.send(:accessor_name, 'abc')).to eq 'abc'
113
+ subject { af_base.send(:accessor_name, value) }
114
+ context "with lowercase" do
115
+ let(:value) { 'abc' }
116
+ it { is_expected.to eq 'abc' }
115
117
  end
116
118
 
117
- it "uses the name" do
118
- expect(af_base.send(:accessor_name, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
119
+ context "with uppercase" do
120
+ let(:value) { 'ARCHIVAL_XML' }
121
+ it { is_expected.to eq 'ARCHIVAL_XML' }
119
122
  end
120
123
 
121
- it "uses the name" do
122
- expect(af_base.send(:accessor_name, 'descMetadata')).to eq 'descMetadata'
124
+ context "with camelcase" do
125
+ let(:value) { 'descMetadata' }
126
+ it { is_expected.to eq 'descMetadata' }
123
127
  end
124
128
 
125
- it "hash-erizes underscores" do
126
- expect(af_base.send(:accessor_name, 'a-b')).to eq 'a_b'
129
+ context "with dashes" do
130
+ let(:value) { 'a-b' }
131
+ it { is_expected.to eq 'a_b' }
127
132
  end
128
133
  end
129
134
 
@@ -187,4 +192,27 @@ describe ActiveFedora::AttachedFiles do
187
192
  expect(af_base.metadata_streams).to_not include(file_ds)
188
193
  end
189
194
  end
195
+
196
+ context "When the resource is using idiomatic basic containment" do
197
+ before do
198
+ class Sample1 < ActiveFedora::Base
199
+ is_a_container
200
+ end
201
+ end
202
+ after do
203
+ Object.send(:remove_const, :Sample1)
204
+ end
205
+
206
+ before do
207
+ child = obj.contains.build
208
+ child.content = "Stuff"
209
+ child.save!
210
+ end
211
+ let(:obj) { Sample1.create! }
212
+ let(:obj2) { Sample1.find(obj.id) }
213
+
214
+ it "doesn't conflate attached_file and contains" do
215
+ expect(obj2.attached_files.keys).to be_empty
216
+ end
217
+ end
190
218
  end
@@ -15,8 +15,8 @@ describe ActiveFedora::Base do
15
15
  Object.send(:remove_const, :BarHistory4)
16
16
  end
17
17
 
18
- let(:obj) { BarHistory4.new(title: ['test1']) }
19
18
  subject(:history) { obj }
19
+ let(:obj) { BarHistory4.new(title: ['test1'], id: 'test:123') }
20
20
 
21
21
  describe "#attribute_names" do
22
22
  context "on an instance" do
@@ -34,15 +34,7 @@ describe ActiveFedora::Base do
34
34
 
35
35
  describe "#inspect" do
36
36
  it "shows the attributes" do
37
- expect(history.inspect).to eq "#<BarHistory4 id: nil, title: [\"test1\"], abstract: nil>"
38
- end
39
-
40
- describe "with a id" do
41
- before { allow(history).to receive(:id).and_return('test:123') }
42
-
43
- it "shows a id" do
44
- expect(history.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
45
- end
37
+ expect(history.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
46
38
  end
47
39
 
48
40
  describe "with no attributes" do
@@ -60,8 +52,8 @@ describe ActiveFedora::Base do
60
52
  history.library = library
61
53
  end
62
54
 
63
- let(:library) { BarHistory4.create }
64
55
  subject(:history) { BarHistory2.new }
56
+ let(:library) { BarHistory4.create }
65
57
 
66
58
  after do
67
59
  Object.send(:remove_const, :BarHistory2)
@@ -98,7 +90,7 @@ describe ActiveFedora::Base do
98
90
  history.resource[:abstract] = ['foo', 'bar']
99
91
  end
100
92
  it "raises an error if just returning the first value would cause data loss" do
101
- expect { history[:abstract] }.to raise_error ActiveFedora::ConstraintError, "Expected \"abstract\" to have 0-1 statements, but there are 2"
93
+ expect { history[:abstract] }.to raise_error ActiveFedora::ConstraintError, "Expected \"abstract\" of test:123 to have 0-1 statements, but there are 2"
102
94
  end
103
95
  end
104
96
  end
@@ -139,13 +131,15 @@ describe ActiveFedora::Base do
139
131
  expect { history.title = "Quack" }.to raise_error ArgumentError
140
132
  expect { history.title = ["Quack"] }.not_to raise_error
141
133
  expect { history.title = nil }.not_to raise_error
134
+ expect { history.title = ActiveTriples::Resource.new }.to raise_error
142
135
  end
143
136
 
144
137
  it "does not allow an enumerable to a unique attribute writer" do
145
138
  expect { history.abstract = "Low" }.not_to raise_error
146
- expect { history.abstract = ["Low"]
147
- }.to raise_error ArgumentError, "You attempted to set the property `abstract' to an enumerable value. However, this property is declared as singular."
139
+ expect { history.abstract = ["Low"] }
140
+ .to raise_error ArgumentError, "You attempted to set the property `abstract' of test:123 to an enumerable value. However, this property is declared as singular."
148
141
  expect { history.abstract = nil }.not_to raise_error
142
+ expect { history.abstract = ActiveTriples::Resource.new }.not_to raise_error
149
143
  end
150
144
  end
151
145
  end
@@ -63,8 +63,8 @@ describe ActiveFedora::Base do
63
63
  Object.send(:remove_const, :FooHistory)
64
64
  end
65
65
 
66
- let(:instance) { FooHistory.new(title: ['A label']) }
67
66
  subject { instance.rdf_label }
67
+ let(:instance) { FooHistory.new(title: ['A label']) }
68
68
 
69
69
  it { is_expected.to eq ['A label'] }
70
70
  end
@@ -88,8 +88,8 @@ describe ActiveFedora::Base do
88
88
  Object.send(:remove_const, :Creator)
89
89
  end
90
90
 
91
- let(:instance) { Creator.new(foaf_name: ['Carolyn'], job: ['Developer']) }
92
91
  subject { instance.rdf_label }
92
+ let(:instance) { Creator.new(foaf_name: ['Carolyn'], job: ['Developer']) }
93
93
 
94
94
  it { is_expected.to eq ['Developer'] }
95
95
  end
@@ -165,11 +165,11 @@ describe ActiveFedora::Base do
165
165
  context "before saving" do
166
166
  context "#to_param" do
167
167
  subject { @test_object.to_param }
168
- it { should be_nil }
168
+ it { is_expected.to be_nil }
169
169
  end
170
170
  context "#to_key" do
171
171
  subject { @test_object.to_key }
172
- it { should be_nil }
172
+ it { is_expected.to be_nil }
173
173
  end
174
174
  end
175
175
 
@@ -181,12 +181,12 @@ describe ActiveFedora::Base do
181
181
 
182
182
  context "#to_param" do
183
183
  subject { @test_object.to_param }
184
- it { should eq 'one/two/three' }
184
+ it { is_expected.to eq 'one/two/three' }
185
185
  end
186
186
 
187
187
  context "#to_key" do
188
188
  subject { @test_object.to_key }
189
- it { should eq ['one/two/three'] }
189
+ it { is_expected.to eq ['one/two/three'] }
190
190
  end
191
191
  end
192
192
  ### end ActiveModel::Conversions
@@ -253,7 +253,7 @@ describe ActiveFedora::Base do
253
253
  end
254
254
 
255
255
  it "updates the resource" do
256
- expect(test_object.resource.rdf_subject).to eq ::RDF::URI.new("#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{@this_id}")
256
+ expect(test_object.resource.rdf_subject).to eq ::RDF::URI.new("#{ActiveFedora.fedora.base_uri}/#{@this_id}")
257
257
  expect(test_object.title).to eq ['foo']
258
258
  end
259
259
  end
@@ -3,6 +3,6 @@ require 'spec_helper'
3
3
  describe ActiveFedora::Associations::Builder::HasAndBelongsToMany do
4
4
  describe "valid_options" do
5
5
  subject { described_class.valid_options({}) }
6
- it { should match_array [:class_name, :predicate, :type_validator, :before_add, :after_add, :before_remove, :after_remove, :inverse_of, :solr_page_size, :autosave] }
6
+ it { is_expected.to match_array [:class_name, :predicate, :type_validator, :before_add, :after_add, :before_remove, :after_remove, :inverse_of, :solr_page_size, :autosave] }
7
7
  end
8
8
  end
@@ -24,7 +24,7 @@ describe ActiveFedora::Base do
24
24
  Object.send(:remove_const, :CallbackStub)
25
25
  end
26
26
 
27
- it "has after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
27
+ it "has after_initialize, before_save, after_save, before_create, after_create" do
28
28
  allow_any_instance_of(CallbackStub).to receive(:a_init)
29
29
  allow_any_instance_of(CallbackStub).to receive :b_create
30
30
  allow_any_instance_of(CallbackStub).to receive :a_create
@@ -34,7 +34,7 @@ describe ActiveFedora::Base do
34
34
  @cb.save
35
35
  end
36
36
 
37
- it "has after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
37
+ it "has after_initialize, before_save, after_save, before_create, after_create, after_update, before_update, before_destroy" do
38
38
  allow_any_instance_of(CallbackStub).to receive(:a_init)
39
39
  allow_any_instance_of(CallbackStub).to receive(:b_create)
40
40
  allow_any_instance_of(CallbackStub).to receive(:a_create)
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::ChangeSet do
4
- let(:change_set) { described_class.new(base, base.resource, base.changed_attributes.keys) }
5
- subject { change_set }
4
+ subject(:change_set) { described_class.new(base, base.resource, base.changed_attributes.keys) }
6
5
 
7
6
  context "with an unchanged object" do
8
7
  let(:base) { ActiveFedora::Base.new }
@@ -14,11 +14,12 @@ describe ActiveFedora::Associations::CollectionProxy do
14
14
  end
15
15
 
16
16
  describe "#spawn" do
17
+ subject { proxy.spawn }
18
+
17
19
  let(:reflection) { ActiveFedora::Reflection.create(:has_many, :pages, nil, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection }, Book) }
18
20
  let(:association) { ActiveFedora::Associations::HasManyAssociation.new(Book.new, reflection) }
19
21
  let(:proxy) { described_class.new(association) }
20
22
 
21
- subject { proxy.spawn }
22
23
  it { is_expected.to be_instance_of ActiveFedora::Relation }
23
24
  end
24
25
  end
@@ -4,7 +4,7 @@ RSpec.describe ActiveFedora::Core::FedoraIdTranslator do
4
4
  describe ".call" do
5
5
  let(:result) { described_class.call(id) }
6
6
  context "when given an id" do
7
- let(:good_uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path + "/banana" }
7
+ let(:good_uri) { ActiveFedora.fedora.base_uri + "/banana" }
8
8
  let(:id) { "banana" }
9
9
  it "returns a fedora URI" do
10
10
  expect(result).to eq good_uri
@@ -18,7 +18,7 @@ RSpec.describe ActiveFedora::Core::FedoraIdTranslator do
18
18
  end
19
19
 
20
20
  context "with characters that need escaping" do
21
- let(:good_uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path + "/%5Bfrob%5D" }
21
+ let(:good_uri) { ActiveFedora.fedora.base_uri + "/%5Bfrob%5D" }
22
22
  let(:id) { "[frob]" }
23
23
  it "returns a good fedora URI" do
24
24
  expect(result).to eq good_uri
@@ -4,13 +4,13 @@ RSpec.describe ActiveFedora::Core::FedoraUriTranslator do
4
4
  describe ".call" do
5
5
  let(:result) { described_class.call(uri) }
6
6
  context "when given a Fedora URI" do
7
- let(:uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path + "/6" }
7
+ let(:uri) { ActiveFedora.fedora.base_uri + "/6" }
8
8
  it "returns the id" do
9
9
  expect(result).to eq '6'
10
10
  end
11
11
  end
12
12
  context "when given a URI missing a slash" do
13
- let(:uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path + "602-a" }
13
+ let(:uri) { ActiveFedora.fedora.base_uri + "602-a" }
14
14
  it "returns the id" do
15
15
  expect(result).to eq "602-a"
16
16
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::NullLogger do
4
+ before { ActiveFedora::Base.logger = described_class.new }
5
+ describe "::logger" do
6
+ let(:logger) { ActiveFedora::Base.logger }
7
+ it "when calling the logger" do
8
+ expect(logger.warn("warning!")).to be_nil
9
+ end
10
+ end
11
+
12
+ describe "#logger" do
13
+ let(:logger) { ActiveFedora::Base.new.logger }
14
+ it "when calling the logger" do
15
+ expect(logger.warn("warning!")).to be_nil
16
+ end
17
+ end
18
+ end
@@ -11,8 +11,8 @@ describe ActiveFedora::Base do
11
11
  end
12
12
  end
13
13
 
14
- let(:library) { Library.create }
15
14
  subject(:book) { Book.new(library: library, title: "War and Peace", publisher: "Random House") }
15
+ let(:library) { Library.create }
16
16
 
17
17
  after do
18
18
  Object.send(:remove_const, :Book)
@@ -23,11 +23,45 @@ describe ActiveFedora::Base do
23
23
  expect(book.has_model).to eq ['Book']
24
24
  end
25
25
 
26
- describe "initialize with a block" do
27
- subject(:book) { Book.new { |b| b.title = "The Sun also Rises" } }
26
+ describe "initialize" do
27
+ context "with a block" do
28
+ subject(:book) { Book.new { |b| b.title = "The Sun also Rises" } }
29
+
30
+ it "has set the title" do
31
+ expect(book.title).to eq "The Sun also Rises"
32
+ end
33
+ end
34
+
35
+ context "with an identifier" do
36
+ subject(:book) { Book.new(attributes) }
37
+ let(:attributes) { { id: '1234' } }
28
38
 
29
- it "has set the title" do
30
- expect(book.title).to eq "The Sun also Rises"
39
+ it "sets the id and doesn't modify the passed hash" do
40
+ expect(book.id).to eq '1234'
41
+ expect(attributes[:id]).to eq '1234'
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#etag' do
47
+ let(:attributes) { { id: '1234' } }
48
+
49
+ it 'before save raises an error' do
50
+ expect { book.etag }
51
+ .to raise_error 'Unable to produce an etag for a unsaved object'
52
+ end
53
+
54
+ context 'after save' do
55
+ before { book.save! }
56
+
57
+ it 'has the etag from the ldp_source' do
58
+ expect(book.etag).to eq book.ldp_source.head.etag
59
+ end
60
+
61
+ it 'after delete raises Ldp::Gone' do
62
+ book.destroy!
63
+ expect { book.etag }.to raise_error Ldp::Gone
64
+ end
31
65
  end
32
66
  end
33
67
 
@@ -105,11 +139,11 @@ describe ActiveFedora::Base do
105
139
  end
106
140
 
107
141
  describe "id_to_uri" do
108
- let(:id) { '123456w' }
109
142
  subject(:uri) { described_class.id_to_uri(id) }
143
+ let(:id) { '123456w' }
110
144
 
111
145
  context "with no custom proc is set" do
112
- it { should eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/123456w" }
146
+ it { is_expected.to eq "#{ActiveFedora.fedora.base_uri}/123456w" }
113
147
  it "justs call #translate_id_to_uri" do
114
148
  allow(described_class).to receive(:translate_id_to_uri).and_call_original
115
149
  allow(ActiveFedora::Core::FedoraIdTranslator).to receive(:call).and_call_original
@@ -122,11 +156,11 @@ describe ActiveFedora::Base do
122
156
 
123
157
  context "when custom proc is set" do
124
158
  before do
125
- described_class.translate_id_to_uri = lambda { |id| "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/foo/#{id}" }
159
+ described_class.translate_id_to_uri = lambda { |id| "#{ActiveFedora.fedora.base_uri}/foo/#{id}" }
126
160
  end
127
161
  after { described_class.translate_id_to_uri = nil }
128
162
 
129
- it { should eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/foo/123456w" }
163
+ it { is_expected.to eq "#{ActiveFedora.fedora.base_uri}/foo/123456w" }
130
164
  end
131
165
 
132
166
  context "with an empty base path" do
@@ -145,11 +179,11 @@ describe ActiveFedora::Base do
145
179
  end
146
180
 
147
181
  describe "uri_to_id" do
148
- let(:uri) { "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/foo/123456w" }
149
182
  subject(:uri_id) { described_class.uri_to_id(uri) }
183
+ let(:uri) { "#{ActiveFedora.fedora.base_uri}/foo/123456w" }
150
184
 
151
185
  context "with no custom proc is set" do
152
- it { should eq 'foo/123456w' }
186
+ it { is_expected.to eq 'foo/123456w' }
153
187
  it "justs call #translate_uri_to_id" do
154
188
  allow(described_class).to receive(:translate_uri_to_id).and_call_original
155
189
  allow(ActiveFedora::Core::FedoraUriTranslator).to receive(:call).and_call_original
@@ -166,7 +200,7 @@ describe ActiveFedora::Base do
166
200
  end
167
201
  after { described_class.translate_uri_to_id = nil }
168
202
 
169
- it { should eq '123456w' }
203
+ it { is_expected.to eq '123456w' }
170
204
  end
171
205
  end
172
206
 
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::DefaultModelMapper do
4
+ subject(:mapper) { described_class.new classifier_class: classifier, solr_field: solr_field, predicate: predicate }
4
5
  let(:classifier) { class_double(ActiveFedora::ModelClassifier) }
5
6
  let(:classifier_instance) { instance_double(ActiveFedora::ModelClassifier) }
6
7
  let(:solr_field) { 'solr_field' }
7
8
  let(:predicate) { 'info:predicate' }
8
- subject(:mapper) { described_class.new classifier_class: classifier, solr_field: solr_field, predicate: predicate }
9
9
 
10
10
  describe '#classifier' do
11
11
  context 'with a solr document' do
@@ -15,5 +15,17 @@ describe ActiveFedora::Fedora do
15
15
  fedora.authorized_connection
16
16
  }
17
17
  end
18
+ describe "with request options" do
19
+ let(:config) {
20
+ { url: "https://example.com",
21
+ user: "fedoraAdmin",
22
+ password: "fedoraAdmin",
23
+ request: { timeout: 600, open_timeout: 60 } }
24
+ }
25
+ specify {
26
+ expect(Faraday).to receive(:new).with("https://example.com", request: { timeout: 600, open_timeout: 60 }).and_call_original
27
+ fedora.authorized_connection
28
+ }
29
+ end
18
30
  end
19
31
  end
@@ -141,7 +141,6 @@ describe ActiveFedora::FileConfigurator do
141
141
  configurator.reset!
142
142
  end
143
143
  it "loads the file specified in fedora_config_path" do
144
- allow(configurator).to receive(:load_solrizer_config)
145
144
  expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
146
145
  expect(configurator).to receive(:load_solr_config)
147
146
  expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n url: http://myfedora:8080")
@@ -150,7 +149,6 @@ describe ActiveFedora::FileConfigurator do
150
149
  end
151
150
 
152
151
  it "allows sharding" do
153
- allow(configurator).to receive(:load_solrizer_config)
154
152
  expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
155
153
  expect(configurator).to receive(:load_solr_config)
156
154
  expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n- url: http://myfedora:8080\n- url: http://myfedora:8081")
@@ -159,7 +157,6 @@ describe ActiveFedora::FileConfigurator do
159
157
  end
160
158
 
161
159
  it "parses the file using ERb" do
162
- allow(configurator).to receive(:load_solrizer_config)
163
160
  expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
164
161
  expect(configurator).to receive(:load_solr_config)
165
162
  expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:<%= 8983 %>\ntest:\n url: http://myfedora:<%= 8081 %>")
@@ -173,7 +170,6 @@ describe ActiveFedora::FileConfigurator do
173
170
  configurator.reset!
174
171
  end
175
172
  it "loads the file specified in solr_config_path" do
176
- allow(configurator).to receive(:load_solrizer_config)
177
173
  expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
178
174
  expect(configurator).to receive(:load_fedora_config)
179
175
  expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
@@ -182,7 +178,6 @@ describe ActiveFedora::FileConfigurator do
182
178
  end
183
179
 
184
180
  it "parses the file using ERb" do
185
- allow(configurator).to receive(:load_solrizer_config)
186
181
  expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
187
182
  expect(configurator).to receive(:load_fedora_config)
188
183
  expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:<%= 8983 %>\ntest:\n default:\n url: http://mysolr:<%= 8081 %>")
@@ -191,7 +186,6 @@ describe ActiveFedora::FileConfigurator do
191
186
  end
192
187
 
193
188
  it "includes update_path and select_path in solr_config" do
194
- allow(configurator).to receive(:load_solrizer_config)
195
189
  expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
196
190
  expect(configurator).to receive(:load_fedora_config)
197
191
  expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("test:\n url: http://mysolr:8080\n update_path: update_test\n select_path: select_test\n")
@@ -255,7 +249,6 @@ describe ActiveFedora::FileConfigurator do
255
249
  end
256
250
 
257
251
  it "loads a config from the current working directory as a second choice" do
258
- allow(configurator).to receive(:load_solrizer_config)
259
252
  allow(Dir).to receive(:getwd).and_return(@fake_rails_root)
260
253
  configurator.init
261
254
  expect(configurator.config_path(:fedora)).to eql("#{@fake_rails_root}/config/fedora.yml")
@@ -264,7 +257,6 @@ describe ActiveFedora::FileConfigurator do
264
257
 
265
258
  it "loads the config that ships with this gem as a last choice" do
266
259
  allow(Dir).to receive(:getwd).and_return("/fake/path")
267
- allow(configurator).to receive(:load_solrizer_config)
268
260
  expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.").exactly(3).times
269
261
  configurator.init
270
262
  expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
@@ -288,7 +280,6 @@ describe ActiveFedora::FileConfigurator do
288
280
  end
289
281
 
290
282
  it "loads a config from Rails.root as a first choice" do
291
- allow(configurator).to receive(:load_solrizer_config)
292
283
  configurator.init
293
284
  expect(configurator.config_path(:fedora)).to eql("#{Rails.root}/config/fedora.yml")
294
285
  expect(configurator.solr_config_path).to eql("#{Rails.root}/config/solr.yml")