active-fedora 6.7.8 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +75 -69
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +59 -59
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Model do
|
4
|
-
|
5
|
-
before(:all) do
|
4
|
+
|
5
|
+
before(:all) do
|
6
6
|
module ModelIntegrationSpec
|
7
7
|
class Basic < ActiveFedora::Base
|
8
|
-
has_metadata :name =>
|
9
|
-
m.field
|
10
|
-
m.field
|
11
|
-
m.field
|
8
|
+
has_metadata :name => 'properties', :type => ActiveFedora::SimpleDatastream do |m|
|
9
|
+
m.field 'foo', :string
|
10
|
+
m.field 'bar', :string
|
11
|
+
m.field 'baz', :string
|
12
12
|
end
|
13
13
|
|
14
14
|
delegate_to :properties, [:foo, :bar, :baz], multiple: true
|
@@ -18,50 +18,48 @@ describe ActiveFedora::Model do
|
|
18
18
|
doc[ActiveFedora::SolrService.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrService.solr_name('foo', type: :string)]
|
19
19
|
doc
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
after(:all) do
|
28
28
|
Object.send(:remove_const, :ModelIntegrationSpec)
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
describe
|
33
|
-
let!(:instance1){ ModelIntegrationSpec::Basic.create!(:foo=>'Beta', :bar=>'Chips')}
|
34
|
-
let!(:instance2){ ModelIntegrationSpec::Basic.create!(:foo=>'Alpha', :bar=>'Peanuts')}
|
35
|
-
let!(:instance3){ ModelIntegrationSpec::Basic.create!(:foo=>'Sigma', :bar=>'Peanuts')}
|
32
|
+
describe 'with multiple objects' do
|
33
|
+
let!(:instance1){ ModelIntegrationSpec::Basic.create!(:foo => 'Beta', :bar => 'Chips')}
|
34
|
+
let!(:instance2){ ModelIntegrationSpec::Basic.create!(:foo => 'Alpha', :bar => 'Peanuts')}
|
35
|
+
let!(:instance3){ ModelIntegrationSpec::Basic.create!(:foo => 'Sigma', :bar => 'Peanuts')}
|
36
36
|
|
37
37
|
after { ModelIntegrationSpec::Basic.delete_all }
|
38
38
|
|
39
39
|
subject { ModelIntegrationSpec::Basic.where(bar: 'Peanuts') }
|
40
40
|
|
41
|
-
it
|
42
|
-
subject.map(&:id).
|
41
|
+
it 'should map' do
|
42
|
+
expect(subject.map(&:id)).to eq([instance2.id, instance3.id])
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
subject.collect(&:id).
|
45
|
+
it 'should collect' do
|
46
|
+
expect(subject.collect(&:id)).to eq([instance2.id, instance3.id])
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'should have each' do
|
50
50
|
t = double
|
51
|
-
t.
|
51
|
+
expect(t).to receive(:foo).twice
|
52
52
|
subject.each { t.foo }
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
56
|
-
expect(subject.all? { |t| t.foo == ['Alpha']}).to
|
57
|
-
expect(subject.all? { |t| t.bar == ['Peanuts']}).to
|
55
|
+
it 'should have all?' do
|
56
|
+
expect(subject.all? { |t| t.foo == ['Alpha']}).to be_falsey
|
57
|
+
expect(subject.all? { |t| t.bar == ['Peanuts']}).to be_truthy
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
61
|
-
expect(subject.include?(instance1)).to
|
62
|
-
expect(subject.include?(instance2)).to
|
60
|
+
it 'should have include?' do
|
61
|
+
expect(subject.include?(instance1)).to be_falsey
|
62
|
+
expect(subject.include?(instance2)).to be_truthy
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
|
-
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'active_fedora'
|
4
|
-
require
|
4
|
+
require 'rexml/document'
|
5
5
|
|
6
6
|
|
7
7
|
describe ActiveFedora::RelsExtDatastream do
|
8
|
-
|
8
|
+
|
9
9
|
before(:all) do
|
10
|
-
@sample_relationships_hash = Hash.new(:is_member_of => [
|
10
|
+
@sample_relationships_hash = Hash.new(:is_member_of => ['info:fedora/demo:5', 'info:fedora/demo:10'])
|
11
11
|
@sample_xml_string = <<-EOS
|
12
12
|
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
13
13
|
<rdf:Description rdf:about="info:fedora/changeme:475">
|
@@ -16,17 +16,17 @@ describe ActiveFedora::RelsExtDatastream do
|
|
16
16
|
</rdf:Description>
|
17
17
|
</rdf:RDF>
|
18
18
|
EOS
|
19
|
-
|
19
|
+
|
20
20
|
@sample_xml = REXML::Document.new(@sample_xml_string)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
before(:each) do
|
24
24
|
@test_object = ActiveFedora::Base.new
|
25
25
|
@test_datastream = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
26
26
|
@test_datastream.model = @test_object
|
27
27
|
@test_object.save
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
after(:each) do
|
31
31
|
begin
|
32
32
|
@test_object.delete
|
@@ -49,34 +49,34 @@ describe ActiveFedora::RelsExtDatastream do
|
|
49
49
|
rescue
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
|
54
54
|
describe '#serialize!' do
|
55
|
-
|
56
|
-
it
|
55
|
+
|
56
|
+
it 'should generate new rdf/xml as the datastream content' do
|
57
57
|
@test_object.add_datastream(@test_datastream)
|
58
|
-
@test_object.add_relationship(:is_member_of,
|
59
|
-
@test_object.add_relationship(:is_member_of,
|
58
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:5')
|
59
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:10')
|
60
60
|
rexml1 = REXML::Document.new(@test_datastream.to_rels_ext())
|
61
61
|
@test_datastream.serialize!
|
62
|
-
rexml2 = REXML::Document.new(@test_object.datastreams[
|
63
|
-
rexml1.root.elements[
|
62
|
+
rexml2 = REXML::Document.new(@test_object.datastreams['RELS-EXT'].content)
|
63
|
+
expect(rexml1.root.elements['rdf:Description'].inspect).to eql(rexml2.root.elements['rdf:Description'].inspect)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
67
|
-
|
68
|
-
it
|
67
|
+
|
68
|
+
it 'should load relationships from fedora into parent object' do
|
69
69
|
class SpecNode; include ActiveFedora::SemanticNode; end
|
70
|
-
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].each_key do |p|
|
70
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].each_key do |p|
|
71
71
|
@test_object.add_relationship(p, "info:fedora/demo:#{rand(100)}")
|
72
72
|
end
|
73
73
|
@test_object.save
|
74
74
|
# make sure that _something_ was actually added to the object's relationships hash
|
75
|
-
@test_object.ids_for_outbound(:is_member_of).size.
|
75
|
+
expect(@test_object.ids_for_outbound(:is_member_of).size).to eq(1)
|
76
76
|
new_rels = ActiveFedora::Base.find(@test_object.pid).relationships
|
77
77
|
# This stopped working, need to push an issue into the rdf library. (when dumping ntriples, the order of assertions changed)
|
78
78
|
#new_rels.should == @test_object.relationships
|
79
|
-
new_rels.dump(:rdfxml).
|
79
|
+
expect(new_rels.dump(:rdfxml)).to eq(@test_object.relationships.dump(:rdfxml))
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
before(:each) do
|
3
|
+
describe 'scoped queries' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
6
|
module ModelIntegrationSpec
|
7
7
|
class Basic < ActiveFedora::Base
|
8
|
-
has_metadata :name =>
|
9
|
-
m.field
|
10
|
-
m.field
|
11
|
-
m.field
|
8
|
+
has_metadata :name => 'properties', :type => ActiveFedora::SimpleDatastream do |m|
|
9
|
+
m.field 'foo', :string
|
10
|
+
m.field 'bar', :string
|
11
|
+
m.field 'baz', :string
|
12
12
|
end
|
13
13
|
|
14
14
|
delegate_to :properties, [:foo, :bar, :baz], multiple: true
|
@@ -18,81 +18,80 @@ describe "scoped queries" do
|
|
18
18
|
doc[ActiveFedora::SolrService.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrService.solr_name('foo', type: :string)]
|
19
19
|
doc
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
after(:each) do
|
28
28
|
Object.send(:remove_const, :ModelIntegrationSpec)
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
describe
|
32
|
+
describe 'When there is one object in the store' do
|
33
33
|
let!(:test_instance) { ModelIntegrationSpec::Basic.create!()}
|
34
34
|
|
35
35
|
after do
|
36
36
|
test_instance.delete
|
37
37
|
end
|
38
|
-
|
39
|
-
describe
|
40
|
-
it
|
38
|
+
|
39
|
+
describe '.all' do
|
40
|
+
it 'should return an array of instances of the calling Class' do
|
41
41
|
result = ModelIntegrationSpec::Basic.all
|
42
|
-
result.
|
42
|
+
expect(result).to be_instance_of(Array)
|
43
43
|
# this test is meaningless if the array length is zero
|
44
|
-
result.length.
|
44
|
+
expect(result.length).to be > 0
|
45
45
|
result.each do |obj|
|
46
|
-
obj.class.
|
46
|
+
expect(obj.class).to eq(ModelIntegrationSpec::Basic)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
52
|
-
it
|
53
|
-
ModelIntegrationSpec::Basic.first.
|
51
|
+
describe '.first' do
|
52
|
+
it 'should return one instance of the calling class' do
|
53
|
+
expect(ModelIntegrationSpec::Basic.first).to eq(test_instance)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe
|
59
|
-
let!(:test_instance1) { ModelIntegrationSpec::Basic.create!(:foo=>'Beta', :bar=>'Chips')}
|
60
|
-
let!(:test_instance2) { ModelIntegrationSpec::Basic.create!(:foo=>'Alpha', :bar=>'Peanuts')}
|
61
|
-
let!(:test_instance3) { ModelIntegrationSpec::Basic.create!(:foo=>'Sigma', :bar=>'Peanuts')}
|
58
|
+
describe 'with multiple objects' do
|
59
|
+
let!(:test_instance1) { ModelIntegrationSpec::Basic.create!(:foo => 'Beta', :bar => 'Chips')}
|
60
|
+
let!(:test_instance2) { ModelIntegrationSpec::Basic.create!(:foo => 'Alpha', :bar => 'Peanuts')}
|
61
|
+
let!(:test_instance3) { ModelIntegrationSpec::Basic.create!(:foo => 'Sigma', :bar => 'Peanuts')}
|
62
62
|
|
63
63
|
after do
|
64
64
|
test_instance1.delete
|
65
65
|
test_instance2.delete
|
66
66
|
test_instance3.delete
|
67
67
|
end
|
68
|
-
it
|
69
|
-
ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('foo', type: :string)=> 'Beta').
|
70
|
-
ModelIntegrationSpec::Basic.where('foo' => 'Beta').
|
68
|
+
it 'should query' do
|
69
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('foo', type: :string) => 'Beta')).to eq([test_instance1])
|
70
|
+
expect(ModelIntegrationSpec::Basic.where('foo' => 'Beta')).to eq([test_instance1])
|
71
71
|
end
|
72
|
-
it
|
73
|
-
ModelIntegrationSpec::Basic.order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').
|
72
|
+
it 'should order' do
|
73
|
+
expect(ModelIntegrationSpec::Basic.order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc')).to eq([test_instance2, test_instance1, test_instance3])
|
74
74
|
end
|
75
|
-
it
|
76
|
-
ModelIntegrationSpec::Basic.limit(1).
|
75
|
+
it 'should limit' do
|
76
|
+
expect(ModelIntegrationSpec::Basic.limit(1)).to eq([test_instance1])
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').limit(1).
|
79
|
+
it 'should chain queries' do
|
80
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').limit(1)).to eq([test_instance2])
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
84
|
-
ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').count.
|
83
|
+
it 'should chain count' do
|
84
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').count).to eq(2)
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "when one of the objects in solr isn't in fedora" do
|
88
|
-
it
|
89
|
-
ModelIntegrationSpec::Basic.
|
90
|
-
ModelIntegrationSpec::Basic.
|
91
|
-
ModelIntegrationSpec::Basic.
|
92
|
-
ActiveFedora::Relation.logger.
|
93
|
-
ModelIntegrationSpec::Basic.all.
|
88
|
+
it 'should log an error' do
|
89
|
+
expect(ModelIntegrationSpec::Basic).to receive(:find_one).with(test_instance1.pid, nil).and_call_original
|
90
|
+
expect(ModelIntegrationSpec::Basic).to receive(:find_one).with(test_instance2.pid, nil).and_raise(ActiveFedora::ObjectNotFoundError)
|
91
|
+
expect(ModelIntegrationSpec::Basic).to receive(:find_one).with(test_instance3.pid, nil).and_call_original
|
92
|
+
expect(ActiveFedora::Relation.logger).to receive(:error).with("When trying to find_each #{test_instance2.pid}, encountered an ObjectNotFoundError. Solr may be out of sync with Fedora")
|
93
|
+
expect(ModelIntegrationSpec::Basic.all).to eq([test_instance1, test_instance3])
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
@@ -22,14 +22,14 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
describe 'with matching solr document' do
|
25
|
-
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>pid).first }
|
25
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id => pid).first }
|
26
26
|
it 'it casts the SOLR document and casts into an AF::Base object' do
|
27
27
|
expect(subject.object).to eq(active_fedora_object)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
describe 'with a mismatching solr document' do
|
31
31
|
let(:mismatching_pid) { @test_object2.pid }
|
32
|
-
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>mismatching_pid).first }
|
32
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id => mismatching_pid).first }
|
33
33
|
it 'it raise ObjectNotFoundError' do
|
34
34
|
expect {
|
35
35
|
subject
|
@@ -47,7 +47,7 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
describe 'with matching solr document' do
|
50
|
-
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>pid).first }
|
50
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id => pid).first }
|
51
51
|
it 'it raise ObjectNotFoundError' do
|
52
52
|
expect {
|
53
53
|
subject.object
|
@@ -56,7 +56,7 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
56
56
|
end
|
57
57
|
describe 'with a mismatching solr document' do
|
58
58
|
let(:mismatching_pid) { @test_object2.pid }
|
59
|
-
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>mismatching_pid).first }
|
59
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id => mismatching_pid).first }
|
60
60
|
it 'it raise ObjectNotFoundError' do
|
61
61
|
expect {
|
62
62
|
subject
|
@@ -3,23 +3,23 @@ require 'spec_helper'
|
|
3
3
|
require 'active_fedora'
|
4
4
|
|
5
5
|
describe ActiveFedora::SolrService do
|
6
|
-
describe
|
6
|
+
describe '#reify_solr_results' do
|
7
7
|
before(:all) do
|
8
8
|
class FooObject < ActiveFedora::Base
|
9
9
|
def self.pid_namespace
|
10
|
-
|
10
|
+
'foo'
|
11
11
|
end
|
12
|
-
|
13
|
-
has_metadata :name =>
|
12
|
+
|
13
|
+
has_metadata :name => 'descMetadata', :type => ActiveFedora::QualifiedDublinCoreDatastream
|
14
14
|
end
|
15
15
|
@test_object = ActiveFedora::Base.new
|
16
16
|
@test_object.label = 'test_object'
|
17
17
|
@foo_object = FooObject.new
|
18
18
|
@foo_object.label = 'foo_object'
|
19
|
-
attributes = {
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
attributes = {'language' => {0 => 'Italian'},
|
20
|
+
'creator' => {0 => 'Linguist, A.'},
|
21
|
+
'geography' => {0 => 'Italy'},
|
22
|
+
'title' => {0 => 'Italian and Spanish: A Comparison of Common Phrases'}}
|
23
23
|
@foo_object.descMetadata.update_indexed_attributes(attributes)
|
24
24
|
@test_object.save
|
25
25
|
@foo_object.save
|
@@ -35,78 +35,78 @@ describe ActiveFedora::SolrService do
|
|
35
35
|
@foo_object.delete
|
36
36
|
Object.send(:remove_const, :FooObject)
|
37
37
|
end
|
38
|
-
it
|
38
|
+
it 'should return an array of objects that are of the class stored in active_fedora_model_s' do
|
39
39
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
40
40
|
solr_result = ActiveFedora::SolrService.query(query)
|
41
41
|
result = ActiveFedora::SolrService.reify_solr_results(solr_result)
|
42
|
-
result.length.
|
42
|
+
expect(result.length).to eq(2)
|
43
43
|
result.each do |r|
|
44
|
-
(r.class == ActiveFedora::Base || r.class == FooObject).
|
44
|
+
expect(r.class == ActiveFedora::Base || r.class == FooObject).to be_truthy
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it 'should load objects from solr data if a :load_from_solr option is passed in' do
|
49
49
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
50
50
|
solr_result = ActiveFedora::SolrService.query(query)
|
51
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
52
|
-
result.length.
|
51
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result, {:load_from_solr => true})
|
52
|
+
expect(result.length).to eq(2)
|
53
53
|
result.each do |r|
|
54
|
-
r.inner_object.
|
55
|
-
[ActiveFedora::Base, FooObject].
|
56
|
-
['test_object','foo_object'].
|
57
|
-
@test_object.inner_object.profile.
|
58
|
-
@foo_object.inner_object.profile.
|
59
|
-
@foo_object.datastreams['descMetadata'].profile.
|
60
|
-
@foo_object.datastreams['descMetadata'].content.
|
54
|
+
expect(r.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
55
|
+
expect([ActiveFedora::Base, FooObject]).to include(r.class)
|
56
|
+
expect(['test_object', 'foo_object']).to include(r.label)
|
57
|
+
expect(@test_object.inner_object.profile).to eq(@profiles['test'])
|
58
|
+
expect(@foo_object.inner_object.profile).to eq(@profiles['foo'])
|
59
|
+
expect(@foo_object.datastreams['descMetadata'].profile).to eq(@profiles['foo_descMetadata'])
|
60
|
+
expect(@foo_object.datastreams['descMetadata'].content).to be_equivalent_to(@foo_content)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it 'should instantiate all datastreams in the solr doc, even ones undeclared by the class' do
|
65
|
-
obj = ActiveFedora::Base.load_instance_from_solr @foo_object.pid
|
66
|
-
obj.datastreams.keys.
|
65
|
+
obj = ActiveFedora::Base.load_instance_from_solr @foo_object.pid
|
66
|
+
expect(obj.datastreams.keys).to include('descMetadata')
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it 'should #reify a lightweight object as a new instance' do
|
70
70
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
71
71
|
solr_result = ActiveFedora::SolrService.query(query)
|
72
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
72
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result, {:load_from_solr => true})
|
73
73
|
solr_foo = result.first
|
74
74
|
real_foo = solr_foo.reify
|
75
|
-
solr_foo.inner_object.
|
76
|
-
real_foo.inner_object.
|
77
|
-
solr_foo.label.
|
78
|
-
real_foo.label.
|
75
|
+
expect(solr_foo.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
76
|
+
expect(real_foo.inner_object).to be_a(ActiveFedora::DigitalObject)
|
77
|
+
expect(solr_foo.label).to eq('foo_object')
|
78
|
+
expect(real_foo.label).to eq('foo_object')
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it 'should #reify! a lightweight object within the same instance' do
|
82
82
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
83
83
|
solr_result = ActiveFedora::SolrService.query(query)
|
84
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
84
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result, {:load_from_solr => true})
|
85
85
|
solr_foo = result.first
|
86
|
-
solr_foo.inner_object.
|
86
|
+
expect(solr_foo.inner_object).to be_a(ActiveFedora::SolrDigitalObject)
|
87
87
|
solr_foo.reify!
|
88
|
-
solr_foo.inner_object.
|
89
|
-
solr_foo.label.
|
88
|
+
expect(solr_foo.inner_object).to be_a(ActiveFedora::DigitalObject)
|
89
|
+
expect(solr_foo.label).to eq('foo_object')
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
it 'should raise an exception when attempting to reify a first-class object' do
|
93
93
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
94
94
|
solr_result = ActiveFedora::SolrService.query(query)
|
95
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
95
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result, {:load_from_solr => true})
|
96
96
|
solr_foo = result.first
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
expect {solr_foo.reify}.not_to raise_exception
|
98
|
+
expect {solr_foo.reify!}.not_to raise_exception
|
99
|
+
expect {solr_foo.reify!}.to raise_exception(/already a full/)
|
100
|
+
expect {solr_foo.reify}.to raise_exception(/already a full/)
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
it 'should call load_instance_from_solr if :load_from_solr option passed in' do
|
104
104
|
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
105
105
|
solr_result = ActiveFedora::SolrService.query(query)
|
106
|
-
ActiveFedora::Base.
|
107
|
-
FooObject.
|
108
|
-
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
106
|
+
expect(ActiveFedora::Base).to receive(:load_instance_from_solr).once
|
107
|
+
expect(FooObject).to receive(:load_instance_from_solr).once
|
108
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result, {:load_from_solr => true})
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
end
|
112
112
|
end
|