active-fedora 9.1.2 → 9.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -0
  4. data/History.txt +90 -0
  5. data/active-fedora.gemspec +2 -2
  6. data/lib/active_fedora.rb +17 -3
  7. data/lib/active_fedora/associations.rb +77 -0
  8. data/lib/active_fedora/associations/association.rb +2 -2
  9. data/lib/active_fedora/associations/basic_contains_association.rb +52 -0
  10. data/lib/active_fedora/associations/builder/directly_contains.rb +23 -0
  11. data/lib/active_fedora/associations/builder/directly_contains_one.rb +44 -0
  12. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +2 -23
  13. data/lib/active_fedora/associations/builder/indirectly_contains.rb +26 -0
  14. data/lib/active_fedora/associations/builder/property.rb +10 -0
  15. data/lib/active_fedora/associations/collection_association.rb +42 -45
  16. data/lib/active_fedora/associations/collection_proxy.rb +6 -0
  17. data/lib/active_fedora/associations/contained_finder.rb +41 -0
  18. data/lib/active_fedora/associations/container_proxy.rb +9 -0
  19. data/lib/active_fedora/associations/contains_association.rb +20 -38
  20. data/lib/active_fedora/associations/delete_proxy.rb +28 -0
  21. data/lib/active_fedora/associations/directly_contains_association.rb +56 -0
  22. data/lib/active_fedora/associations/directly_contains_one_association.rb +113 -0
  23. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +6 -14
  24. data/lib/active_fedora/associations/has_many_association.rb +0 -3
  25. data/lib/active_fedora/associations/id_composite.rb +30 -0
  26. data/lib/active_fedora/associations/indirectly_contains_association.rb +90 -0
  27. data/lib/active_fedora/associations/rdf.rb +8 -4
  28. data/lib/active_fedora/associations/record_composite.rb +39 -0
  29. data/lib/active_fedora/attached_files.rb +1 -1
  30. data/lib/active_fedora/attributes.rb +28 -10
  31. data/lib/active_fedora/attributes/active_triple_attribute.rb +17 -0
  32. data/lib/active_fedora/attributes/om_attribute.rb +29 -0
  33. data/lib/active_fedora/attributes/rdf_datastream_attribute.rb +47 -0
  34. data/lib/active_fedora/attributes/stream_attribute.rb +46 -0
  35. data/lib/active_fedora/autosave_association.rb +2 -2
  36. data/lib/active_fedora/base.rb +3 -0
  37. data/lib/active_fedora/containers/container.rb +38 -0
  38. data/lib/active_fedora/containers/direct_container.rb +5 -0
  39. data/lib/active_fedora/containers/indirect_container.rb +7 -0
  40. data/lib/active_fedora/core.rb +4 -48
  41. data/lib/active_fedora/delegated_attribute.rb +5 -98
  42. data/lib/active_fedora/fedora.rb +1 -1
  43. data/lib/active_fedora/fedora_attributes.rb +4 -26
  44. data/lib/active_fedora/file.rb +87 -159
  45. data/lib/active_fedora/file/attributes.rb +63 -0
  46. data/lib/active_fedora/file/streaming.rb +46 -0
  47. data/lib/active_fedora/file_relation.rb +7 -0
  48. data/lib/active_fedora/identifiable.rb +87 -0
  49. data/lib/active_fedora/inbound_relation_connection.rb +21 -0
  50. data/lib/active_fedora/indexers.rb +10 -0
  51. data/lib/active_fedora/indexers/global_indexer.rb +30 -0
  52. data/lib/active_fedora/indexers/null_indexer.rb +12 -0
  53. data/lib/active_fedora/indexing/map.rb +4 -5
  54. data/lib/active_fedora/indexing_service.rb +3 -22
  55. data/lib/active_fedora/loadable_from_json.rb +8 -0
  56. data/lib/active_fedora/pathing.rb +24 -0
  57. data/lib/active_fedora/persistence.rb +15 -8
  58. data/lib/active_fedora/rdf.rb +2 -0
  59. data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
  60. data/lib/active_fedora/rdf/field_map.rb +90 -0
  61. data/lib/active_fedora/rdf/field_map_entry.rb +28 -0
  62. data/lib/active_fedora/rdf/indexing_service.rb +9 -23
  63. data/lib/active_fedora/rdf/rdf_datastream.rb +1 -2
  64. data/lib/active_fedora/reflection.rb +16 -15
  65. data/lib/active_fedora/relation/delegation.rb +15 -4
  66. data/lib/active_fedora/relation/finder_methods.rb +4 -4
  67. data/lib/active_fedora/schema.rb +26 -0
  68. data/lib/active_fedora/schema_indexing_strategy.rb +25 -0
  69. data/lib/active_fedora/simple_datastream.rb +2 -2
  70. data/lib/active_fedora/solr_query_builder.rb +3 -2
  71. data/lib/active_fedora/version.rb +1 -1
  72. data/lib/active_fedora/with_metadata.rb +1 -1
  73. data/spec/integration/associations/rdf_spec.rb +49 -0
  74. data/spec/integration/base_spec.rb +19 -0
  75. data/spec/integration/belongs_to_association_spec.rb +6 -6
  76. data/spec/integration/collection_association_spec.rb +4 -4
  77. data/spec/integration/complex_rdf_datastream_spec.rb +12 -12
  78. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +1 -1
  79. data/spec/integration/direct_container_spec.rb +254 -0
  80. data/spec/integration/directly_contains_one_association_spec.rb +102 -0
  81. data/spec/integration/file_spec.rb +16 -5
  82. data/spec/integration/has_many_associations_spec.rb +93 -58
  83. data/spec/integration/indirect_container_spec.rb +251 -0
  84. data/spec/integration/rdf_nested_attributes_spec.rb +1 -1
  85. data/spec/integration/relation_spec.rb +43 -27
  86. data/spec/spec_helper.rb +1 -1
  87. data/spec/unit/attributes_spec.rb +6 -6
  88. data/spec/unit/collection_proxy_spec.rb +28 -0
  89. data/spec/unit/file_spec.rb +1 -1
  90. data/spec/unit/files_hash_spec.rb +4 -4
  91. data/spec/unit/has_and_belongs_to_many_association_spec.rb +11 -9
  92. data/spec/unit/indexers/global_indexer_spec.rb +41 -0
  93. data/spec/unit/indexing_service_spec.rb +0 -21
  94. data/spec/unit/loadable_from_json_spec.rb +31 -0
  95. data/spec/unit/pathing_spec.rb +37 -0
  96. data/spec/unit/rdf/indexing_service_spec.rb +3 -3
  97. data/spec/unit/rdf_resource_datastream_spec.rb +26 -7
  98. data/spec/unit/schema_indexing_strategy_spec.rb +68 -0
  99. data/spec/unit/solr_query_builder_spec.rb +1 -1
  100. data/spec/unit/solr_service_spec.rb +1 -1
  101. metadata +49 -8
