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
@@ -334,12 +334,6 @@
334
334
  -->
335
335
  <uniqueKey>id</uniqueKey>
336
336
 
337
- <!-- field for the QueryParser to use when an explicit fieldname is absent -->
338
- <!-- <defaultSearchField>text</defaultSearchField> -->
339
-
340
- <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
341
- <solrQueryParser defaultOperator="OR"/>
342
-
343
337
  <!-- copyField commands copy one field to another at the time a document
344
338
  is added to the index. It's used either to index the same field differently,
345
339
  or to add multiple fields to the same field for easier/faster searching. -->
@@ -1,7 +1,7 @@
1
1
  # This is a sample config file that points to a solr server for each environment
2
2
  development:
3
- url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8983 %>/solr/hydra-development
3
+ url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV.fetch('SOLR_DEVELOPMENT_PORT', 8983)}/solr/hydra-development" %>
4
4
  test:
5
- url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8985 %>/solr/hydra-test
5
+ url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV.fetch('SOLR_TEST_PORT', 8985)}/solr/hydra-test" %>
6
6
  production:
7
- url: http://your.production.server:8080/bl_solr/core0
7
+ url: <%= ENV['SOLR_URL'] || "http://your.production.server:8080/bl_solr/core0" %>
@@ -16,8 +16,8 @@ describe ActiveFedora::Base do
16
16
  Object.send(:remove_const, :Person)
17
17
  end
18
18
 
19
- let(:person) { Person.create }
20
19
  subject(:book) { Book.new(author: person) }
20
+ let(:person) { Person.create }
21
21
 
22
22
  it "goes" do
23
23
  book.save
@@ -511,8 +511,7 @@ describe ActiveFedora::Base do
511
511
  after_count(m.reload.library_books.count)
512
512
  end
513
513
 
514
- def say_hi(_var)
515
- end
514
+ def say_hi(_var); end
516
515
  end
517
516
  class Page < ActiveFedora::Base
518
517
  has_many :library_books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
@@ -524,14 +523,15 @@ describe ActiveFedora::Base do
524
523
  end
525
524
 
526
525
  describe "removing association" do
527
- let(:p1) { Page.create }
528
- let(:p2) { Page.create }
529
526
  subject(:book) do
530
527
  book = LibraryBook.create
531
528
  book.pages << p1 << p2
532
529
  book.save!
533
530
  book
534
531
  end
532
+ let(:p1) { Page.create }
533
+ let(:p2) { Page.create }
534
+
535
535
  it "saves between the before and after hooks" do
536
536
  expect(book).to receive(:before_count).with(1)
537
537
  expect(book).to receive(:after_count).with(0)
@@ -582,7 +582,7 @@ describe ActiveFedora::Base do
582
582
  Object.send(:remove_const, :MediaObject)
583
583
  end
584
584
 
585
- it "it should find the reflection that bears the predicate" do
585
+ it "finds the reflection that bears the predicate" do
586
586
  expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble._reflect_on_association(:media_object)
587
587
  end
588
588
  end
@@ -602,7 +602,7 @@ describe ActiveFedora::Base do
602
602
  Object.send(:remove_const, :MediaObject)
603
603
  end
604
604
 
605
- it "it should find the reflection that bears the predicate" do
605
+ it "finds the reflection that bears the predicate" do
606
606
  expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile._reflect_on_association(:media_object)
607
607
  end
608
608
  end
@@ -622,7 +622,7 @@ describe ActiveFedora::Base do
622
622
  Object.send(:remove_const, :MediaObject)
623
623
  end
624
624
 
625
- it "it should find the reflection that bears the predicate" do
625
+ it "finds the reflection that bears the predicate" do
626
626
  expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject._reflect_on_association(:baubles)
627
627
  end
628
628
  end
@@ -37,16 +37,15 @@ describe ActiveFedora::AttachedFiles do
37
37
  end
