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
@@ -14,50 +14,50 @@ describe ActiveFedora::ServiceDefinitions do
|
|
14
14
|
</fmm:MethodMap>
|
15
15
|
MMAP
|
16
16
|
@repository = ActiveFedora::Base.connection_for_pid(0)
|
17
|
-
@repository.
|
18
|
-
Test.has_service_definition
|
17
|
+
allow(@repository).to receive(:datastream_dissemination).with({:pid => 'test:12', :dsid => 'METHODMAP'}).and_return mmap
|
18
|
+
Test.has_service_definition 'test:12'
|
19
19
|
end
|
20
20
|
|
21
|
-
subject {
|
21
|
+
subject {
|
22
22
|
obj = Test.new()
|
23
|
-
obj.
|
23
|
+
allow(obj).to receive(:pid).and_return('monkey:99')
|
24
24
|
obj
|
25
25
|
}
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
ActiveFedora::ServiceDefinitions.lookup_method(
|
26
|
+
describe 'method lookup' do
|
27
|
+
it 'should find method keys in the YAML config' do
|
28
|
+
expect(ActiveFedora::ServiceDefinitions.lookup_method('fedora-system:3', 'viewObjectProfile')).to eq(:object_profile)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
describe
|
32
|
-
it
|
33
|
-
subject.
|
31
|
+
describe 'method creation' do
|
32
|
+
it 'should create the system sdef methods' do
|
33
|
+
expect(subject).to respond_to(:object_profile)
|
34
34
|
end
|
35
|
-
it
|
36
|
-
subject.
|
35
|
+
it 'should create the declared sdef methods' do
|
36
|
+
expect(subject).to respond_to(:document_style_1)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
describe
|
40
|
-
it
|
41
|
-
@repository.
|
39
|
+
describe 'generated method' do
|
40
|
+
it 'should call the appropriate rubydora rest api method' do
|
41
|
+
expect(@repository).to receive(:dissemination).with({:pid => 'monkey:99', :sdef => 'test:12', :method => 'getDocumentStyle1'})
|
42
42
|
#@mock_client.stub(:[]).with('objects/monkey%3A99/methods/test%3A12/getDocumentStyle1')
|
43
43
|
|
44
44
|
subject.document_style_1
|
45
45
|
end
|
46
|
-
it
|
47
|
-
@repository.
|
46
|
+
it 'should call the appropriate rubydora rest api method with parameters' do
|
47
|
+
expect(@repository).to receive(:dissemination).with({:pid => 'monkey:99', :sdef => 'test:12', :method => 'getDocumentStyle1', :format => 'xml'})
|
48
48
|
obj = Test.new()
|
49
|
-
obj.
|
50
|
-
obj.document_style_1({:format=>'xml'})
|
49
|
+
allow(obj).to receive(:pid).and_return('monkey:99')
|
50
|
+
obj.document_style_1({:format => 'xml'})
|
51
51
|
end
|
52
|
-
it
|
53
|
-
@repository.
|
52
|
+
it 'should call the appropriate rubydora rest api method with a block' do
|
53
|
+
allow(@repository).to receive(:dissemination).with({:pid => 'monkey:99', :sdef => 'test:12', :method => 'getDocumentStyle1'}).and_yield 'ping!', 'pang!'
|
54
54
|
obj = Test.new()
|
55
|
-
obj.
|
56
|
-
block_response =
|
57
|
-
obj.document_style_1 {|res,req|
|
58
|
-
block_response += 'pong!' if res ==
|
55
|
+
allow(obj).to receive(:pid).and_return('monkey:99')
|
56
|
+
block_response = ''
|
57
|
+
obj.document_style_1 {|res, req|
|
58
|
+
block_response += 'pong!' if res == 'ping!' and req == 'pang!'
|
59
59
|
}
|
60
|
-
block_response.
|
60
|
+
expect(block_response).to eq('pong!')
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::SimpleDatastream do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@sample_xml =
|
6
|
+
@sample_xml = '<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>2012-01-15</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>'
|
7
7
|
@test_ds = ActiveFedora::SimpleDatastream.from_xml(@sample_xml )
|
8
8
|
@test_ds.field :coverage
|
9
9
|
@test_ds.field :creation_date, :date
|
@@ -11,36 +11,36 @@ describe ActiveFedora::SimpleDatastream do
|
|
11
11
|
@test_ds.field :publisher
|
12
12
|
|
13
13
|
end
|
14
|
-
it
|
15
|
-
@test_ds.ng_xml.
|
14
|
+
it 'from_xml should parse everything correctly' do
|
15
|
+
expect(@test_ds.ng_xml).to be_equivalent_to @sample_xml
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
|
19
19
|
describe '#new' do
|
20
|
-
describe
|
20
|
+
describe 'model methods' do
|
21
21
|
|
22
22
|
[:coverage, :mydate, :publisher].each do |el|
|
23
23
|
it "should respond to getters and setters for the string typed #{el} element" do
|
24
24
|
value = "Hey #{el}"
|
25
|
-
@test_ds.send("#{el.to_s}=", value)
|
26
|
-
@test_ds.send(el).first.
|
25
|
+
@test_ds.send("#{el.to_s}=", value)
|
26
|
+
expect(@test_ds.send(el).first).to eq(value) #Looking at first because creator has 2 nodes
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'should set date elements' do
|
31
31
|
d = Date.parse('1939-05-23')
|
32
32
|
@test_ds.creation_date = d
|
33
|
-
@test_ds.creation_date.first.
|
33
|
+
expect(@test_ds.creation_date.first).to eq(d)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
describe '.to_xml' do
|
39
39
|
it 'should output the fields hash as Qualified Dublin Core XML' do
|
40
|
-
@test_ds.publisher=
|
41
|
-
@test_ds.coverage= [
|
40
|
+
@test_ds.publisher = 'charlie'
|
41
|
+
@test_ds.coverage = ['80%', '20%']
|
42
42
|
|
43
|
-
@test_ds.to_xml.
|
43
|
+
expect(@test_ds.to_xml).to be_equivalent_to('
|
44
44
|
<fields>
|
45
45
|
<coverage>80%</coverage>
|
46
46
|
<coverage>20%</coverage>
|
@@ -51,11 +51,11 @@ describe ActiveFedora::SimpleDatastream do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
it
|
54
|
+
describe '#to_solr' do
|
55
|
+
it 'should have title' do
|
56
56
|
solr = @test_ds.to_solr
|
57
|
-
solr[ActiveFedora::SolrService.solr_name('publisher', type: :string)].
|
58
|
-
solr[ActiveFedora::SolrService.solr_name('creation_date', type: :date)].
|
57
|
+
expect(solr[ActiveFedora::SolrService.solr_name('publisher', type: :string)]).to eq('publisher1')
|
58
|
+
expect(solr[ActiveFedora::SolrService.solr_name('creation_date', type: :date)]).to eq('2012-01-15')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
#include ActiveFedora
|
5
5
|
|
6
6
|
describe ActiveFedora do
|
7
|
-
|
7
|
+
|
8
8
|
before(:all) do
|
9
9
|
module SolrSpecModel
|
10
10
|
class Basic < ActiveFedora::Base
|
@@ -13,56 +13,55 @@ describe ActiveFedora do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
before(:each) do
|
18
18
|
@test_object = ActiveFedora::Base.new
|
19
19
|
end
|
20
|
-
|
21
|
-
|
22
|
-
describe
|
20
|
+
|
21
|
+
|
22
|
+
describe 'SOLR_DOCUMENT_ID' do
|
23
23
|
before(:all) do
|
24
|
-
SOLR_DOCUMENT_ID =
|
24
|
+
SOLR_DOCUMENT_ID = 'MY_SAMPLE_ID'
|
25
25
|
end
|
26
26
|
after(:all) do
|
27
|
-
SOLR_DOCUMENT_ID =
|
27
|
+
SOLR_DOCUMENT_ID = 'id'
|
28
28
|
end
|
29
|
-
it
|
29
|
+
it 'should be used by ActiveFedora::Base.to_solr' do
|
30
30
|
@test_object.stub(pid: 'changeme:123')
|
31
|
-
SOLR_DOCUMENT_ID =
|
32
|
-
@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym].
|
33
|
-
@test_object.to_solr[:id].
|
31
|
+
SOLR_DOCUMENT_ID = 'MY_SAMPLE_ID'
|
32
|
+
expect(@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym]).to eq('changeme:123')
|
33
|
+
expect(@test_object.to_solr[:id]).to be_nil
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
mock_response = double(
|
38
|
-
ActiveFedora::SolrService.
|
39
|
-
|
40
|
-
SolrSpecModel::Basic.find_with_conditions(:id=>
|
36
|
+
it 'should be used by ActiveFedora::Base#find_with_conditions' do
|
37
|
+
mock_response = double('SolrResponse')
|
38
|
+
expect(ActiveFedora::SolrService).to receive(:query).with("_query_:\"{!raw f=#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}}info:fedora/afmodel:SolrSpecModel_Basic\" AND " + SOLR_DOCUMENT_ID + ':"changeme\\:30"', {:sort => ["#{ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)} asc"]}).and_return(mock_response)
|
39
|
+
|
40
|
+
expect(SolrSpecModel::Basic.find_with_conditions(:id => 'changeme:30')).to equal(mock_response)
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
describe
|
45
|
-
|
43
|
+
|
44
|
+
describe 'ENABLE_SOLR_UPDATES' do
|
45
|
+
|
46
46
|
before(:all) do
|
47
47
|
ENABLE_SOLR_UPDATES = false
|
48
48
|
end
|
49
49
|
after(:all) do
|
50
50
|
ENABLE_SOLR_UPDATES = true
|
51
51
|
end
|
52
|
-
|
53
|
-
it
|
52
|
+
|
53
|
+
it 'should prevent Base.save from calling update_index if false' do
|
54
54
|
dirty_ds = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, 'ds1')
|
55
55
|
@test_object.datastreams['ds1'] = dirty_ds
|
56
|
-
@test_object.
|
57
|
-
@test_object.
|
58
|
-
@test_object.
|
56
|
+
allow(@test_object).to receive(:datastreams).and_return({:ds1 => dirty_ds})
|
57
|
+
expect(@test_object).to receive(:update_index).never
|
58
|
+
expect(@test_object).to receive(:refresh)
|
59
59
|
@test_object.save
|
60
60
|
end
|
61
|
-
it
|
62
|
-
ActiveFedora::SolrService.instance.conn.
|
63
|
-
@test_object.inner_object.
|
61
|
+
it 'should prevent Base.delete from deleting the corresponding Solr document if false' do
|
62
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(@test_object.pid).never
|
63
|
+
expect(@test_object.inner_object).to receive(:delete)
|
64
64
|
@test_object.delete
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::SolrDigitalObject do
|
4
4
|
|
5
|
-
describe
|
6
|
-
subject { ActiveFedora::SolrDigitalObject.new({},{'datastreams'=>{}}) }
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
subject.
|
5
|
+
describe 'repository' do
|
6
|
+
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams' => {}}) }
|
7
|
+
describe 'when not finished' do
|
8
|
+
it 'should not respond_to? :repository' do
|
9
|
+
expect(subject).not_to respond_to :repository
|
10
10
|
end
|
11
11
|
end
|
12
|
-
describe
|
12
|
+
describe 'when finished' do
|
13
13
|
before do
|
14
14
|
subject.freeze
|
15
15
|
end
|
16
|
-
it
|
17
|
-
subject.
|
16
|
+
it 'should respond_to? :repository' do
|
17
|
+
expect(subject).to respond_to :repository
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
describe
|
22
|
+
describe 'initializing' do
|
23
|
+
describe 'without a datastream in the ds spec and an xml mime type in the solr doc' do
|
24
24
|
before do
|
25
25
|
class WithoutMetadataDs < ActiveFedora::Base
|
26
26
|
## No datastreams are defined in this class
|
@@ -29,22 +29,22 @@ describe ActiveFedora::SolrDigitalObject do
|
|
29
29
|
after do
|
30
30
|
Object.send(:remove_const, :WithoutMetadataDs)
|
31
31
|
end
|
32
|
-
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams'=>{'properties'=>{'dsMIME'=>'text/xml'}}},WithoutMetadataDs) }
|
33
|
-
it
|
34
|
-
subject.datastreams['properties'].
|
32
|
+
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams' => {'properties' => {'dsMIME' => 'text/xml'}}}, WithoutMetadataDs) }
|
33
|
+
it 'should create an xml datastream' do
|
34
|
+
expect(subject.datastreams['properties']).to be_kind_of ActiveFedora::OmDatastream
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
describe "with a ds spec that's not part of the solrized object" do
|
39
39
|
before do
|
40
40
|
class MissingMetadataDs < ActiveFedora::Base
|
41
|
-
has_metadata :name =>
|
41
|
+
has_metadata :name => 'foo', :type => ActiveFedora::OmDatastream, :label => 'Foo Data'
|
42
42
|
end
|
43
43
|
after do
|
44
44
|
Object.send(:remove_const, MissingMetadataDs)
|
45
45
|
end
|
46
|
-
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams'=>{'properties'=>{'dsMIME'=>'text/xml'}}},MissingMetadataDs) }
|
47
|
-
it
|
46
|
+
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams' => {'properties' => {'dsMIME' => 'text/xml'}}}, MissingMetadataDs) }
|
47
|
+
it 'should have a foo datastream' do
|
48
48
|
subject.datastreams['foo'].label.should == 'Foo Data'
|
49
49
|
end
|
50
50
|
end
|
@@ -52,10 +52,10 @@ describe ActiveFedora::SolrDigitalObject do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
describe
|
56
|
-
subject { ActiveFedora::SolrDigitalObject.new({},{'datastreams'=>{}}) }
|
57
|
-
it
|
58
|
-
subject.new_record
|
55
|
+
describe 'new_record?' do
|
56
|
+
subject { ActiveFedora::SolrDigitalObject.new({}, {'datastreams' => {}}) }
|
57
|
+
it 'should respond to :new_record? and return false' do
|
58
|
+
expect(subject.new_record?).to be_falsey
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -2,39 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::SolrService do
|
4
4
|
before do
|
5
|
-
Thread.current[:solr_service]=nil
|
5
|
+
Thread.current[:solr_service] = nil
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
after(:all) do
|
9
9
|
ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
|
10
10
|
end
|
11
|
-
|
12
|
-
it
|
13
|
-
RSolr.
|
11
|
+
|
12
|
+
it 'should take a narg constructor and configure for localhost' do
|
13
|
+
expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://localhost:8080/solr')
|
14
14
|
ActiveFedora::SolrService.register
|
15
15
|
end
|
16
|
-
it
|
17
|
-
RSolr.
|
16
|
+
it 'should accept host arg into constructor' do
|
17
|
+
expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://fubar')
|
18
18
|
ActiveFedora::SolrService.register('http://fubar')
|
19
19
|
end
|
20
|
-
it
|
21
|
-
RSolr.
|
22
|
-
ActiveFedora::SolrService.register(nil, {:autocommit
|
20
|
+
it 'should clobber options' do
|
21
|
+
expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://localhost:8080/solr', :autocommit => :off, :foo => :bar)
|
22
|
+
ActiveFedora::SolrService.register(nil, {:autocommit => :off, :foo => :bar})
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
RSolr.
|
27
|
-
ss = ActiveFedora::SolrService.register(nil, {:autocommit
|
28
|
-
Thread.current[:solr_service].
|
29
|
-
ActiveFedora::SolrService.instance.
|
25
|
+
it 'should set the threadlocal solr service' do
|
26
|
+
expect(RSolr).to receive(:connect).with(:read_timeout => 120, :open_timeout => 120, :url => 'http://localhost:8080/solr', :autocommit => :off, :foo => :bar)
|
27
|
+
ss = ActiveFedora::SolrService.register(nil, {:autocommit => :off, :foo => :bar})
|
28
|
+
expect(Thread.current[:solr_service]).to eq(ss)
|
29
|
+
expect(ActiveFedora::SolrService.instance).to eq(ss)
|
30
30
|
end
|
31
|
-
it
|
32
|
-
Thread.current[:solr_service].
|
33
|
-
ActiveFedora::SolrService.
|
34
|
-
|
31
|
+
it 'should try to initialize if the service not initialized, and fail if it does not succeed' do
|
32
|
+
expect(Thread.current[:solr_service]).to be_nil
|
33
|
+
expect(ActiveFedora::SolrService).to receive(:register)
|
34
|
+
expect{ActiveFedora::SolrService.instance}.to raise_error(ActiveFedora::SolrNotInitialized)
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
37
|
+
describe 'reify solr results' do
|
38
38
|
before(:all) do
|
39
39
|
class AudioRecord
|
40
40
|
attr_accessor :pid
|
@@ -45,99 +45,99 @@ describe ActiveFedora::SolrService do
|
|
45
45
|
def self.connection_for_pid(pid)
|
46
46
|
end
|
47
47
|
end
|
48
|
-
@sample_solr_hits = [{
|
49
|
-
{
|
50
|
-
{
|
48
|
+
@sample_solr_hits = [{'id' => 'my:_PID1_', ActiveFedora::SolrService.solr_name('has_model', :symbol) => ['info:fedora/afmodel:AudioRecord']},
|
49
|
+
{'id' => 'my:_PID2_', ActiveFedora::SolrService.solr_name('has_model', :symbol) => ['info:fedora/afmodel:AudioRecord']},
|
50
|
+
{'id' => 'my:_PID3_', ActiveFedora::SolrService.solr_name('has_model', :symbol) => ['info:fedora/afmodel:AudioRecord']}]
|
51
51
|
end
|
52
|
-
describe
|
53
|
-
it
|
54
|
-
AudioRecord.
|
55
|
-
AudioRecord.
|
56
|
-
AudioRecord.
|
52
|
+
describe '.reify_solr_results' do
|
53
|
+
it 'should use AudioRecord.find to instantiate objects' do
|
54
|
+
expect(AudioRecord).to receive(:find).with('my:_PID1_', cast: true)
|
55
|
+
expect(AudioRecord).to receive(:find).with('my:_PID2_', cast: true)
|
56
|
+
expect(AudioRecord).to receive(:find).with('my:_PID3_', cast: true)
|
57
57
|
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits)
|
58
58
|
end
|
59
|
-
it
|
60
|
-
AudioRecord.
|
61
|
-
AudioRecord.
|
62
|
-
AudioRecord.
|
59
|
+
it 'should use AudioRecord.load_instance_from_solr when called with :load_from_solr option' do
|
60
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID1_')
|
61
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID2_')
|
62
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID3_')
|
63
63
|
ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits, load_from_solr: true)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
describe
|
67
|
-
it
|
68
|
-
AudioRecord.
|
69
|
-
AudioRecord.
|
70
|
-
AudioRecord.
|
66
|
+
describe '.lazy_reify_solr_results' do
|
67
|
+
it 'should lazily reify solr results' do
|
68
|
+
expect(AudioRecord).to receive(:find).with('my:_PID1_', cast: true)
|
69
|
+
expect(AudioRecord).to receive(:find).with('my:_PID2_', cast: true)
|
70
|
+
expect(AudioRecord).to receive(:find).with('my:_PID3_', cast: true)
|
71
71
|
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits).each {|r| r}
|
72
72
|
end
|
73
|
-
it
|
74
|
-
AudioRecord.
|
75
|
-
AudioRecord.
|
76
|
-
AudioRecord.
|
73
|
+
it 'should use AudioRecord.load_instance_from_solr when called with :load_from_solr option' do
|
74
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID1_')
|
75
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID2_')
|
76
|
+
expect(AudioRecord).to receive(:load_instance_from_solr).with('my:_PID3_')
|
77
77
|
ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits, load_from_solr: true).each {|r| r}
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
describe '#construct_query_for_pids' do
|
83
|
-
it
|
84
|
-
ActiveFedora::SolrService.construct_query_for_pids([
|
83
|
+
it 'should generate a useable solr query from an array of Fedora pids' do
|
84
|
+
expect(ActiveFedora::SolrService.construct_query_for_pids(['my:_PID1_', 'my:_PID2_', 'my:_PID3_'])).to eq('_query_:"{!raw f=id}my:_PID1_" OR _query_:"{!raw f=id}my:_PID2_" OR _query_:"{!raw f=id}my:_PID3_"')
|
85
85
|
|
86
86
|
end
|
87
|
-
it
|
88
|
-
ActiveFedora::SolrService.construct_query_for_pids([
|
89
|
-
|
87
|
+
it 'should return a valid solr query even if given an empty array as input' do
|
88
|
+
expect(ActiveFedora::SolrService.construct_query_for_pids([''])).to eq('id:NEVER_USE_THIS_ID')
|
89
|
+
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
describe '#escape_uri_for_query' do
|
94
|
-
it
|
95
|
-
ActiveFedora::SolrService.escape_uri_for_query(
|
94
|
+
it 'should escape : with a backslash' do
|
95
|
+
expect(ActiveFedora::SolrService.escape_uri_for_query('my:pid')).to eq('my\:pid')
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe
|
100
|
-
it
|
101
|
-
mock_conn = double(
|
102
|
-
stub_result = double(
|
103
|
-
mock_conn.
|
104
|
-
ActiveFedora::SolrService.stub(:instance =>double(
|
105
|
-
ActiveFedora::SolrService.query('querytext', :raw=>true).
|
99
|
+
describe '.query' do
|
100
|
+
it 'should call solr' do
|
101
|
+
mock_conn = double('Connection')
|
102
|
+
stub_result = double('Result')
|
103
|
+
expect(mock_conn).to receive(:get).with('select', :params => {:q => 'querytext', :qt => 'standard'}).and_return(stub_result)
|
104
|
+
ActiveFedora::SolrService.stub(:instance => double('instance', :conn => mock_conn))
|
105
|
+
expect(ActiveFedora::SolrService.query('querytext', :raw => true)).to eq(stub_result)
|
106
106
|
end
|
107
107
|
end
|
108
|
-
describe
|
109
|
-
it
|
110
|
-
mock_conn = double(
|
111
|
-
stub_result = {'response' => {'numFound'=>'7'}}
|
112
|
-
mock_conn.
|
113
|
-
ActiveFedora::SolrService.stub(:instance =>double(
|
114
|
-
ActiveFedora::SolrService.count('querytext').
|
108
|
+
describe '.count' do
|
109
|
+
it 'should return a count of matching records' do
|
110
|
+
mock_conn = double('Connection')
|
111
|
+
stub_result = {'response' => {'numFound' => '7'}}
|
112
|
+
expect(mock_conn).to receive(:get).with('select', :params => {:rows => 0, :q => 'querytext', :qt => 'standard'}).and_return(stub_result)
|
113
|
+
ActiveFedora::SolrService.stub(:instance => double('instance', :conn => mock_conn))
|
114
|
+
expect(ActiveFedora::SolrService.count('querytext')).to eq(7)
|
115
115
|
end
|
116
|
-
it
|
117
|
-
mock_conn = double(
|
118
|
-
stub_result = {'response' => {'numFound'=>'7'}}
|
119
|
-
mock_conn.
|
120
|
-
ActiveFedora::SolrService.stub(:instance =>double(
|
121
|
-
ActiveFedora::SolrService.count('querytext', :fq=>'filter', :rows=>10).
|
116
|
+
it 'should accept query args' do
|
117
|
+
mock_conn = double('Connection')
|
118
|
+
stub_result = {'response' => {'numFound' => '7'}}
|
119
|
+
expect(mock_conn).to receive(:get).with('select', :params => {:rows => 0, :q => 'querytext', :qt => 'standard', :fq => 'filter'}).and_return(stub_result)
|
120
|
+
ActiveFedora::SolrService.stub(:instance => double('instance', :conn => mock_conn))
|
121
|
+
expect(ActiveFedora::SolrService.count('querytext', :fq => 'filter', :rows => 10)).to eq(7)
|
122
122
|
end
|
123
123
|
end
|
124
|
-
describe
|
125
|
-
it
|
126
|
-
mock_conn = double(
|
124
|
+
describe '.add' do
|
125
|
+
it 'should call solr' do
|
126
|
+
mock_conn = double('Connection')
|
127
127
|
doc = {'id' => '1234'}
|
128
|
-
mock_conn.
|
129
|
-
ActiveFedora::SolrService.stub(:instance =>double(
|
128
|
+
expect(mock_conn).to receive(:add).with(doc)
|
129
|
+
ActiveFedora::SolrService.stub(:instance => double('instance', :conn => mock_conn))
|
130
130
|
ActiveFedora::SolrService.add(doc)
|
131
131
|
end
|
132
132
|
end
|
133
|
-
describe
|
134
|
-
it
|
135
|
-
mock_conn = double(
|
133
|
+
describe '.commit' do
|
134
|
+
it 'should call solr' do
|
135
|
+
mock_conn = double('Connection')
|
136
136
|
doc = {'id' => '1234'}
|
137
|
-
mock_conn.
|
138
|
-
ActiveFedora::SolrService.stub(:instance =>double(
|
137
|
+
expect(mock_conn).to receive(:commit)
|
138
|
+
ActiveFedora::SolrService.stub(:instance => double('instance', :conn => mock_conn))
|
139
139
|
ActiveFedora::SolrService.commit()
|
140
140
|
end
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
end
|