@@ -7,7 +7,7 @@ describe "Nesting attribute behavior of RDF resources" do
7
7
  end
8
8
 
9
9
  class ComplexResource < ActiveFedora::Base
10
- property :topic, predicate: DummyMADS.Topic, class_name: "Topic"
10
+ property :topic, predicate: DummyMADS.Topic, class_name: "ComplexResource::Topic"
11
11
 
12
12
  class Topic < ActiveTriples::Resource
13
13
  property :subject, predicate: ::RDF::DC.subject
@@ -3,10 +3,13 @@ require 'spec_helper'
3
3
  describe ActiveFedora::Base do
4
4
  before :all do
5
5
  class Library < ActiveFedora::Base
6
- has_many :books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
6
+ has_many :books
7
+ end
8
+ class Book < ActiveFedora::Base
9
+ belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
7
10
  end
8
- class Book < ActiveFedora::Base; end
9
11
  end
12
+
10
13
  after :all do
11
14
  Object.send(:remove_const, :Library)
12
15
  Object.send(:remove_const, :Book)
@@ -18,40 +21,53 @@ describe ActiveFedora::Base do
18
21
  expect(subject.class).to be ActiveFedora::Relation
19
22
  end
20
23
 
21
- before :each do
22
- Library.create
23
- @library = Library.create
24
- end
25
-
26
- let(:library1) { @library }
27
-
28
- describe "is cached" do
24
+ context "when some records exist" do
29
25
  before do
30
- subject.to_a # trigger initial load
26
+ Library.create
31
27
  end
32
28
 
