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
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'deletgating multiple terms to one datastream' do
|
6
6
|
class BarnyardDocument < ActiveFedora::OmDatastream
|
7
7
|
set_terminology do |t|
|
8
|
-
t.root(:path=>
|
8
|
+
t.root(:path => 'animals', :xmlns => 'urn:zoobar')
|
9
9
|
t.waterfowl do
|
10
10
|
t.ducks do
|
11
11
|
t.duck
|
@@ -16,60 +16,58 @@ describe ActiveFedora::Base do
|
|
16
16
|
t.horse()
|
17
17
|
t.chicken()
|
18
18
|
t.pig()
|
19
|
-
t.duck(:ref=>[:waterfowl
|
19
|
+
t.duck(:ref => [:waterfowl, :ducks, :duck])
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.xml_template
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
|
24
|
+
<waterfowl>
|
25
|
+
<ducks>
|
26
|
+
<duck/>
|
27
|
+
</ducks>
|
28
|
+
</waterfowl>
|
29
|
+
<donkey></donkey>
|
30
|
+
<cow></cow>
|
31
|
+
<horse></horse>
|
32
|
+
<chicken></chicken>
|
33
|
+
<pig></pig>
|
34
|
+
</animals>'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
class Barnyard < ActiveFedora::Base
|
39
|
-
has_metadata :type=>BarnyardDocument, :name=>
|
39
|
+
has_metadata :type => BarnyardDocument, :name => 'xmlish'
|
40
40
|
delegate_to :xmlish, [:cow, :chicken, :pig, :duck], multiple: true
|
41
|
-
delegate_to :xmlish, [:donkey, :horse], :unique=>true
|
42
|
-
#delegate :donkey, :to=>'xmlish', :unique=>true
|
41
|
+
delegate_to :xmlish, [:donkey, :horse], :unique => true
|
42
|
+
# delegate :donkey, :to=>'xmlish', :unique=>true
|
43
43
|
end
|
44
44
|
before :each do
|
45
45
|
@n = Barnyard.new()
|
46
46
|
end
|
47
|
-
it
|
48
|
-
@n.donkey=
|
49
|
-
@n.donkey.
|
50
|
-
@n.xmlish.term_values(:donkey).first.
|
51
|
-
@n.horse=
|
52
|
-
@n.horse.
|
53
|
-
@n.xmlish.term_values(:horse).first.
|
47
|
+
it 'should save a delegated property uniquely' do
|
48
|
+
@n.donkey = 'Bray'
|
49
|
+
expect(@n.donkey).to eq('Bray')
|
50
|
+
expect(@n.xmlish.term_values(:donkey).first).to eq('Bray')
|
51
|
+
@n.horse = 'Winee'
|
52
|
+
expect(@n.horse).to eq('Winee')
|
53
|
+
expect(@n.xmlish.term_values(:horse).first).to eq('Winee')
|
54
54
|
end
|
55
|
-
it
|
56
|
-
|
57
|
-
@n.cow=[
|
58
|
-
@n.cow.
|
55
|
+
it 'should return an array if not marked as unique' do
|
56
|
+
# Metadata datastream does not appear to support multiple value setting
|
57
|
+
@n.cow = ['one', 'two']
|
58
|
+
expect(@n.cow).to eq(['one', 'two'])
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
@n.duck=[
|
63
|
-
@n.duck.
|
61
|
+
it 'should be able to delegate deeply into the terminology' do
|
62
|
+
@n.duck = ['Quack', 'Peep']
|
63
|
+
expect(@n.duck).to eq(['Quack', 'Peep'])
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
@n.chicken_changed
|
68
|
-
@n.chicken = [
|
69
|
-
@n.chicken_changed
|
70
|
-
end
|
66
|
+
it 'should be able to track change status' do
|
67
|
+
expect(@n.chicken_changed?).to be_falsey
|
68
|
+
@n.chicken = ['Cheep']
|
69
|
+
expect(@n.chicken_changed?).to be_truthy
|
70
|
+
end
|
71
71
|
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
|
-
|
@@ -1,81 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
6
|
@test_object = ActiveFedora::Base.new
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe '.update_index' do
|
10
10
|
before do
|
11
|
-
mock_conn = double(
|
12
|
-
mock_conn.
|
13
|
-
mock_conn.
|
14
|
-
mock_ss = double(
|
15
|
-
mock_ss.
|
16
|
-
ActiveFedora::SolrService.
|
11
|
+
mock_conn = double('SolrConnection')
|
12
|
+
expect(mock_conn).to receive(:add)
|
13
|
+
expect(mock_conn).to receive(:commit)
|
14
|
+
mock_ss = double('SolrService')
|
15
|
+
allow(mock_ss).to receive(:conn).and_return(mock_conn)
|
16
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
|
17
17
|
end
|
18
|
-
|
19
|
-
it
|
18
|
+
|
19
|
+
it 'should call .to_solr on all SimpleDatastreams AND RelsExtDatastreams and pass the resulting document to solr' do
|
20
20
|
# Actually uses self.to_solr internally to gather solr info from all metadata datastreams
|
21
|
-
mock1 = double(
|
22
|
-
mock2 = double(
|
23
|
-
mock3 = double(
|
24
|
-
|
21
|
+
mock1 = double('ds1', :to_solr => {})
|
22
|
+
mock2 = double('ds2', :to_solr => {})
|
23
|
+
mock3 = double('RELS-EXT', :to_solr => {})
|
24
|
+
|
25
25
|
mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
|
26
|
-
mock1.
|
27
|
-
mock2.
|
28
|
-
mock3.
|
29
|
-
@test_object.
|
30
|
-
@test_object.
|
26
|
+
expect(mock1).to receive(:solrize_profile).and_return({})
|
27
|
+
expect(mock2).to receive(:solrize_profile).and_return({})
|
28
|
+
expect(mock3).to receive(:solrize_profile).and_return({})
|
29
|
+
expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
|
30
|
+
expect(@test_object).to receive(:solrize_relationships)
|
31
31
|
@test_object.update_index
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'should call .to_solr on all RDFDatastreams and pass the resulting document to solr' do
|
35
35
|
# Actually uses self.to_solr internally to gather solr info from all metadata datastreams
|
36
|
-
mock1 = double(
|
37
|
-
mock2 = double(
|
38
|
-
mock3 = double(
|
39
|
-
|
36
|
+
mock1 = double('ds1', :to_solr => {})
|
37
|
+
mock2 = double('ds2', :to_solr => {})
|
38
|
+
mock3 = double('RELS-EXT', :to_solr => {})
|
39
|
+
|
40
40
|
mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
|
41
|
-
mock1.
|
42
|
-
mock2.
|
43
|
-
mock3.
|
44
|
-
@test_object.
|
45
|
-
@test_object.
|
41
|
+
expect(mock1).to receive(:solrize_profile).and_return({})
|
42
|
+
expect(mock2).to receive(:solrize_profile).and_return({})
|
43
|
+
expect(mock3).to receive(:solrize_profile).and_return({})
|
44
|
+
expect(@test_object).to receive(:datastreams).twice.and_return(mock_datastreams)
|
45
|
+
expect(@test_object).to receive(:solrize_relationships)
|
46
46
|
@test_object.update_index
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'should retrieve a solr Connection and call Connection.add' do
|
50
50
|
@test_object.update_index
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
|
-
|
55
|
-
describe
|
56
|
-
|
54
|
+
|
55
|
+
describe '.delete' do
|
56
|
+
|
57
57
|
before(:each) do
|
58
58
|
end
|
59
|
-
|
60
|
-
it
|
61
|
-
@test_object.inner_object.
|
62
|
-
mock_conn = double(
|
63
|
-
mock_conn.
|
64
|
-
mock_conn.
|
65
|
-
mock_ss = double(
|
66
|
-
mock_ss.
|
67
|
-
ActiveFedora::SolrService.
|
59
|
+
|
60
|
+
it 'should delete object from repository and index' do
|
61
|
+
allow(@test_object.inner_object).to receive(:delete)
|
62
|
+
mock_conn = double('SolrConnection')
|
63
|
+
expect(mock_conn).to receive(:delete_by_id).with(nil)
|
64
|
+
expect(mock_conn).to receive(:commit)
|
65
|
+
mock_ss = double('SolrService')
|
66
|
+
allow(mock_ss).to receive(:conn).and_return(mock_conn)
|
67
|
+
allow(ActiveFedora::SolrService).to receive(:instance).and_return(mock_ss)
|
68
68
|
@test_object.delete
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
72
|
-
|
73
|
-
describe '#pids_from_uris' do
|
74
|
-
it
|
75
|
-
ActiveFedora::Base.pids_from_uris(
|
72
|
+
|
73
|
+
describe '#pids_from_uris' do
|
74
|
+
it 'should strip the info:fedora/ out of a given string' do
|
75
|
+
expect(ActiveFedora::Base.pids_from_uris('info:fedora/FOOBAR')).to eq('FOOBAR')
|
76
76
|
end
|
77
|
-
it
|
78
|
-
ActiveFedora::Base.pids_from_uris([
|
77
|
+
it 'should accept an array of strings'do
|
78
|
+
expect(ActiveFedora::Base.pids_from_uris(['info:fedora/FOOBAR', 'info:fedora/BAZFOO'])).to eq(['FOOBAR', 'BAZFOO'])
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
data/spec/unit/base_spec.rb
CHANGED
@@ -1,81 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
@@last_pid = 0
|
2
|
+
@@last_pid = 0
|
3
3
|
|
4
4
|
describe ActiveFedora::Base do
|
5
|
-
it_behaves_like
|
5
|
+
it_behaves_like 'An ActiveModel'
|
6
6
|
|
7
7
|
describe 'descendants' do
|
8
|
-
it
|
9
|
-
ActiveFedora::Base.descendants.
|
8
|
+
it 'should record the decendants' do
|
9
|
+
expect(ActiveFedora::Base.descendants).to include(ModsArticle, SpecialThing)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
ActiveFedora::Base.shard_index(@this_pid).
|
13
|
+
describe 'sharding' do
|
14
|
+
it 'should have a shard_index' do
|
15
|
+
expect(ActiveFedora::Base.shard_index(@this_pid)).to eq(0)
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
18
|
+
context 'When the repository is NOT sharded' do
|
19
19
|
subject {ActiveFedora::Base.connection_for_pid('test:bar')}
|
20
20
|
before(:each) do
|
21
|
-
ActiveFedora.config.
|
21
|
+
allow(ActiveFedora.config).to receive(:sharded?).and_return(false)
|
22
22
|
ActiveFedora::Base.fedora_connection = {}
|
23
|
-
ActiveFedora.config.
|
23
|
+
allow(ActiveFedora.config).to receive(:credentials).and_return(:url => 'myfedora')
|
24
24
|
end
|
25
|
-
it {
|
26
|
-
it
|
27
|
-
subject.client.url.
|
25
|
+
it { is_expected.to be_kind_of Rubydora::Repository}
|
26
|
+
it 'should be the standard connection' do
|
27
|
+
expect(subject.client.url).to eq('myfedora')
|
28
28
|
end
|
29
|
-
describe
|
30
|
-
it
|
29
|
+
describe 'assign_pid' do
|
30
|
+
it 'should use fedora to generate pids' do
|
31
31
|
# TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
|
32
32
|
# possibly wrap it all into a fedora_connection method - MZ 06-05-2012
|
33
|
-
stubfedora = double(
|
34
|
-
stubfedora.
|
33
|
+
stubfedora = double('Fedora')
|
34
|
+
expect(stubfedora).to receive(:connection).and_return(double('Connection', :mint => 'sample:newpid'))
|
35
35
|
# Should use ActiveFedora.config.credentials as a single hash rather than an array of shards
|
36
|
-
ActiveFedora::RubydoraConnection.
|
36
|
+
expect(ActiveFedora::RubydoraConnection).to receive(:new).with(ActiveFedora.config.credentials).and_return(stubfedora)
|
37
37
|
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
ActiveFedora::Base.shard_index('test:bar').
|
40
|
+
describe 'shard_index' do
|
41
|
+
it 'should always return zero (the first and only connection)' do
|
42
|
+
expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
context
|
46
|
+
context 'When the repository is sharded' do
|
47
47
|
before :each do
|
48
|
-
ActiveFedora.config.
|
48
|
+
allow(ActiveFedora.config).to receive(:sharded?).and_return(true)
|
49
49
|
ActiveFedora::Base.fedora_connection = {}
|
50
|
-
ActiveFedora.config.
|
51
|
-
end
|
52
|
-
describe
|
53
|
-
it
|
54
|
-
stubhard1 = double(
|
55
|
-
stubhard2 = double(
|
56
|
-
stubhard1.
|
57
|
-
stubhard2.
|
50
|
+
allow(ActiveFedora.config).to receive(:credentials).and_return([{:url => 'shard1'}, {:url => 'shard2'} ])
|
51
|
+
end
|
52
|
+
describe 'assign_pid' do
|
53
|
+
it 'should always use the first shard to generate pids' do
|
54
|
+
stubhard1 = double('Shard')
|
55
|
+
stubhard2 = double('Shard')
|
56
|
+
expect(stubhard1).to receive(:connection).and_return(double('Connection', :mint => 'sample:newpid'))
|
57
|
+
expect(stubhard2).to receive(:connection).never
|
58
58
|
ActiveFedora::Base.fedora_connection = {0 => stubhard1, 1 => stubhard2}
|
59
59
|
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
60
60
|
end
|
61
61
|
end
|
62
|
-
describe
|
63
|
-
it
|
64
|
-
ActiveFedora::Base.shard_index('test:bar').
|
65
|
-
ActiveFedora::Base.shard_index('test:nanana').
|
62
|
+
describe 'shard_index' do
|
63
|
+
it 'should use modulo of md5 of the pid to distribute objects across shards' do
|
64
|
+
expect(ActiveFedora::Base.shard_index('test:bar')).to eq(0)
|
65
|
+
expect(ActiveFedora::Base.shard_index('test:nanana')).to eq(1)
|
66
66
|
end
|
67
67
|
end
|
68
|
-
describe
|
69
|
-
describe
|
68
|
+
describe 'the repository' do
|
69
|
+
describe 'for test:bar' do
|
70
70
|
subject {ActiveFedora::Base.connection_for_pid('test:bar')}
|
71
|
-
it
|
72
|
-
subject.client.url.
|
71
|
+
it 'should be shard1' do
|
72
|
+
expect(subject.client.url).to eq('shard1')
|
73
73
|
end
|
74
74
|
end
|
75
|
-
describe
|
75
|
+
describe 'for test:baz' do
|
76
76
|
subject {ActiveFedora::Base.connection_for_pid('test:nanana')}
|
77
|
-
it
|
78
|
-
subject.client.url.
|
77
|
+
it 'should be shard1' do
|
78
|
+
expect(subject.client.url).to eq('shard2')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -83,53 +83,53 @@ describe ActiveFedora::Base do
|
|
83
83
|
|
84
84
|
end
|
85
85
|
|
86
|
-
describe
|
87
|
-
it
|
88
|
-
Rubydora::Repository.
|
89
|
-
and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ')).
|
90
|
-
and_yield(double(pid:'fedora-system:ServiceDeployment-3.0')).
|
91
|
-
and_yield(double(pid:'fedora-system:ServiceDefinition-3.0')).
|
92
|
-
and_yield(double(pid:'fedora-system:FedoraObject-3.0'))
|
86
|
+
describe 'reindex_everything' do
|
87
|
+
it 'should call update_index on every object except for the fedora-system objects' do
|
88
|
+
expect_any_instance_of(Rubydora::Repository).to receive(:search).
|
89
|
+
and_yield(double(pid: 'XXX')).and_yield(double(pid: 'YYY')).and_yield(double(pid: 'ZZZ')).
|
90
|
+
and_yield(double(pid: 'fedora-system:ServiceDeployment-3.0')).
|
91
|
+
and_yield(double(pid: 'fedora-system:ServiceDefinition-3.0')).
|
92
|
+
and_yield(double(pid: 'fedora-system:FedoraObject-3.0'))
|
93
93
|
|
94
94
|
mock_update = double(:mock_obj)
|
95
|
-
mock_update.
|
96
|
-
ActiveFedora::Base.
|
97
|
-
ActiveFedora::Base.
|
98
|
-
ActiveFedora::Base.
|
95
|
+
expect(mock_update).to receive(:update_index).exactly(3).times
|
96
|
+
expect(ActiveFedora::Base).to receive(:find).with('XXX', :cast => true).and_return(mock_update)
|
97
|
+
expect(ActiveFedora::Base).to receive(:find).with('YYY', :cast => true).and_return(mock_update)
|
98
|
+
expect(ActiveFedora::Base).to receive(:find).with('ZZZ', :cast => true).and_return(mock_update)
|
99
99
|
ActiveFedora::Base.reindex_everything
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
query_string =
|
104
|
-
Rubydora::Repository.
|
105
|
-
and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ'))
|
102
|
+
it 'should accept a query param for the search' do
|
103
|
+
query_string = 'pid~*'
|
104
|
+
expect_any_instance_of(Rubydora::Repository).to receive(:search).with(query_string).
|
105
|
+
and_yield(double(pid: 'XXX')).and_yield(double(pid: 'YYY')).and_yield(double(pid: 'ZZZ'))
|
106
106
|
mock_update = double(:mock_obj)
|
107
|
-
mock_update.
|
108
|
-
ActiveFedora::Base.
|
109
|
-
ActiveFedora::Base.
|
110
|
-
ActiveFedora::Base.
|
107
|
+
expect(mock_update).to receive(:update_index).exactly(3).times
|
108
|
+
expect(ActiveFedora::Base).to receive(:find).with('XXX', :cast => true).and_return(mock_update)
|
109
|
+
expect(ActiveFedora::Base).to receive(:find).with('YYY', :cast => true).and_return(mock_update)
|
110
|
+
expect(ActiveFedora::Base).to receive(:find).with('ZZZ', :cast => true).and_return(mock_update)
|
111
111
|
ActiveFedora::Base.reindex_everything(query_string)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe
|
115
|
+
describe 'With a test class' do
|
116
116
|
before :all do
|
117
117
|
class FooHistory < ActiveFedora::Base
|
118
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>
|
119
|
-
m.field
|
120
|
-
m.field
|
118
|
+
has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'someData', :autocreate => true do |m|
|
119
|
+
m.field 'fubar', :string
|
120
|
+
m.field 'swank', :text
|
121
121
|
end
|
122
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>
|
123
|
-
m.field
|
122
|
+
has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'withText', :autocreate => true do |m|
|
123
|
+
m.field 'fubar', :text
|
124
124
|
end
|
125
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>
|
126
|
-
m.field
|
127
|
-
end
|
128
|
-
delegate :fubar, :to=>'withText', multiple: true
|
129
|
-
delegate :swank, :to=>'someData', multiple: true
|
125
|
+
has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'withText2', :label => 'withLabel', :autocreate => true do |m|
|
126
|
+
m.field 'fubar', :text
|
127
|
+
end
|
128
|
+
delegate :fubar, :to => 'withText', multiple: true
|
129
|
+
delegate :swank, :to => 'someData', multiple: true
|
130
130
|
end
|
131
131
|
class FooAdaptation < ActiveFedora::Base
|
132
|
-
has_metadata :type=>ActiveFedora::OmDatastream, :name=>'someData'
|
132
|
+
has_metadata :type => ActiveFedora::OmDatastream, :name => 'someData'
|
133
133
|
end
|
134
134
|
|
135
135
|
class FooInherited < FooHistory
|
@@ -150,15 +150,15 @@ describe ActiveFedora::Base do
|
|
150
150
|
before(:each) do
|
151
151
|
@this_pid = increment_pid.to_s
|
152
152
|
stub_get(@this_pid)
|
153
|
-
Rubydora::Repository.
|
154
|
-
ActiveFedora::Base.
|
153
|
+
allow_any_instance_of(Rubydora::Repository).to receive(:client).and_return(@mock_client)
|
154
|
+
allow(ActiveFedora::Base).to receive(:assign_pid).and_return(@this_pid)
|
155
155
|
|
156
156
|
@test_object = ActiveFedora::Base.new
|
157
157
|
end
|
158
158
|
|
159
159
|
after(:each) do
|
160
160
|
begin
|
161
|
-
ActiveFedora::SolrService.
|
161
|
+
allow(ActiveFedora::SolrService).to receive(:instance)
|
162
162
|
#@test_object.delete
|
163
163
|
rescue
|
164
164
|
end
|
@@ -166,449 +166,449 @@ describe ActiveFedora::Base do
|
|
166
166
|
|
167
167
|
|
168
168
|
describe '#new' do
|
169
|
-
it
|
169
|
+
it 'should create an inner object' do
|
170
170
|
# for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
|
171
|
-
Rubydora::DigitalObject.
|
171
|
+
expect_any_instance_of(Rubydora::DigitalObject).to receive(:save).never
|
172
172
|
result = ActiveFedora::Base.new(nil)
|
173
|
-
result.inner_object.
|
173
|
+
expect(result.inner_object).to be_kind_of(ActiveFedora::UnsavedDigitalObject)
|
174
174
|
end
|
175
175
|
|
176
|
-
it
|
177
|
-
Rubydora::DigitalObject.
|
178
|
-
ActiveFedora::Base.
|
176
|
+
it 'should not save or get an pid on init' do
|
177
|
+
expect_any_instance_of(Rubydora::DigitalObject).to receive(:save).never
|
178
|
+
expect(ActiveFedora::Base).to receive(:assign_pid).never
|
179
179
|
f = FooHistory.new
|
180
180
|
end
|
181
181
|
|
182
|
-
it
|
183
|
-
f = FooHistory.new(:pid=>'numbnuts:1')
|
184
|
-
f.pid.
|
182
|
+
it 'should be able to create with a custom pid' do
|
183
|
+
f = FooHistory.new(:pid => 'numbnuts:1')
|
184
|
+
expect(f.pid).to eq('numbnuts:1')
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
describe
|
189
|
-
it
|
190
|
-
FooAdaptation.datastream_class_for_name('someData').
|
188
|
+
describe '.datastream_class_for_name' do
|
189
|
+
it 'should return the specifed class' do
|
190
|
+
expect(FooAdaptation.datastream_class_for_name('someData')).to eq(ActiveFedora::OmDatastream)
|
191
191
|
end
|
192
|
-
it
|
193
|
-
FooAdaptation.datastream_class_for_name('content').
|
192
|
+
it 'should return the specifed class' do
|
193
|
+
expect(FooAdaptation.datastream_class_for_name('content')).to eq(ActiveFedora::Datastream)
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
describe
|
198
|
-
it
|
199
|
-
@test_object.internal_uri.
|
197
|
+
describe '.internal_uri' do
|
198
|
+
it 'should return pid as fedors uri' do
|
199
|
+
expect(@test_object.internal_uri).to eql("info:fedora/#{@test_object.pid}")
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
203
|
### Methods for ActiveModel::Conversions
|
204
204
|
it "should have to_param once it's saved" do
|
205
|
-
@test_object.to_param.
|
205
|
+
expect(@test_object.to_param).to be_nil
|
206
206
|
@test_object.inner_object.stub(:new? => false, :pid => 'foo:123')
|
207
|
-
@test_object.to_param.
|
207
|
+
expect(@test_object.to_param).to eq('foo:123')
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should have to_key once it's saved" do
|
211
|
-
@test_object.to_key.
|
211
|
+
expect(@test_object.to_key).to be_nil
|
212
212
|
@test_object.inner_object.stub(:new? => false)
|
213
|
-
@test_object.to_key.
|
213
|
+
expect(@test_object.to_key).to eq([@test_object.pid])
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should have to_model when it's saved" do
|
217
|
-
@test_object.to_model.
|
217
|
+
expect(@test_object.to_model).to be @test_object
|
218
218
|
end
|
219
219
|
### end ActiveModel::Conversions
|
220
220
|
|
221
221
|
### Methods for ActiveModel::Naming
|
222
|
-
it
|
223
|
-
FooHistory.model_name.
|
224
|
-
FooHistory.model_name.human.
|
222
|
+
it 'Should know the model_name' do
|
223
|
+
expect(FooHistory.model_name).to eq('FooHistory')
|
224
|
+
expect(FooHistory.model_name.human).to eq('Foo history')
|
225
225
|
end
|
226
226
|
### End ActiveModel::Naming
|
227
227
|
|
228
228
|
|
229
|
-
describe
|
229
|
+
describe '.datastreams' do
|
230
230
|
before do
|
231
231
|
@test_history = FooHistory.new
|
232
232
|
end
|
233
|
-
it
|
234
|
-
@test_history.withText.
|
233
|
+
it 'should create dynamic accessors' do
|
234
|
+
expect(@test_history.withText).to eq(@test_history.datastreams['withText'])
|
235
235
|
end
|
236
|
-
it
|
237
|
-
ds = double('datastream', :dsid=>'eac-cpf')
|
236
|
+
it 'dynamic accessors should convert dashes to underscores' do
|
237
|
+
ds = double('datastream', :dsid => 'eac-cpf')
|
238
238
|
@test_history.add_datastream(ds)
|
239
|
-
@test_history.eac_cpf.
|
239
|
+
expect(@test_history.eac_cpf).to eq(ds)
|
240
240
|
end
|
241
|
-
it
|
242
|
-
ds = double('datastream', :dsid=>'foo_bar')
|
241
|
+
it 'dynamic accessors should not convert datastreams named with underscore' do
|
242
|
+
ds = double('datastream', :dsid => 'foo_bar')
|
243
243
|
@test_history.add_datastream(ds)
|
244
|
-
@test_history.foo_bar.
|
244
|
+
expect(@test_history.foo_bar).to eq(ds)
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'should provide #find' do
|
249
|
-
ActiveFedora::Base.
|
249
|
+
expect(ActiveFedora::Base).to respond_to(:find)
|
250
250
|
end
|
251
251
|
|
252
|
-
it
|
253
|
-
@test_object.
|
252
|
+
it 'should provide .create_date' do
|
253
|
+
expect(@test_object).to respond_to(:create_date)
|
254
254
|
end
|
255
255
|
|
256
|
-
it
|
257
|
-
@test_object.
|
256
|
+
it 'should provide .modified_date' do
|
257
|
+
expect(@test_object).to respond_to(:modified_date)
|
258
258
|
end
|
259
259
|
|
260
260
|
it 'should respond to .rels_ext' do
|
261
|
-
@test_object.
|
261
|
+
expect(@test_object).to respond_to(:rels_ext)
|
262
262
|
end
|
263
263
|
|
264
264
|
describe '.rels_ext' do
|
265
265
|
|
266
266
|
it 'should return the RelsExtDatastream object from the datastreams array' do
|
267
|
-
@test_object.stub(:datastreams => {
|
268
|
-
@test_object.rels_ext.
|
267
|
+
@test_object.stub(:datastreams => {'RELS-EXT' => 'foo'})
|
268
|
+
expect(@test_object.rels_ext).to eq('foo')
|
269
269
|
end
|
270
270
|
end
|
271
271
|
|
272
272
|
it 'should provide #add_relationship' do
|
273
|
-
@test_object.
|
273
|
+
expect(@test_object).to respond_to(:add_relationship)
|
274
274
|
end
|
275
275
|
|
276
276
|
describe '#add_relationship' do
|
277
277
|
it 'should call #add_relationship on the rels_ext datastream' do
|
278
|
-
@test_object.add_relationship(
|
279
|
-
pred = ActiveFedora::Predicates.vocabularies[
|
280
|
-
@test_object.relationships.
|
278
|
+
@test_object.add_relationship('predicate', 'info:fedora/object')
|
279
|
+
pred = ActiveFedora::Predicates.vocabularies['info:fedora/fedora-system:def/relations-external#']['predicate']
|
280
|
+
expect(@test_object.relationships).to have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new('info:fedora/object')))
|
281
281
|
end
|
282
282
|
|
283
|
-
it
|
284
|
-
mock_ds = double(
|
285
|
-
mock_ds.
|
286
|
-
@test_object.datastreams[
|
287
|
-
@test_object.add_relationship(:is_member_of,
|
288
|
-
@test_object.add_relationship(:is_member_of,
|
283
|
+
it 'should update the RELS-EXT datastream and set the datastream as dirty when relationships are added' do
|
284
|
+
mock_ds = double('Rels-Ext')
|
285
|
+
allow(mock_ds).to receive(:content_will_change!)
|
286
|
+
@test_object.datastreams['RELS-EXT'] = mock_ds
|
287
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:5')
|
288
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:10')
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'should add a relationship to an object only if it does not exist already' do
|
292
292
|
next_pid = increment_pid.to_s
|
293
|
-
ActiveFedora::Base.
|
293
|
+
allow(ActiveFedora::Base).to receive(:assign_pid).and_return(next_pid)
|
294
294
|
stub_get(next_pid)
|
295
295
|
|
296
296
|
@test_object3 = ActiveFedora::Base.new
|
297
|
-
@test_object.add_relationship(:has_part
|
298
|
-
@test_object.ids_for_outbound(:has_part).
|
297
|
+
@test_object.add_relationship(:has_part, @test_object3)
|
298
|
+
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
|
299
299
|
#try adding again and make sure not there twice
|
300
|
-
@test_object.add_relationship(:has_part
|
301
|
-
@test_object.ids_for_outbound(:has_part).
|
300
|
+
@test_object.add_relationship(:has_part, @test_object3)
|
301
|
+
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid])
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should add literal relationships if requested' do
|
305
|
-
@test_object.add_relationship(:conforms_to,
|
306
|
-
@test_object.ids_for_outbound(:conforms_to).
|
305
|
+
@test_object.add_relationship(:conforms_to, 'AnInterface', true)
|
306
|
+
expect(@test_object.ids_for_outbound(:conforms_to)).to eq(['AnInterface'])
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
310
|
it 'should provide #remove_relationship' do
|
311
|
-
@test_object.
|
311
|
+
expect(@test_object).to respond_to(:remove_relationship)
|
312
312
|
end
|
313
313
|
|
314
314
|
describe '#remove_relationship' do
|
315
315
|
it 'should remove a relationship from the relationships hash' do
|
316
316
|
@test_object3 = ActiveFedora::Base.new()
|
317
|
-
@test_object3.stub(:pid=>'7')
|
317
|
+
@test_object3.stub(:pid => '7')
|
318
318
|
@test_object4 = ActiveFedora::Base.new()
|
319
|
-
@test_object4.stub(:pid=>'8')
|
320
|
-
@test_object.add_relationship(:has_part
|
321
|
-
@test_object.add_relationship(:has_part
|
319
|
+
@test_object4.stub(:pid => '8')
|
320
|
+
@test_object.add_relationship(:has_part, @test_object3)
|
321
|
+
@test_object.add_relationship(:has_part, @test_object4)
|
322
322
|
#check both are there
|
323
|
-
@test_object.ids_for_outbound(:has_part).
|
324
|
-
@test_object.remove_relationship(:has_part
|
323
|
+
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object3.pid, @test_object4.pid])
|
324
|
+
@test_object.remove_relationship(:has_part, @test_object3)
|
325
325
|
#check only one item removed
|
326
|
-
@test_object.ids_for_outbound(:has_part).
|
327
|
-
@test_object.remove_relationship(:has_part
|
326
|
+
expect(@test_object.ids_for_outbound(:has_part)).to eq([@test_object4.pid])
|
327
|
+
@test_object.remove_relationship(:has_part, @test_object4)
|
328
328
|
#check last item removed and predicate removed since now emtpy
|
329
|
-
@test_object.relationships.size.
|
329
|
+
expect(@test_object.relationships.size).to eq(0)
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
333
|
it 'should provide #relationships' do
|
334
|
-
@test_object.
|
334
|
+
expect(@test_object).to respond_to(:relationships)
|
335
335
|
end
|
336
336
|
|
337
337
|
describe '#relationships' do
|
338
338
|
it 'should return a graph' do
|
339
|
-
@test_object.relationships.kind_of?(RDF::Graph).
|
340
|
-
@test_object.relationships.size.
|
339
|
+
expect(@test_object.relationships.kind_of?(RDF::Graph)).to be_truthy
|
340
|
+
expect(@test_object.relationships.size).to eq(0)
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
344
344
|
describe '.assert_content_model' do
|
345
|
-
it
|
345
|
+
it 'should default to the name of the class' do
|
346
346
|
stub_get(@this_pid)
|
347
347
|
stub_add_ds(@this_pid, ['RELS-EXT'])
|
348
348
|
@test_object.assert_content_model
|
349
|
-
@test_object.relationships(:has_model).
|
349
|
+
expect(@test_object.relationships(:has_model)).to eq(['info:fedora/afmodel:ActiveFedora_Base'])
|
350
350
|
|
351
351
|
end
|
352
352
|
end
|
353
353
|
|
354
354
|
describe '.save' do
|
355
|
-
it
|
355
|
+
it 'should create a new record' do
|
356
356
|
@test_object.stub(:new_record? => true)
|
357
|
-
@test_object.
|
358
|
-
@test_object.
|
357
|
+
expect(@test_object).to receive(:create)
|
358
|
+
expect(@test_object).to receive(:update_index)
|
359
359
|
@test_object.save
|
360
360
|
end
|
361
361
|
|
362
|
-
it
|
362
|
+
it 'should update an existing record' do
|
363
363
|
@test_object.stub(:new_record? => false)
|
364
|
-
@test_object.
|
365
|
-
@test_object.
|
364
|
+
expect(@test_object).to receive(:update_record)
|
365
|
+
expect(@test_object).to receive(:update_index)
|
366
366
|
@test_object.save
|
367
367
|
end
|
368
368
|
end
|
369
369
|
|
370
|
-
describe
|
371
|
-
it
|
370
|
+
describe '#create' do
|
371
|
+
it 'should build a new record and save it' do
|
372
372
|
obj = double()
|
373
|
-
obj.
|
374
|
-
FooHistory.
|
375
|
-
@hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
|
373
|
+
expect(obj).to receive(:save)
|
374
|
+
expect(FooHistory).to receive(:new).and_return(obj)
|
375
|
+
@hist = FooHistory.create(:fubar => 'ta', :swank => 'da')
|
376
376
|
end
|
377
377
|
|
378
378
|
end
|
379
379
|
|
380
|
-
describe
|
381
|
-
it
|
380
|
+
describe '.adapt_to' do
|
381
|
+
it 'should return an adapted object of the requested type' do
|
382
382
|
@test_object = FooHistory.new()
|
383
|
-
@test_object.adapt_to(FooAdaptation).class.
|
383
|
+
expect(@test_object.adapt_to(FooAdaptation).class).to eq(FooAdaptation)
|
384
384
|
end
|
385
|
-
it
|
385
|
+
it 'should not make an additional call to fedora to create the adapted object' do
|
386
386
|
@test_object = FooHistory.new()
|
387
387
|
adapted = @test_object.adapt_to(FooAdaptation)
|
388
388
|
end
|
389
|
-
it
|
389
|
+
it 'should propagate new datastreams to the adapted object' do
|
390
390
|
@test_object = FooHistory.new()
|
391
|
-
@test_object.add_file_datastream(
|
391
|
+
@test_object.add_file_datastream('XXX', :dsid => 'MY_DSID')
|
392
392
|
adapted = @test_object.adapt_to(FooAdaptation)
|
393
|
-
adapted.datastreams.keys.
|
394
|
-
adapted.datastreams['MY_DSID'].content.
|
395
|
-
adapted.datastreams['MY_DSID'].changed
|
393
|
+
expect(adapted.datastreams.keys).to include 'MY_DSID'
|
394
|
+
expect(adapted.datastreams['MY_DSID'].content).to eq('XXX')
|
395
|
+
expect(adapted.datastreams['MY_DSID'].changed?).to be_truthy
|
396
396
|
end
|
397
|
-
it
|
397
|
+
it 'should propagate modified datastreams to the adapted object' do
|
398
398
|
@test_object = FooHistory.new()
|
399
399
|
orig_ds = @test_object.datastreams['someData']
|
400
|
-
orig_ds.content=
|
400
|
+
orig_ds.content = '<YYY/>'
|
401
401
|
adapted = @test_object.adapt_to(FooAdaptation)
|
402
|
-
adapted.datastreams.keys.
|
403
|
-
adapted.datastreams['someData'].
|
404
|
-
adapted.datastreams['someData'].content.strip.
|
405
|
-
adapted.datastreams['someData'].changed
|
402
|
+
expect(adapted.datastreams.keys).to include 'someData'
|
403
|
+
expect(adapted.datastreams['someData']).to eq(orig_ds)
|
404
|
+
expect(adapted.datastreams['someData'].content.strip).to eq('<YYY/>')
|
405
|
+
expect(adapted.datastreams['someData'].changed?).to be_truthy
|
406
406
|
end
|
407
|
-
it
|
407
|
+
it 'should use the datastream definitions from the adapted object' do
|
408
408
|
@test_object = FooHistory.new()
|
409
409
|
adapted = @test_object.adapt_to(FooAdaptation)
|
410
|
-
adapted.datastreams.keys.
|
411
|
-
adapted.datastreams['someData'].class.
|
410
|
+
expect(adapted.datastreams.keys).to include 'someData'
|
411
|
+
expect(adapted.datastreams['someData'].class).to eq(ActiveFedora::OmDatastream)
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
415
|
-
describe
|
415
|
+
describe '.adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel' do
|
416
416
|
subject { FooHistory.new }
|
417
417
|
|
418
|
-
it
|
419
|
-
ActiveFedora::ContentModel.
|
420
|
-
subject.adapt_to_cmodel.
|
418
|
+
it 'should not cast to a random first cmodel if it has a specific cmodel already' do
|
419
|
+
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation])
|
420
|
+
expect(subject.adapt_to_cmodel).to be_kind_of FooHistory
|
421
421
|
end
|
422
|
-
it
|
423
|
-
ActiveFedora::ContentModel.
|
424
|
-
subject.adapt_to_cmodel.
|
422
|
+
it 'should cast to an inherited model over a random one' do
|
423
|
+
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
|
424
|
+
expect(subject.adapt_to_cmodel).to be_kind_of FooInherited
|
425
425
|
end
|
426
|
-
it
|
427
|
-
ActiveFedora::ContentModel.
|
428
|
-
subject.adapt_to_cmodel.
|
426
|
+
it 'should not cast when a cmodel is same as the class' do
|
427
|
+
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooHistory])
|
428
|
+
expect(subject.adapt_to_cmodel).to be === subject
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
432
|
-
describe
|
432
|
+
describe '.adapt_to_cmodel with ActiveFedora::Base' do
|
433
433
|
subject { ActiveFedora::Base.new }
|
434
434
|
|
435
|
-
it
|
436
|
-
ActiveFedora::ContentModel.
|
437
|
-
subject.adapt_to_cmodel.
|
435
|
+
it 'should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)' do
|
436
|
+
expect(ActiveFedora::ContentModel).to receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
|
437
|
+
expect(subject.adapt_to_cmodel).to be_kind_of FooAdaptation
|
438
438
|
end
|
439
439
|
end
|
440
440
|
|
441
441
|
|
442
|
-
describe
|
443
|
-
it
|
444
|
-
@test_object.
|
442
|
+
describe '.to_solr' do
|
443
|
+
it 'should provide .to_solr' do
|
444
|
+
expect(@test_object).to respond_to(:to_solr)
|
445
445
|
end
|
446
446
|
|
447
|
-
it
|
448
|
-
@test_object.
|
449
|
-
@test_object.
|
447
|
+
it 'should add pid, system_create_date, system_modified_date and object_state from object attributes' do
|
448
|
+
expect(@test_object).to receive(:create_date).and_return('2012-03-04T03:12:02Z')
|
449
|
+
expect(@test_object).to receive(:modified_date).and_return('2012-03-07T03:12:02Z')
|
450
450
|
@test_object.stub(pid: 'changeme:123')
|
451
|
-
@test_object.state =
|
451
|
+
@test_object.state = 'D'
|
452
452
|
solr_doc = @test_object.to_solr
|
453
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
454
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
455
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
456
|
-
solr_doc[:id].
|
453
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('system_create', :stored_sortable, type: :date)]).to eql('2012-03-04T03:12:02Z')
|
454
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('system_modified', :stored_sortable, type: :date)]).to eql('2012-03-07T03:12:02Z')
|
455
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('object_state', :stored_sortable)]).to eql('D')
|
456
|
+
expect(solr_doc[:id]).to eql('changeme:123')
|
457
457
|
end
|
458
458
|
|
459
|
-
it
|
460
|
-
@test_object.add_relationship(:has_part,
|
461
|
-
solr_doc = @test_object.to_solr(
|
462
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
463
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
464
|
-
solr_doc[
|
465
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
459
|
+
it 'should omit base metadata and RELS-EXT if :model_only==true' do
|
460
|
+
@test_object.add_relationship(:has_part, 'foo', true)
|
461
|
+
solr_doc = @test_object.to_solr({}, :model_only => true)
|
462
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('system_create', type: :date)]).to be_nil
|
463
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('system_modified', type: :date)]).to be_nil
|
464
|
+
expect(solr_doc['id']).to be_nil
|
465
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('has_part', :symbol)]).to be_nil
|
466
466
|
end
|
467
467
|
|
468
|
-
it
|
468
|
+
it 'should add self.class as the :active_fedora_model' do
|
469
469
|
stub_get(@this_pid)
|
470
470
|
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
471
471
|
@test_history = FooHistory.new()
|
472
472
|
solr_doc = @test_history.to_solr
|
473
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
473
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('active_fedora_model', :stored_sortable)]).to eql('FooHistory')
|
474
474
|
end
|
475
475
|
|
476
|
-
it
|
477
|
-
mock1 = double(
|
478
|
-
mock2 = double(
|
479
|
-
ngds = double(
|
480
|
-
ngds.
|
481
|
-
mock1.
|
482
|
-
mock2.
|
476
|
+
it 'should call .to_solr on all SimpleDatastreams and OmDatastreams, passing the resulting document to solr' do
|
477
|
+
mock1 = double('ds1', :to_solr => {})
|
478
|
+
mock2 = double('ds2', :to_solr => {})
|
479
|
+
ngds = double('ngds', :to_solr => {})
|
480
|
+
expect(ngds).to receive(:solrize_profile)
|
481
|
+
expect(mock1).to receive(:solrize_profile)
|
482
|
+
expect(mock2).to receive(:solrize_profile)
|
483
483
|
|
484
|
-
@test_object.
|
485
|
-
@test_object.
|
484
|
+
expect(@test_object).to receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
|
485
|
+
expect(@test_object).to receive(:solrize_relationships)
|
486
486
|
@test_object.to_solr
|
487
487
|
end
|
488
|
-
it
|
489
|
-
mock = double(
|
490
|
-
mock.
|
488
|
+
it 'should call .to_solr on all RDFDatastreams, passing the resulting document to solr' do
|
489
|
+
mock = double('ds1', :to_solr => {})
|
490
|
+
expect(mock).to receive(:solrize_profile)
|
491
491
|
|
492
|
-
@test_object.
|
493
|
-
@test_object.
|
492
|
+
expect(@test_object).to receive(:datastreams).twice.and_return({:ds1 => mock})
|
493
|
+
expect(@test_object).to receive(:solrize_relationships)
|
494
494
|
@test_object.to_solr
|
495
495
|
end
|
496
496
|
|
497
|
-
it
|
498
|
-
@test_object.add_relationship(:has_collection_member,
|
497
|
+
it 'should call .to_solr on the relationships rels-ext is dirty' do
|
498
|
+
@test_object.add_relationship(:has_collection_member, 'info:fedora/test:member')
|
499
499
|
rels_ext = @test_object.rels_ext
|
500
|
-
rels_ext.
|
501
|
-
@test_object.
|
500
|
+
expect(rels_ext).to be_changed
|
501
|
+
expect(@test_object).to receive(:solrize_relationships)
|
502
502
|
@test_object.to_solr
|
503
503
|
end
|
504
504
|
|
505
505
|
end
|
506
506
|
|
507
|
-
describe
|
508
|
-
it
|
509
|
-
@test_object.inner_object.
|
510
|
-
@test_object.label.
|
507
|
+
describe '.label' do
|
508
|
+
it 'should return the label of the inner object' do
|
509
|
+
expect(@test_object.inner_object).to receive(:label).and_return('foo label')
|
510
|
+
expect(@test_object.label).to eq('foo label')
|
511
511
|
end
|
512
512
|
end
|
513
513
|
|
514
|
-
describe
|
515
|
-
it
|
516
|
-
@test_object.label.
|
517
|
-
@test_object.label =
|
518
|
-
@test_object.label.
|
514
|
+
describe '.label=' do
|
515
|
+
it 'should set the label of the inner object' do
|
516
|
+
expect(@test_object.label).not_to eq('foo label')
|
517
|
+
@test_object.label = 'foo label'
|
518
|
+
expect(@test_object.label).to eq('foo label')
|
519
519
|
end
|
520
520
|
end
|
521
521
|
|
522
522
|
|
523
|
-
describe
|
524
|
-
it
|
525
|
-
mock_ds = double(
|
526
|
-
@test_object.
|
527
|
-
@test_object.get_values_from_datastream(
|
523
|
+
describe 'get_values_from_datastream' do
|
524
|
+
it 'should look up the named datastream and call get_values with the given pointer/field_name' do
|
525
|
+
mock_ds = double('Datastream', :get_values => ['value1', 'value2'])
|
526
|
+
allow(@test_object).to receive(:datastreams).and_return({'ds1' => mock_ds})
|
527
|
+
expect(@test_object.get_values_from_datastream('ds1', '--my xpath--')).to eq(['value1', 'value2'])
|
528
528
|
end
|
529
529
|
end
|
530
530
|
|
531
|
-
describe
|
532
|
-
it
|
533
|
-
mock_desc_metadata = double(
|
534
|
-
mock_properties = double(
|
535
|
-
mock_ds_hash = {'descMetadata'=>mock_desc_metadata, 'properties'=>mock_properties}
|
531
|
+
describe 'update_datastream_attributes' do
|
532
|
+
it 'should look up any datastreams specified as keys in the given hash and call update_attributes on the datastream' do
|
533
|
+
mock_desc_metadata = double('descMetadata')
|
534
|
+
mock_properties = double('properties')
|
535
|
+
mock_ds_hash = {'descMetadata' => mock_desc_metadata, 'properties' => mock_properties}
|
536
536
|
|
537
537
|
ds_values_hash = {
|
538
|
-
|
539
|
-
|
538
|
+
'descMetadata' => { [{:person => 0}, :role] => {'0' => 'role1', '1' => 'role2', '2' => 'role3'} },
|
539
|
+
'properties' => { 'notes' => 'foo' }
|
540
540
|
}
|
541
541
|
m = FooHistory.new
|
542
|
-
m.
|
543
|
-
mock_desc_metadata.
|
544
|
-
mock_properties.
|
542
|
+
allow(m).to receive(:datastreams).and_return(mock_ds_hash)
|
543
|
+
expect(mock_desc_metadata).to receive(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
|
544
|
+
expect(mock_properties).to receive(:update_indexed_attributes).with( ds_values_hash['properties'] )
|
545
545
|
m.update_datastream_attributes( ds_values_hash )
|
546
546
|
end
|
547
|
-
it
|
548
|
-
|
547
|
+
it 'should not do anything and should return an empty hash if the specified datastream does not exist' do
|
548
|
+
skip "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
549
549
|
ds_values_hash = {
|
550
|
-
|
550
|
+
'nonexistentDatastream' => { 'notes' => 'foo' }
|
551
551
|
}
|
552
552
|
m = FooHistory.new
|
553
553
|
untouched_xml = m.to_xml
|
554
|
-
m.update_datastream_attributes( ds_values_hash ).
|
555
|
-
m.to_xml.
|
554
|
+
expect(m.update_datastream_attributes( ds_values_hash )).to eq({})
|
555
|
+
expect(m.to_xml).to eq(untouched_xml)
|
556
556
|
end
|
557
557
|
end
|
558
558
|
|
559
|
-
describe
|
560
|
-
it
|
559
|
+
describe 'update_attributes' do
|
560
|
+
it 'should set the attributes and save' do
|
561
561
|
m = FooHistory.new
|
562
|
-
att= {
|
562
|
+
att = {'fubar' => '1234', 'baz' => 'stuff'}
|
563
563
|
|
564
|
-
m.
|
565
|
-
m.
|
566
|
-
m.
|
564
|
+
expect(m).to receive(:fubar=).with('1234')
|
565
|
+
expect(m).to receive(:baz=).with('stuff')
|
566
|
+
expect(m).to receive(:save)
|
567
567
|
m.update_attributes(att)
|
568
568
|
end
|
569
569
|
end
|
570
570
|
|
571
|
-
describe
|
572
|
-
it
|
571
|
+
describe 'update' do
|
572
|
+
it 'should set the attributes and save' do
|
573
573
|
m = FooHistory.new
|
574
|
-
att= {
|
574
|
+
att = {'fubar' => '1234', 'baz' => 'stuff'}
|
575
575
|
|
576
|
-
m.
|
577
|
-
m.
|
578
|
-
m.
|
576
|
+
expect(m).to receive(:fubar=).with('1234')
|
577
|
+
expect(m).to receive(:baz=).with('stuff')
|
578
|
+
expect(m).to receive(:save)
|
579
579
|
m.update(att)
|
580
580
|
end
|
581
581
|
end
|
582
582
|
|
583
|
-
describe
|
583
|
+
describe 'update_indexed_attributes' do
|
584
584
|
before do
|
585
|
-
Deprecation.
|
585
|
+
expect(Deprecation).to receive(:warn).at_least(1).times
|
586
586
|
end
|
587
|
-
it
|
587
|
+
it 'should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams' do
|
588
588
|
m = FooHistory.new
|
589
|
-
att= {
|
589
|
+
att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
|
590
590
|
|
591
|
-
m.datastreams['someData'].
|
592
|
-
m.datastreams[
|
593
|
-
m.datastreams['withText2'].
|
591
|
+
expect(m.datastreams['someData']).to receive(:update_indexed_attributes)
|
592
|
+
expect(m.datastreams['withText']).to receive(:update_indexed_attributes)
|
593
|
+
expect(m.datastreams['withText2']).to receive(:update_indexed_attributes)
|
594
594
|
m.update_indexed_attributes(att)
|
595
595
|
end
|
596
|
-
it
|
597
|
-
att= {
|
596
|
+
it 'should take a :datastreams argument' do
|
597
|
+
att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
|
598
598
|
stub_get(@this_pid)
|
599
599
|
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
600
600
|
m = FooHistory.new()
|
601
|
-
m.update_indexed_attributes(att, :datastreams=>
|
602
|
-
m.
|
603
|
-
m.datastreams['someData'].fubar.
|
604
|
-
m.datastreams[
|
605
|
-
m.datastreams['withText2'].fubar.
|
601
|
+
m.update_indexed_attributes(att, :datastreams => 'withText')
|
602
|
+
expect(m).not_to be_nil
|
603
|
+
expect(m.datastreams['someData'].fubar).to eq([])
|
604
|
+
expect(m.datastreams['withText'].fubar).to eq(['mork', 'york', 'mangle'])
|
605
|
+
expect(m.datastreams['withText2'].fubar).to eq([])
|
606
606
|
|
607
|
-
att= {
|
608
|
-
m.update_indexed_attributes(att, :datastreams=>[
|
609
|
-
m.
|
610
|
-
m.datastreams['someData'].fubar.
|
611
|
-
m.datastreams['withText2'].fubar.
|
607
|
+
att = {'fubar' => {'-1' => 'tork', '0' => 'work', '1' => 'bork'}}
|
608
|
+
m.update_indexed_attributes(att, :datastreams => ['someData', 'withText2'])
|
609
|
+
expect(m).not_to be_nil
|
610
|
+
expect(m.datastreams['someData'].fubar).to eq(['tork', 'work', 'bork'])
|
611
|
+
expect(m.datastreams['withText2'].fubar).to eq(['tork', 'work', 'bork'])
|
612
612
|
end
|
613
613
|
end
|
614
614
|
|
@@ -622,21 +622,21 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
622
622
|
end
|
623
623
|
end
|
624
624
|
|
625
|
-
describe
|
626
|
-
it
|
625
|
+
describe '.solrize_relationships' do
|
626
|
+
it 'should serialize the relationships into a Hash' do
|
627
627
|
graph = RDF::Graph.new
|
628
|
-
subject = RDF::URI.new
|
628
|
+
subject = RDF::URI.new 'info:fedora/test:sample_pid'
|
629
629
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
630
630
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
631
631
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
632
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to),
|
632
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), 'AnInterface')
|
633
633
|
|
634
|
-
@test_object.
|
634
|
+
expect(@test_object).to receive(:relationships).and_return(graph)
|
635
635
|
solr_doc = @test_object.solrize_relationships
|
636
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
637
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
638
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
639
|
-
solr_doc[ActiveFedora::SolrService.solr_name(
|
636
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('is_member_of', :symbol)]).to eq('info:fedora/demo:10')
|
637
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('is_part_of', :symbol)]).to eq('info:fedora/demo:11')
|
638
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('has_part', :symbol)]).to eq('info:fedora/demo:12')
|
639
|
+
expect(solr_doc[ActiveFedora::SolrService.solr_name('conforms_to', :symbol)]).to eq('AnInterface')
|
640
640
|
end
|
641
641
|
end
|
642
642
|
end
|