38
38
  end
39
39
 
40
+ subject { ds.content }
40
41
  let(:file) { DSTest.create }
41
42
  let(:ds) { file.test_ds }
42
43
 
43
- subject { ds.content }
44
-
45
44
  after do
46
45
  Object.send(:remove_const, :DSTest)
47
46
  end
48
47
 
49
- it { should == 'XXX' }
48
+ it { is_expected.to eq('XXX') }
50
49
 
51
50
  context "After updating" do
52
51
  before do
@@ -1,21 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
- describe '#reload' do
5
- before do
6
- class Foo < ActiveFedora::Base
7
- property :person, predicate: ::RDF::Vocab::DC.creator
8
- end
9
- end
10
- after do
11
- Object.send(:remove_const, :Foo)
4
+ before(:all) do
5
+ class Foo < ActiveFedora::Base
6
+ property :person, predicate: ::RDF::Vocab::DC.creator
12
7
  end
8
+ end
9
+ after(:all) { Object.send(:remove_const, :Foo) }
10
+
11
+ describe '#reload' do
13
12
  context "when persisted" do
14
13
  let(:object) { Foo.create(person: ['bob']) }
15
14
  let(:object2) { Foo.find(object.id) }
16
- before do
17
- object2.update(person: ['dave'])
18
- end
15
+ before { object2.update(person: ['dave']) }
19
16
 
20
17
  it 're-queries Fedora' do
21
18
  object.reload
@@ -24,36 +21,31 @@ describe ActiveFedora::Base do
24
21
  end
25
22
 
26
23
  context "when not persisted" do
27
- let(:object) { Foo.new }
28
24
  it 'raises an error' do