33
- it "should be loaded" do
34
- expect(subject).to be_loaded
29
+ let!(:library1) { Library.create }
30
+
31
+ describe "is cached" do
32
+ before do
33
+ subject.to_a # trigger initial load
34
+ end
35
+
36
+ it "should be loaded" do
37
+ expect(subject).to be_loaded
38
+ end
39
+ it "shouldn't reload" do
40
+ expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
41
+ subject[0]
42
+ end
35
43
  end
36
- it "shouldn't reload" do
37
- expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
38
- subject[0]
44
+
45
+ describe "#find" do
46
+ it "should find one of them" do
47
+ expect(subject.find(library1.id)).to eq library1
48
+ end
49
+ it "should find with a block" do
50
+ expect(subject.find { |l| l.id == library1.id}).to eq library1
51
+ end
39
52
  end
40
- end
41
53
 
42
- describe "#find" do
43
- it "should find one of them" do
44
- expect(subject.find(library1.id)).to eq library1
54
+ describe "#select" do
55
+ it "should find with a block" do
56
+ expect(subject.select { |l| l.id == library1.id}).to eq [library1]
57
+ end
45
58
  end
46
- it "should find with a block" do
47
- expect(subject.find { |l| l.id == library1.id}).to eq library1
59
+
60
+ context "unpermitted methods" do
61
+ it "excludes them" do
62
+ expect{ subject.sort! }.to raise_error NoMethodError
63
+ end
48
64
  end
49
- end
50
65
 
51
- describe "#select" do
52
- it "should find with a block" do
53
- expect(subject.select { |l| l.id == library1.id}).to eq [library1]
66
+ context "when limit is applied" do
67
+ subject { Library.create books: [Book.create, Book.create] }
68
+ it "limits the number of books" do
69
+ expect(subject.books.limit(1).size).to eq 1
70
+ end
54
71
  end
55
72
  end
56
73
  end
57
-
@@ -17,7 +17,7 @@ require 'rspec'
17
17
  require 'rspec/its'
18
18
  require 'equivalent-xml/rspec_matchers'
19
19
  require 'logger'
20
- require 'byebug' unless ENV['TRAVIS']
20
+ require 'pry' unless ENV['TRAVIS']
21
21
 
22
22
  ActiveFedora::Base.logger = Logger.new(STDERR)
23
23
  ActiveFedora::Base.logger.level = Logger::WARN
@@ -407,12 +407,14 @@ describe ActiveFedora::Base do
407
407
 
408
408
  subject { BarHistory4.new }
409
409
 
410
- it "should raise an error on get" do
411
- expect {subject.description}.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
410
+ let(:error_message) { "Undefined file: `rdfish' in property description" }
411
+
412
+ it "raises an error on get" do
413
+ expect { subject.description }.to raise_error(ArgumentError, error_message)
412
414
  end
413
415
 
414
- it "should raise an error on set" do
415
- expect { subject.description = ['Neat'] }.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
416
+ it "raises an error on set" do
417
+ expect { subject.description = ['Neat'] }.to raise_error(ArgumentError, error_message)
416
418
  end
417
419
 
418
420
  describe ".datastream_class_for_name" do
@@ -520,5 +522,3 @@ describe ActiveFedora::Base do
520
522
  end
521
523
  end
522
524
  end
523
-
524
-
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Associations::CollectionProxy do
4
+
5
+ before do
6
+ class Book < ActiveFedora::Base
7
+ end
8
+ class Page < ActiveFedora::Base
9
+ end
10
+ end
11
+
12
+ after do
13
+ Object.send(:remove_const, :Page)
14
+ Object.send(:remove_const, :Book)
15
+ end
16
+
17
+ describe "#spawn" do
18
+
19
+ let(:reflection) { Book.create_reflection(:has_many, :pages, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection }, Book) }
20
+ let(:association) { ActiveFedora::Associations::HasManyAssociation.new(Book.new, reflection ) }
21
+ let(:proxy) { described_class.new(association) }
22
+
23
+ subject { proxy.spawn }
24
+ it { is_expected.to be_instance_of ActiveFedora::Relation }
25
+
26
+ end
27
+
28
+ end
@@ -228,7 +228,7 @@ describe ActiveFedora::Datastream do
228
228
  context "when there is nothing to save" do
229
229
  it "should not write" do
230
230
  expect(file.ldp_source).not_to receive(:create)
231
- expect(file.save).to be true
231
+ expect(file.save).to be false
232
232
  end
233
233
  end
234
234
  end
@@ -2,18 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::FilesHash do
4
4
  before do
5
- class Container; end
6
- allow(Container).to receive(:child_resource_reflections).and_return(file: reflection)
5
+ class FilesContainer; end
6
+ allow(FilesContainer).to receive(:child_resource_reflections).and_return(file: reflection)
7
7
  allow(container).to receive(:association).with(:file).and_return(association)
8
8
  allow(container).to receive(:undeclared_files).and_return([])
9
9
  end
10
10
 
11
- after { Object.send(:remove_const, :Container) }
11
+ after { Object.send(:remove_const, :FilesContainer) }
12
12
 
13
13
  let(:reflection) { double('reflection') }
14
14
  let(:association) { double('association', reader: object) }
15
15
  let(:object) { double('object') }
16
- let(:container) { Container.new }
16
+ let(:container) { FilesContainer.new }
17
17
 
18
18
  subject { ActiveFedora::FilesHash.new(container) }
19
19
 
@@ -42,17 +42,19 @@ describe ActiveFedora::Associations::HasAndBelongsToManyAssociation do
42
42
 
43
43
  describe "finding member" do
44
44
  let(:ids) { (0..15).map(&:to_s) }
45
- let(:query1) { ids.slice(0,10).map {|i| "_query_:\"{!raw f=id}#{i}\""}.join(" OR ") }
46
- let(:query2) { ids.slice(10,10).map {|i| "_query_:\"{!raw f=id}#{i}\""}.join(" OR ") }
47
-
48
- it "should call solr query multiple times" do
49
- reflection = Book.create_reflection(:has_and_belongs_to_many, :pages, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection, solr_page_size: 10}, Book)
45
+ let(:reflection) { Book.create_reflection(:has_and_belongs_to_many, :pages, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection }, Book) }
46
+ let(:association) { ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, reflection) }
47
+ it "calls ActiveFedora::Base.find" do
50
48
  expect(subject).to receive(:[]).with('page_ids').and_return(ids)
51
- expect(ActiveFedora::SolrService).to receive(:query).with(query1, rows: 10).and_return([])
52
- expect(ActiveFedora::SolrService).to receive(:query).with(query2, rows: 10).and_return([])
49
+ expect(ActiveFedora::Base).to receive(:find).with(ids)
50
+ association.send(:find_target)
51
+ end
52
+ end
53
53
 
54
- ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, reflection)
55
- ac.find_target
54
+ describe "solr page size option" do
55
+ it "sends a deprecation warning" do
56
+ expect(Deprecation).to receive(:warn)
57
+ Book.has_and_belongs_to_many(:pages, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isMemberOfCollection, solr_page_size: 123)
56
58
  end
57
59
  end
58
60
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::Indexers::GlobalIndexer do
4
+ subject { described_class.new(index_types) }
5
+ let(:index_types) {}
6
+
7
+ describe "#new" do
8
+ # The global indexer acts as both an indexer factory and an indexer, since
9
+ # the property doesn't matter.
10
+ it "should return itself" do
11
+ expect(subject.new("bla")).to eq subject
12
+ end
13
+ end
14
+ describe "#index" do
15
+ let(:index_obj) { instance_double(ActiveFedora::Indexing::Map::IndexObject, as: nil) }
16
+ context "with one index type" do
17
+ let(:index_types) { :symbol }
18
+ it "should pass that to index_obj" do
19
+ subject.index(index_obj)
20
+
21
+ expect(index_obj).to have_received(:as).with(:symbol)
22
+ end
23
+ end
24
+ context "with multiple index types" do
25
+ let(:index_types) { [:symbol, :stored_searchable] }
26
+ it "should pass that to index_obj" do
27
+ subject.index(index_obj)
28
+
29
+ expect(index_obj).to have_received(:as).with(:symbol, :stored_searchable)
30
+ end
31
+ end
32
+ context "with no index types" do
33
+ subject { described_class.new }
34
+ it "should not pass anything to index_obj" do
35
+ subject.index(index_obj)
36
+
37
+ expect(index_obj).not_to have_received(:as)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -4,27 +4,6 @@ describe ActiveFedora::IndexingService do
4
4
  let(:indexer) { described_class.new(object) }
5
5
  let(:object) { ActiveFedora::Base.new }