29
- expect { object.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
25
+ expect { Foo.new.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
30
26
  end
31
27
  end
32
28
  end
33
29
 
34
30
  describe "a saved object" do
35
- before do
31
+ before(:all) do
36
32
  class Book < ActiveFedora::Base
37
33
  type [::RDF::URI("http://www.example.com/Book")]
38
34
  property :title, predicate: ::RDF::Vocab::DC.title
39
35
  end
40
36
  end
41
-
42
- after do
43
- Object.send(:remove_const, :Book)
44
- end
45
- let!(:obj) { Book.create }
46
-
37
+ after(:all) { Object.send(:remove_const, :Book) }
47
38
  after { obj.destroy unless obj.destroyed? }
39
+ let!(:obj) { Book.create }
48
40
 
49
41
  describe "#errors" do
50
42
  subject { obj.errors }
51
- it { should be_empty }
43
+ it { is_expected.to be_empty }
52
44
  end
53
45
 
54
46
  describe "#id" do
55
47
  subject { obj.id }
56
- it { should_not be_nil }
48
+ it { is_expected.to_not be_nil }
57
49
  end
58
50
 
59
51
  context "when updated with changes after one second" do
@@ -71,12 +63,12 @@ describe ActiveFedora::Base do
71
63
 
72
64
  describe "#create_date" do
73
65
  subject { obj.create_date }
74
- it { should_not be_nil }
66
+ it { is_expected.to_not be_nil }
75
67
  end
76
68
 
77
69
  describe "#modified_date" do
78
70
  subject { obj.modified_date }
79
- it { should_not be_nil }
71
+ it { is_expected.to_not be_nil }
80
72
  end
81
73
 
82
74
  describe "delete" do
@@ -121,43 +113,55 @@ describe ActiveFedora::Base do
121
113
  end
122
114
  end
123
115
 
124
- describe "#exists?" do
125
- let(:obj) { described_class.create }
116
+ shared_examples 'ActiveFedora::Base#exists?' do
117
+ let(:obj) { test_class.create }
126
118
  it "returns true for objects that exist" do
127
- expect(described_class.exists?(obj)).to be true
119
+ expect(test_class.exists?(obj)).to be true
128
120
  end
129
121
  it "returns true for ids that exist" do
130
- expect(described_class.exists?(obj.id)).to be true
122
+ expect(test_class.exists?(obj.id)).to be true
131
123
  end
132
124
  it "returns false for ids that don't exist" do
133
- expect(described_class.exists?('test:missing_object')).to be false
134
- end
135
- it "returns false for nil" do
136
- expect(described_class.exists?(nil)).to be false
137
- end
138
- it "returns false for false" do
139
- expect(described_class.exists?(false)).to be false
125
+ expect(test_class.exists?('test_missing_object')).to be false
140
126
  end
141
- it "returns false for empty" do
142
- expect(described_class.exists?('')).to be false
127
+ it "returns false for nil, false and empty" do
128
+ expect(test_class.exists?(nil)).to be false
129
+ expect(test_class.exists?(false)).to be false
130
+ expect(test_class.exists?('')).to be false
143
131
  end
144
132
  context "when passed a hash of conditions" do
145
133
  let(:conditions) { { foo: "bar" } }
146
134
  context "and at least one object matches the conditions" do
147
135
  it "returns true" do
148
136
  allow(ActiveFedora::SolrService).to receive(:query) { [instance_double(RSolr::HashWithResponse)] }
149
- expect(described_class.exists?(conditions)).to be true
137
+ expect(test_class.exists?(conditions)).to be true
150
138
  end
151
139
  end
152
140
  context "and no object matches the conditions" do
153
141
  it "returns false" do
154
142
  allow(ActiveFedora::SolrService).to receive(:query) { [] }
155
- expect(described_class.exists?(conditions)).to be false
143
+ expect(test_class.exists?(conditions)).to be false
156
144
  end
157
145
  end
158
146
  end
159
147
  end
160
148
 
149
+ context 'base class' do
150
+ let(:test_class) { described_class }
151
+ it_behaves_like 'ActiveFedora::Base#exists?'
152
+ end
153
+
154
+ context 'subclass' do
155
+ let(:test_class) { Foo }
156
+ it_behaves_like 'ActiveFedora::Base#exists?'
157
+
158
+ it 'does not mistake other fedora objects for subclass' do
159
+ obj = described_class.create
160
+ expect { test_class.exists?(obj.id) }.not_to raise_error
161
+ expect(test_class.exists?(obj.id)).to be false
162
+ end
163
+ end
164
+
161
165
  describe "overriding resource_class_factory" do
162
166
  subject(:test_base) { TestBase.new }
163
167
  before do
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveFedora::Base do
4
- let(:model) { Source.new }
5
-
3
+ describe ActiveFedora::Associations::BasicContainsAssociation do
6
4
  context "with a file" do
7
5
  before do
8
6
  class Source < ActiveFedora::Base
@@ -10,6 +8,8 @@ describe ActiveFedora::Base do
10
8
  end
11
9
  end
12
10
 
11
+ let(:model) { Source.new }
12
+
13
13
  after do
14
14
  Object.send(:remove_const, :Source)
15
15
  end
@@ -104,5 +104,18 @@ describe ActiveFedora::Base do
104
104
  .and change { Thing.count }.by(-2)
105
105
  end
106
106
  end
107
+
108
+ describe "#reload" do
109
+ before do
110
+ model.save!
111
+ child = model.contains.create(title: ['title 1'])
112
+ model.reload # Cause the model to load its graph that contains the child ids.
113
+ ActiveFedora::Base.find(child.id).destroy
114
+ end
115
+
116
+ it "can reload without attempting to load any deleted objects" do
117
+ expect { model.contains.reload }.not_to raise_error
118
+ end
119
+ end
107
120
  end
108
121
  end
@@ -157,8 +157,8 @@ describe ActiveFedora::Base do
157
157
  Object.send(:remove_const, :Foo)
158
158
  end
159
159
 
160
- let(:instance) { Foo::Container.new }
161
160
  subject { instance.items }
161
+ let(:instance) { Foo::Container.new }
162
162
 
163
163
  it { is_expected.to eq [] }
164
164
  end
@@ -16,8 +16,8 @@ describe "Direct containers" do
16
16
  let(:reloaded) { FooHistory.find(o.id) }
17
17
 
18
18
  context "with no files" do
19
- let(:o) { FooHistory.new }
20
19
  subject { o.files }
20
+ let(:o) { FooHistory.new }
21
21
 
22
22
  it { is_expected.to be_empty }
23
23
  it { is_expected.to eq [] }
@@ -124,8 +124,8 @@ describe "Direct containers" do
124
124
  let(:reloaded) { FooHistory.find(o.id) }
125
125
 
126
126
  context "with no files" do
127
- let(:o) { FooHistory.new }
128
127
  subject { o.files }
128
+ let(:o) { FooHistory.new }
129
129
 
130
130
  it { is_expected.to be_empty }
131
131
  it { is_expected.to eq [] }
@@ -17,8 +17,8 @@ describe "fedora_solr_sync_issues" do
17
17
  Object.send(:remove_const, :ParentThing)
18
18
  end
19
19
 
20
- let(:parent) { ParentThing.create }
21
20
  subject(:child) { ChildThing.create parent: parent }
21
+ let(:parent) { ParentThing.create }
22
22
 
23
23
  before { Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, child.uri).delete }
24
24
 
@@ -84,7 +84,45 @@ describe ActiveFedora::File do
84
84
  allow_any_instance_of(SampleResource).to receive(:content_changed?).and_return(true)
85
85
  end
86
86
  subject { descMetadata.described_by }
87
- it { should eq descMetadata.uri + '/fcr:metadata' }
87
+ it { is_expected.to eq descMetadata.uri + '/fcr:metadata' }
88
+ end
89
+ end
90
+
91
+ describe "#content" do
92
+ let(:file) { described_class.new { |ds| ds.content = content } }
93
+
94
+ before do
95
+ file.save
96
+ end
97
+
98
+ describe "#content" do
99
+ subject(:resource) { described_class.new(file.uri).content }
100
+
101
+ before { content.rewind }
102
+
103
+ context "when encoding is not set" do
104
+ let(:content) { fixture('dino.jpg') }
105
+
106
+ it "is read from fedora" do
107
+ expect(resource).to eq content.read
108
+ expect(resource.encoding).to eq Encoding::ASCII_8BIT
109
+ end
110
+ end
111
+
112
+ context "when encoding is set" do
113
+ let(:file) do
114
+ described_class.new do |f|
115
+ f.content = content
116
+ f.mime_type = 'text/plain;charset=UTF-8'
117
+ end
118
+ end
119
+ let(:content) { StringIO.new "I'm a little teåpot" }
120
+
121
+ it "is read from fedora" do
122
+ expect(resource).to eq content.read
123
+ expect(resource.encoding).to eq Encoding::UTF_8
124
+ end
125
+ end
88
126
  end
89
127
  end
90
128
 
@@ -108,13 +146,13 @@ describe ActiveFedora::File do
108
146
 
109
147
  describe "the metadata file" do
110
148
  subject { descMetadata }
111
- it { should be_a_kind_of(described_class) }
149
+ it { is_expected.to be_a_kind_of(described_class) }
112
150
  end
113
151
 
114
152
  context "a binary file" do
115
153
  let(:path) { "ds#{Time.now.to_i}" }
116
154
  let(:content) { fixture('dino.jpg') }
117
- let(:file) { described_class.new.tap { |ds| ds.content = content } }
155
+ let(:file) { described_class.new { |ds| ds.content = content } }
118
156
 
119
157
  before do
120
158
  test_object.attach_file(file, path)
@@ -125,11 +163,6 @@ describe ActiveFedora::File do
125
163
  expect(test_object.attached_files[path]).to_not be_content_changed
126
164
  end
127
165
 
128
- it "is able to read the content from fedora" do
129
- content.rewind
130
- expect(test_object.attached_files[path].content).to eq content.read
131
- end
132
-
133
166
  describe "streaming the response" do
134
167
  let(:stream_reader) { instance_double(IO) }
135
168
  it "streams the response" do
@@ -145,19 +178,19 @@ describe ActiveFedora::File do
145
178
  subject { str = ''; test_object.webm.stream(range).each { |chunk| str << chunk }; str }
146
179
  context "whole thing" do
147
180
  let(:range) { 'bytes=0-15' }
148
- it { should eq 'one1two2threfour' }
181
+ it { is_expected.to eq 'one1two2threfour' }
149
182
  end
150
183
  context "open ended" do
151
184
  let(:range) { 'bytes=0-' }
152
- it { should eq 'one1two2threfour' }
185
+ it { is_expected.to eq 'one1two2threfour' }
153
186
  end
154
187
  context "not starting at the beginning" do
155
188
  let(:range) { 'bytes=3-15' }
156
- it { should eq '1two2threfour' }
189
+ it { is_expected.to eq '1two2threfour' }
157
190
  end
158
191
  context "not ending at the end" do
159
192
  let(:range) { 'bytes=4-11' }
160
- it { should eq 'two2thre' }
193
+ it { is_expected.to eq 'two2thre' }
161
194
  end
162
195
  end
163
196
 
@@ -168,7 +201,7 @@ describe ActiveFedora::File do
168
201
  test_object.save!
169
202
  end
170
203
  subject { str = ''; test_object.redirector.stream.each { |chunk| str << chunk }; str }
171
- it { should eq 'one1two2threfour' }
204
+ it { is_expected.to eq 'one1two2threfour' }
172
205
  end
173
206
 
174
207
  context "when there are more than 3 requests because of redirects" do
@@ -4,7 +4,7 @@ require 'generators/active_fedora/config/fedora/fedora_generator'
4
4
  describe ActiveFedora::Config::FedoraGenerator do
5
5
  describe "#fcrepo_wrapper_config" do
6
6
  let(:generator) { described_class.new }
7
- let(:files_to_test) {[
7
+ let(:files_to_test) { [
8
8
  'config/fcrepo_wrapper_test.yml',
9
9
  '.fcrepo_wrapper'
10
10
  ]}
@@ -4,7 +4,7 @@ require 'generators/active_fedora/config/solr/solr_generator'
4
4
  describe ActiveFedora::Config::SolrGenerator do
5
5
  describe "#solr_wrapper_config" do
6
6
  let(:generator) { described_class.new }
7
- let(:files_to_test) {[
7
+ let(:files_to_test) { [
8
8
  'config/solr_wrapper_test.yml',
9
9
  '.solr_wrapper'
10
10
  ]}
@@ -171,14 +171,14 @@ describe ActiveFedora::Base do
171
171
 
172
172
  describe "#empty?" do
173
173
  subject { book.collections }
174
- it { should_not be_empty }
174
+ it { is_expected.to_not be_empty }
175
175
  end
176
176
  end
177
177
 
178
178
  context "when a book isn't in a collection" do
179
179
  describe "#empty?" do
180
180
  subject { book.collections }
181
- it { should be_empty }
181
+ it { is_expected.to be_empty }
182
182
  end
183
183
  end
184
184
  end
@@ -28,17 +28,17 @@ describe ActiveFedora::Associations::HasManyAssociation do
28
28
  end
29
29
 
30
30
  context "when the owner is not saved, and potential targets (Books) exist" do
31
+ subject { library.books.count }
31
32
  let!(:book) { Book.create }
32
33
  let(:library) { Library.new }
33
- subject { library.books.count }
34
34
  # it excludes the books that aren't associated
35
35
  it { is_expected.to eq 0 }
36
36
  end
37
37
 
38
38
  context "when the owner is saved with associations" do
39
+ subject { library.reload; library.books.count }
39
40
  let(:book) { Book.create }
40
41
  let!(:library) { Library.create(books: [book]) }
41
- subject { library.reload; library.books.count }
42
42
  # it excludes the books that are associated
43
43
  it { is_expected.to eq 1 }
44
44
  end
@@ -55,13 +55,13 @@ describe ActiveFedora::Associations::HasManyAssociation do
55
55
  end
56
56
 
57
57
  context "loading the association prior to a save that affects the association" do
58
- let(:library) { Library.new }
59
58
  before do
60
59
  Book.create
61
60
  library.books
62
61
  library.save
63
62
  end
64
63
  subject { library.books.size }
64
+ let(:library) { Library.new }
65
65
  it { is_expected.to eq 0 }
66
66
  end
67
67
  end
@@ -396,8 +396,6 @@ describe ActiveFedora::Associations::HasManyAssociation do
396
396
  Object.send(:remove_const, :Library)
397
397
  end
398
398
 
399
- let(:library) { Library.create }
400
-
401
399
  before do
402
400
  library.books.create(title: ["Great Book"])
403
401
  library.books.first.title = ["Better book"]
@@ -405,6 +403,7 @@ describe ActiveFedora::Associations::HasManyAssociation do
405
403
  end
406
404
 
407
405
  subject(:books) { library.books(true) }
406
+ let(:library) { Library.create }
408
407
 
409
408
  it "saves the new title" do
410
409
  expect(books.first.title).to eq ["Better book"]
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::Indexing::DescendantFetcher do
4
+ before do
5
+ class Thing < ActiveFedora::Base
6
+ property :title, predicate: ::RDF::Vocab::DC.title
7
+ end
8
+ class Source < ActiveFedora::Base
9
+ is_a_container class_name: 'Thing'
10
+ end
11
+ end
12
+ after do
13
+ Object.send(:remove_const, :Source)
14
+ Object.send(:remove_const, :Thing)
15
+ end
16
+
17
+ let(:parent) { Source.create }
18
+ let(:child) { parent.contains.create(title: ['my title']) }
19
+ let(:other_parent) { Source.create }
20
+ let!(:source_uris) { [parent, other_parent].map(&:uri).map(&:to_s) }
21
+ let!(:thing_uris) { [child].map(&:uri).map(&:to_s) }
22
+ let(:uri) { ActiveFedora.fedora.base_uri }
23
+ let(:fetcher) { described_class.new(uri) }
24
+
25
+ describe '.descendant_and_self_uris' do
26
+ context 'with default priority models' do
27
+ it 'returns uris for all objects by walking tree' do
28
+ expect(fetcher.descendant_and_self_uris).to match_array(source_uris + thing_uris)
29
+ end
30
+ end
31
+ context 'when supplying priority models' do
32
+ let(:priority_models) { ['Thing'] }
33
+ let(:fetcher) { described_class.new(uri, priority_models: priority_models) }
34
+ it 'returns priority model uris first' do
35
+ expect(fetcher.descendant_and_self_uris.slice(0..(thing_uris.count - 1))).to match_array(thing_uris)
36
+ end
37
+ end
38
+ end
39
+ describe '.descendant_and_self_uris_partitioned' do
40
+ context 'with default priority models' do
41
+ it 'returns' do
42
+ expect(fetcher.descendant_and_self_uris_partitioned.to_a).to match_array([[:priority, []], [:other, match_array(source_uris + thing_uris)]])
43
+ end
44
+ end
45
+ context 'when supplying priority models' do
46
+ let(:priority_models) { ['Thing'] }
47
+ let(:fetcher) { described_class.new(uri, priority_models: priority_models) }
48
+ it 'returns' do
49
+ expect(fetcher.descendant_and_self_uris_partitioned.to_a).to match_array([[:priority, match_array(thing_uris)], [:other, match_array(source_uris)]])
50
+ end
51
+ end
52
+ end
53
+ describe '.descendant_and_self_uris_partitioned_by_model' do
54
+ it 'returns' do
55
+ expect(fetcher.descendant_and_self_uris_partitioned_by_model.to_a).to match_array([['Source', match_array(source_uris)], ['Thing', match_array(thing_uris)]])
56
+ end
57
+ context 'excluding self' do
58
+ let(:fetcher) { described_class.new(parent.uri, exclude_self: true) }
59
+ it 'returns' do
60
+ expect(fetcher.descendant_and_self_uris_partitioned_by_model.to_a).to match_array([['Thing', [child.uri.to_s]]])
61
+ end
62
+ end
63
+ end
64
+ end
@@ -43,13 +43,33 @@ describe ActiveFedora::Base do
43
43
  end
44
44
  end
45
45
 
46
+ describe "when some of the descendants are prioritized models" do
47
+ around do |example|
48
+ class PriorityModel < ActiveFedora::Base
49
+ end
50
+ original_defaults = ActiveFedora::Indexing::DescendantFetcher.default_priority_models
51
+ ActiveFedora::Indexing::DescendantFetcher.default_priority_models = ["PriorityModel"]
52
+
53
+ example.run
54
+
55
+ ActiveFedora::Indexing::DescendantFetcher.default_priority_models = original_defaults
56
+ Object.send(:remove_const, :PriorityModel)
57
+ end
58
+ let(:ids) { ['foo', 'bar'] }
59
+ let!(:priority_models) { [PriorityModel.create, PriorityModel.create] }
60
+
61
+ it "puts prioritized model ids first" do
62
+ expect(described_class.descendant_uris(ActiveFedora.fedora.base_uri).slice(0..(priority_models.count - 1))).to contain_exactly(*priority_models.collect(&:uri).collect(&:to_s))
63
+ end
64
+ end
65
+
46
66
  describe "reindex_everything" do
47
67
  let(:ids) { ['foo', 'bar'] }
48
68
  let(:solr) { ActiveFedora::SolrService.instance.conn }
49
69
  before do
50
70
  solr.delete_by_query('*:*', params: { 'softCommit' => true })
51
71
  end
52
- it "calls update_index on every object represented in the sitemap" do
72
+ it "adds object to solr" do
53
73
  expect {
54
74
  described_class.reindex_everything
55
75
  }.to change { ActiveFedora::SolrService.query('id:foo').size }.from(0).to(1)
@@ -83,7 +103,7 @@ describe ActiveFedora::Base do
83
103
  before { gf.update(permissions_attributes: [{ id: p1.id, _destroy: 'true' }]) }
84
104
 
85
105
  it "saves to solr correctly" do
86
- result = ActiveFedora::SolrService.query("id:#{gf.id}").first['permissions_ssim']
106
+ result = ActiveFedora::SolrService.query("id:#{gf.id}", rows: 10).first['permissions_ssim']
87
107
  expect(result).to eq [p2.id]
88
108
  end
89
109
  end
@@ -114,8 +114,8 @@ describe "Indirect containers" do
114
114
  let(:reloaded) { FooHistory.find(o.id) }
115
115
 
116
116
  context "with no related_objects" do
117
- let(:o) { FooHistory.new }
118
117
  subject { o.related_objects }
118
+ let(:o) { FooHistory.new }
119
119
 
120
120
  it { is_expected.to be_empty }
121
121
  it { is_expected.to eq [] }
@@ -263,8 +263,8 @@ describe "Indirect containers" do
263
263
  let(:reloaded) { FooHistory.find(o.id) }
264
264
 
265
265
  context "with no related_objects" do
266
- let(:o) { FooHistory.new }
267
266
  subject { o.related_objects }
267
+ let(:o) { FooHistory.new }
268
268
 
269
269
  it { is_expected.to be_empty }
270
270
  it { is_expected.to eq [] }