6
6
 
7
- describe "#solrize_relationships" do
8
- subject { indexer.send(:solrize_relationships) }
9
- let(:person_reflection) { double('person', foreign_key: 'person_id', kind_of?: true, solr_key: member_of) }
10
- let(:location_reflection) { double('location', foreign_key: 'location_id', kind_of?: true, solr_key: part_of) }
11
- let(:reflections) { { 'person' => person_reflection, 'location' => location_reflection } }
12
-
13
- let(:member_of) { ActiveFedora::SolrQueryBuilder.solr_name("info:fedora/fedora-system:def/relations-external#isMemberOf", :symbol) }
14
- let(:part_of) { ActiveFedora::SolrQueryBuilder.solr_name("info:fedora/fedora-system:def/relations-external#isPartOf", :symbol) }
15
-
16
- before do
17
- expect(object).to receive(:[]).with('person_id').and_return('info:fedora/demo:10')
18
- expect(object).to receive(:[]).with('location_id').and_return('info:fedora/demo:11')
19
- expect(object.class).to receive(:reflections).and_return(reflections)
20
- end
21
-
22
- it "should serialize the relationships into a Hash" do
23
- expect(subject[member_of]).to eq "info:fedora/demo:10"
24
- expect(subject[part_of]).to eq "info:fedora/demo:11"
25
- end
26
- end
27
-
28
7
  describe "#generate_solr_document" do
29
8
  context "when no block is passed" do
30
9
  subject { indexer.generate_solr_document }
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::LoadableFromJson::SolrBackedResource do
4
+ before do
5
+ class Foo < ActiveFedora::Base
6
+ belongs_to :bar, predicate: ::RDF::DC.extent
7
+ end
8
+
9
+ class Bar < ActiveFedora::Base
10
+ end
11
+ end
12
+
13
+ after do
14
+ Object.send(:remove_const, :Foo)
15
+ Object.send(:remove_const, :Bar)
16
+ end
17
+
18
+ let(:resource) { described_class.new(Foo) }
19
+
20
+ before do
21
+ resource.insert [nil, ::RDF::DC.extent, RDF::URI('http://example.org/123')]
22
+ end
23
+
24
+ describe "#query" do
25
+ subject { resource.query(predicate: ::RDF::DC.extent) }
26
+
27
+ it "is enumerable" do
28
+ expect(subject.map { |g| g.object }).to eq [RDF::URI('http://example.org/123')]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ describe ".uri_prefix" do
5
+ let(:path) { "foo" }
6
+
7
+ before do
8
+ class FooHistory < ActiveFedora::Base
9
+ def uri_prefix
10
+ "foo"
11
+ end
12
+ property :title, predicate: ::RDF::DC.title
13
+ end
14
+ end
15
+
16
+ after do
17
+ Object.send(:remove_const, :FooHistory)
18
+ end
19
+
20
+ subject { FooHistory.new(title: ["Root foo"]) }
21
+
22
+ it { is_expected.to have_uri_prefix }
23
+
24
+ it "uses the root path in the uri" do
25
+ expect(subject.uri_prefix).to eql path
26
+ end
27
+
28
+ context "when the object is saved" do
29
+ before { subject.save }
30
+
31
+ it "should persist the path in the uri" do
32
+ expect(subject.uri.to_s).to include(path)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -78,12 +78,12 @@ describe ActiveFedora::RDF::IndexingService do
78
78
  end
79
79
 
80
80
  it "should return the right values" do
81
- expect(fields[:related_url][:values]).to eq ["http://example.org/blogtastic/"]
82
- expect(fields[:based_near][:values]).to eq ["Tacoma, WA", "Renton, WA"]
81
+ expect(fields["related_url"].values).to eq ["http://example.org/blogtastic/"]
82
+ expect(fields["based_near"].values).to eq ["Tacoma, WA", "Renton, WA"]
83
83
  end
84
84
 
85
85
  it "should return the right type information" do
86
- expect(fields[:created][:type]).to eq :date
86
+ expect(fields["created"].type).to eq :date
87
87
  end
88
88
  end
89
89
 
@@ -42,10 +42,8 @@ describe ActiveFedora::RDFDatastream do
42
42
  subject { DummyAsset.new }
43
43
 
44
44
  describe "#to_solr" do
45
- before do
46
- subject.descMetadata.title = "bla"
47
- subject.descMetadata.license = DummySubnode.new('http://example.org/blah')
48
- end
45
+
46
+ before { subject.descMetadata.title = "bla" }
49
47
 
50
48
  it "should not be blank" do
51
49
  expect(subject.to_solr).not_to be_blank
@@ -55,9 +53,31 @@ describe ActiveFedora::RDFDatastream do
55
53
  expect(subject.to_solr["desc_metadata__title_teim"]).to eq ["bla"]
56
54
  end
57
55
 
58
- it "should solrize uris" do
59
- expect(subject.to_solr["desc_metadata__license_teim"]).to eq ['http://example.org/blah']
56
+ context "with ActiveFedora::Base resources" do
57
+
58
+ let(:dummy_asset) { DummyAsset.new }
59
+
60
+ before do
61
+ allow(dummy_asset).to receive(:uri).and_return("http://foo")
62
+ subject.descMetadata.creator = dummy_asset
63
+ end
64
+
65
+ it "should solrize objects" do
66
+ expect(subject.to_solr["desc_metadata__creator_teim"]).to eq ["http://foo"]
67
+ end
68
+
60
69
  end
70
+
71
+ context "with ActiveTriples resources" do
72
+
73
+ before { subject.descMetadata.license = DummySubnode.new('http://example.org/blah') }
74
+
75
+ it "should solrize uris" do
76
+ expect(subject.to_solr["desc_metadata__license_teim"]).to eq ['http://example.org/blah']
77
+ end
78
+
79
+ end
80
+
61
81
  end
62
82
 
63
83
  describe "delegation" do
@@ -148,7 +168,6 @@ describe ActiveFedora::RDFDatastream do
148
168
  end
149
169
  context "persisted to repository" do
150
170
  before do
151
- DummySubnode.configure :repository => :default
152
171
  allow_any_instance_of(DummySubnode).to receive(:repository).and_return(RDF::Repository.new)
153
172
  dummy = DummySubnode.new(RDF::URI('http://example.org/dummy/blah'))
154
173
  dummy.title = 'subbla'
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::SchemaIndexingStrategy do
4
+ subject { described_class.new(property_indexer_factory) }
5
+
6
+ describe "#apply" do
7
+ let(:property) do
8
+ p = object_double(ActiveTriples::Property.new(:name => nil))
9
+ allow(p).to receive(:to_h).and_return(options)
10
+ allow(p).to receive(:name).and_return(name)
11
+ p
12
+ end
13
+ let(:name) { "Name" }
14
+ let(:options) do
15
+ {
16
+ :class_name => "Test"
17
+ }
18
+ end
19
+ let(:object) do
20
+ o = object_double(ActiveFedora::Base)
21
+ allow(o).to receive(:property).and_yield(index_configuration)
22
+ o
23
+ end
24
+ let(:index_configuration) do
25
+ d = double("index configuration")
26
+ allow(d).to receive(:as)
27
+ d
28
+ end
29
+ let(:property_indexer) do
30
+ p = double("property_indexer")
31
+ allow(p).to receive(:index).with(anything) do |index|
32
+ index.as(*Array.wrap(index_types))
33
+ end
34
+ p
35
+ end
36
+ let(:property_indexer_factory) do
37
+ p = double("property indexer factory")
38
+ allow(p).to receive(:new).with(anything).and_return(property_indexer)
39
+ p
40
+ end
41
+ let(:index_types) {}
42
+ context "with no index types" do
43
+ subject { described_class.new }
44
+ it "should not try to index it" do
45
+ subject.apply(object, property)
46
+
47
+ expect(object).to have_received(:property).with(property.name, property.to_h)
48
+ expect(index_configuration).not_to have_received(:as)
49
+ end
50
+ end
51
+ context "with one index type" do
52
+ let(:index_types) { :symbol }
53
+ it "should apply that one" do
54
+ subject.apply(object, property)
55
+
56
+ expect(index_configuration).to have_received(:as).with(:symbol)
57
+ end
58
+ end
59
+ context "with multiple index types" do
60
+ let(:index_types) { [:symbol, :stored_searchable] }
61
+ it "should apply all of them" do
62
+ subject.apply(object, property)
63
+
64
+ expect(index_configuration).to have_received(:as).with(:symbol, :stored_searchable)
65
+ end
66
+ end
67
+ end
68
+ end