active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- 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/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- 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 +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- 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 +68 -74
- 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 +48 -107
- 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 +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -1,82 +1,110 @@
|
|
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
|
-
|
13
|
-
|
14
|
-
mock_ss = double(
|
15
|
-
|
16
|
-
|
11
|
+
mock_conn = double("SolrConnection")
|
12
|
+
mock_conn.should_receive(:add)
|
13
|
+
mock_conn.should_receive(:commit)
|
14
|
+
mock_ss = double("SolrService")
|
15
|
+
mock_ss.stub(:conn).and_return(mock_conn)
|
16
|
+
ActiveFedora::SolrService.stub(: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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
mock1.should_receive(:solrize_profile).and_return({})
|
27
|
+
mock2.should_receive(:solrize_profile).and_return({})
|
28
|
+
mock3.should_receive(:solrize_profile).and_return({})
|
29
|
+
@test_object.should_receive(:datastreams).twice.and_return(mock_datastreams)
|
30
|
+
@test_object.should_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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
mock1.should_receive(:solrize_profile).and_return({})
|
42
|
+
mock2.should_receive(:solrize_profile).and_return({})
|
43
|
+
mock3.should_receive(:solrize_profile).and_return({})
|
44
|
+
@test_object.should_receive(:datastreams).twice.and_return(mock_datastreams)
|
45
|
+
@test_object.should_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
|
-
|
62
|
-
mock_conn = double(
|
63
|
-
|
64
|
-
|
65
|
-
mock_ss = double(
|
66
|
-
|
67
|
-
|
59
|
+
|
60
|
+
it "should delete object from repository and index" do
|
61
|
+
@test_object.inner_object.stub(:delete)
|
62
|
+
mock_conn = double("SolrConnection")
|
63
|
+
mock_conn.should_receive(:delete_by_id).with(nil)
|
64
|
+
mock_conn.should_receive(:commit)
|
65
|
+
mock_ss = double("SolrService")
|
66
|
+
mock_ss.stub(:conn).and_return(mock_conn)
|
67
|
+
ActiveFedora::SolrService.stub(: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
|
-
|
72
|
+
|
73
|
+
describe '#pids_from_uris' do
|
74
|
+
it "should strip the info:fedora/ out of a given string" do
|
75
|
+
ActiveFedora::Base.pids_from_uris("info:fedora/FOOBAR").should == "FOOBAR"
|
76
76
|
end
|
77
|
-
it
|
78
|
-
|
77
|
+
it "should accept an array of strings"do
|
78
|
+
ActiveFedora::Base.pids_from_uris(["info:fedora/FOOBAR", "info:fedora/BAZFOO"]).should == ["FOOBAR", "BAZFOO"]
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
describe "to_class_uri" do
|
83
|
+
before :all do
|
84
|
+
module SpecModel
|
85
|
+
class CamelCased < ActiveFedora::Base
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
after :all do
|
91
|
+
SpecModel.send(:remove_const, :CamelCased)
|
92
|
+
end
|
93
|
+
subject {SpecModel::CamelCased}
|
94
|
+
|
95
|
+
its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased' }
|
96
|
+
|
97
|
+
context "with the namespace declared in the model" do
|
98
|
+
before do
|
99
|
+
subject.stub(:pid_namespace).and_return("test-cModel")
|
100
|
+
end
|
101
|
+
its(:to_class_uri) {should == 'info:fedora/test-cModel:SpecModel_CamelCased' }
|
102
|
+
end
|
103
|
+
context "with the suffix declared in the model" do
|
104
|
+
before do
|
105
|
+
subject.stub(:pid_suffix).and_return("-TEST-SUFFIX")
|
106
|
+
end
|
107
|
+
its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
|
108
|
+
end
|
109
|
+
end
|
82
110
|
end
|
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
|
-
|
8
|
+
it "should record the decendants" do
|
9
|
+
ActiveFedora::Base.descendants.should include(ModsArticle, SpecialThing)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
|
13
|
+
describe "sharding" do
|
14
|
+
it "should have a shard_index" do
|
15
|
+
ActiveFedora::Base.shard_index(@this_pid).should == 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
|
-
|
21
|
+
ActiveFedora.config.stub(:sharded?).and_return(false)
|
22
22
|
ActiveFedora::Base.fedora_connection = {}
|
23
|
-
|
23
|
+
ActiveFedora.config.stub(:credentials).and_return(:url=>'myfedora')
|
24
24
|
end
|
25
|
-
it {
|
26
|
-
it
|
27
|
-
|
25
|
+
it { should be_kind_of Rubydora::Repository}
|
26
|
+
it "should be the standard connection" do
|
27
|
+
subject.client.url.should == '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
|
-
|
33
|
+
stubfedora = double("Fedora")
|
34
|
+
stubfedora.should_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
|
-
|
36
|
+
ActiveFedora::RubydoraConnection.should_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
|
-
|
40
|
+
describe "shard_index" do
|
41
|
+
it "should always return zero (the first and only connection)" do
|
42
|
+
ActiveFedora::Base.shard_index('test:bar').should == 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
|
-
|
48
|
+
ActiveFedora.config.stub(:sharded?).and_return(true)
|
49
49
|
ActiveFedora::Base.fedora_connection = {}
|
50
|
-
|
51
|
-
end
|
52
|
-
describe
|
53
|
-
it
|
54
|
-
stubhard1 = double(
|
55
|
-
stubhard2 = double(
|
56
|
-
|
57
|
-
|
50
|
+
ActiveFedora.config.stub(: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
|
+
stubhard1.should_receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
|
57
|
+
stubhard2.should_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
|
-
|
65
|
-
|
62
|
+
describe "shard_index" do
|
63
|
+
it "should use modulo of md5 of the pid to distribute objects across shards" do
|
64
|
+
ActiveFedora::Base.shard_index('test:bar').should == 0
|
65
|
+
ActiveFedora::Base.shard_index('test:nanana').should == 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
|
-
|
71
|
+
it "should be shard1" do
|
72
|
+
subject.client.url.should == '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
|
-
|
77
|
+
it "should be shard1" do
|
78
|
+
subject.client.url.should == '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
|
-
|
89
|
-
and_yield(double(pid:
|
90
|
-
and_yield(double(pid:
|
91
|
-
and_yield(double(pid:
|
92
|
-
and_yield(double(pid:
|
86
|
+
describe "reindex_everything" do
|
87
|
+
it "should call update_index on every object except for the fedora-system objects" do
|
88
|
+
Rubydora::Repository.any_instance.should_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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
mock_update.should_receive(:update_index).exactly(3).times
|
96
|
+
ActiveFedora::Base.should_receive(:find).with('XXX').and_return(mock_update)
|
97
|
+
ActiveFedora::Base.should_receive(:find).with('YYY').and_return(mock_update)
|
98
|
+
ActiveFedora::Base.should_receive(:find).with('ZZZ').and_return(mock_update)
|
99
99
|
ActiveFedora::Base.reindex_everything
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
query_string =
|
104
|
-
|
105
|
-
and_yield(double(pid:
|
102
|
+
it "should accept a query param for the search" do
|
103
|
+
query_string = "pid~*"
|
104
|
+
Rubydora::Repository.any_instance.should_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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
mock_update.should_receive(:update_index).exactly(3).times
|
108
|
+
ActiveFedora::Base.should_receive(:find).with('XXX').and_return(mock_update)
|
109
|
+
ActiveFedora::Base.should_receive(:find).with('YYY').and_return(mock_update)
|
110
|
+
ActiveFedora::Base.should_receive(:find).with('ZZZ').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
|
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
|
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
|
126
|
-
m.field
|
127
|
-
end
|
128
|
-
|
129
|
-
|
125
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel", :autocreate => true do |m|
|
126
|
+
m.field "fubar", :text
|
127
|
+
end
|
128
|
+
has_attributes :fubar, datastream: 'withText', multiple: true
|
129
|
+
has_attributes :swank, datastream: 'someData', multiple: true
|
130
130
|
end
|
131
131
|
class FooAdaptation < ActiveFedora::Base
|
132
|
-
has_metadata :type
|
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
|
-
|
154
|
-
|
153
|
+
Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
|
154
|
+
ActiveFedora::Base.stub(: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
|
-
|
161
|
+
ActiveFedora::SolrService.stub(:instance)
|
162
162
|
#@test_object.delete
|
163
163
|
rescue
|
164
164
|
end
|
@@ -166,477 +166,406 @@ 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
|
-
|
171
|
+
Rubydora::DigitalObject.any_instance.should_receive(:save).never
|
172
172
|
result = ActiveFedora::Base.new(nil)
|
173
|
-
|
173
|
+
result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
|
174
174
|
end
|
175
175
|
|
176
|
-
it
|
177
|
-
|
178
|
-
|
176
|
+
it "should not save or get an pid on init" do
|
177
|
+
Rubydora::DigitalObject.any_instance.should_receive(:save).never
|
178
|
+
ActiveFedora::Base.should_receive(:assign_pid).never
|
179
179
|
f = FooHistory.new
|
180
180
|
end
|
181
181
|
|
182
|
-
it
|
183
|
-
f = FooHistory.new(:pid
|
184
|
-
|
182
|
+
it "should be able to create with a custom pid" do
|
183
|
+
f = FooHistory.new(:pid=>'numbnuts:1')
|
184
|
+
f.pid.should == 'numbnuts:1'
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
describe
|
189
|
-
it
|
190
|
-
|
188
|
+
describe ".datastream_class_for_name" do
|
189
|
+
it "should return the specifed class" do
|
190
|
+
FooAdaptation.datastream_class_for_name('someData').should == ActiveFedora::OmDatastream
|
191
191
|
end
|
192
|
-
it
|
193
|
-
|
192
|
+
it "should return the specifed class" do
|
193
|
+
FooAdaptation.datastream_class_for_name('content').should == ActiveFedora::Datastream
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
describe
|
198
|
-
it
|
199
|
-
|
197
|
+
describe ".internal_uri" do
|
198
|
+
it "should return pid as fedors uri" do
|
199
|
+
@test_object.internal_uri.should 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
|
-
|
205
|
+
@test_object.to_param.should be_nil
|
206
206
|
@test_object.inner_object.stub(:new? => false, :pid => 'foo:123')
|
207
|
-
|
207
|
+
@test_object.to_param.should == 'foo:123'
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should have to_key once it's saved" do
|
211
|
-
|
212
|
-
@test_object.inner_object.stub(
|
213
|
-
|
211
|
+
@test_object.to_key.should be_nil
|
212
|
+
@test_object.inner_object.stub(new?: false, pid: 'foo:123')
|
213
|
+
@test_object.to_key.should == ['foo:123']
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should have to_model when it's saved" do
|
217
|
-
|
217
|
+
@test_object.to_model.should be @test_object
|
218
218
|
end
|
219
219
|
### end ActiveModel::Conversions
|
220
220
|
|
221
221
|
### Methods for ActiveModel::Naming
|
222
|
-
it
|
223
|
-
|
224
|
-
|
222
|
+
it "Should know the model_name" do
|
223
|
+
FooHistory.model_name.should == 'FooHistory'
|
224
|
+
FooHistory.model_name.human.should == 'Foo history'
|
225
225
|
end
|
226
226
|
### End ActiveModel::Naming
|
227
227
|
|
228
228
|
|
229
|
-
describe
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
it 'should create dynamic accessors' do
|
234
|
-
expect(@test_history.withText).to eq(@test_history.datastreams['withText'])
|
229
|
+
describe ".datastreams" do
|
230
|
+
let(:test_history) { FooHistory.new }
|
231
|
+
it "should create accessors for datastreams declared with has_metadata" do
|
232
|
+
test_history.withText.should == test_history.datastreams['withText']
|
235
233
|
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
234
|
+
describe "dynamic accessors" do
|
235
|
+
before do
|
236
|
+
test_history.add_datastream(ds)
|
237
|
+
test_history.class.build_datastream_accessor(ds.dsid)
|
238
|
+
end
|
239
|
+
describe "when the datastream is named with dash" do
|
240
|
+
let(:ds) {double('datastream', :dsid=>'eac-cpf')}
|
241
|
+
it "should convert dashes to underscores" do
|
242
|
+
test_history.eac_cpf.should == ds
|
243
|
+
end
|
244
|
+
end
|
245
|
+
describe "when the datastream is named with underscore" do
|
246
|
+
let (:ds) { double('datastream', :dsid=>'foo_bar') }
|
247
|
+
it "should preserve the underscore" do
|
248
|
+
test_history.foo_bar.should == ds
|
249
|
+
end
|
250
|
+
end
|
245
251
|
end
|
246
252
|
end
|
247
253
|
|
248
254
|
it 'should provide #find' do
|
249
|
-
|
255
|
+
ActiveFedora::Base.should respond_to(:find)
|
250
256
|
end
|
251
257
|
|
252
|
-
it
|
253
|
-
|
258
|
+
it "should provide .create_date" do
|
259
|
+
@test_object.should respond_to(:create_date)
|
254
260
|
end
|
255
261
|
|
256
|
-
it
|
257
|
-
|
262
|
+
it "should provide .modified_date" do
|
263
|
+
@test_object.should respond_to(:modified_date)
|
258
264
|
end
|
259
265
|
|
260
266
|
it 'should respond to .rels_ext' do
|
261
|
-
|
267
|
+
@test_object.should respond_to(:rels_ext)
|
262
268
|
end
|
263
269
|
|
264
270
|
describe '.rels_ext' do
|
265
271
|
|
266
272
|
it 'should return the RelsExtDatastream object from the datastreams array' do
|
267
|
-
@test_object.stub(:datastreams => {
|
268
|
-
|
273
|
+
@test_object.stub(:datastreams => {"RELS-EXT" => "foo"})
|
274
|
+
@test_object.rels_ext.should == "foo"
|
269
275
|
end
|
270
276
|
end
|
271
277
|
|
272
278
|
it 'should provide #add_relationship' do
|
273
|
-
|
279
|
+
@test_object.should respond_to(:add_relationship)
|
274
280
|
end
|
275
281
|
|
276
282
|
describe '#add_relationship' do
|
277
283
|
it 'should call #add_relationship on the rels_ext datastream' do
|
278
|
-
@test_object.add_relationship(
|
279
|
-
pred = ActiveFedora::Predicates.vocabularies[
|
280
|
-
|
284
|
+
@test_object.add_relationship("predicate", "info:fedora/object")
|
285
|
+
pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
|
286
|
+
@test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
|
281
287
|
end
|
282
288
|
|
283
|
-
it
|
284
|
-
mock_ds = double(
|
285
|
-
|
286
|
-
@test_object.datastreams[
|
287
|
-
@test_object.add_relationship(:is_member_of,
|
288
|
-
@test_object.add_relationship(:is_member_of,
|
289
|
+
it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
|
290
|
+
mock_ds = double("Rels-Ext")
|
291
|
+
mock_ds.stub(:content_will_change!)
|
292
|
+
@test_object.datastreams["RELS-EXT"] = mock_ds
|
293
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
294
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
289
295
|
end
|
290
296
|
|
291
297
|
it 'should add a relationship to an object only if it does not exist already' do
|
292
298
|
next_pid = increment_pid.to_s
|
293
|
-
|
299
|
+
ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
|
294
300
|
stub_get(next_pid)
|
295
301
|
|
296
302
|
@test_object3 = ActiveFedora::Base.new
|
297
|
-
@test_object.add_relationship(:has_part
|
298
|
-
|
303
|
+
@test_object.add_relationship(:has_part,@test_object3)
|
304
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
|
299
305
|
#try adding again and make sure not there twice
|
300
|
-
@test_object.add_relationship(:has_part
|
301
|
-
|
306
|
+
@test_object.add_relationship(:has_part,@test_object3)
|
307
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
|
302
308
|
end
|
303
309
|
|
304
310
|
it 'should add literal relationships if requested' do
|
305
|
-
@test_object.add_relationship(:conforms_to,
|
306
|
-
|
311
|
+
@test_object.add_relationship(:conforms_to,"AnInterface",true)
|
312
|
+
@test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
|
307
313
|
end
|
308
314
|
end
|
309
315
|
|
310
316
|
it 'should provide #remove_relationship' do
|
311
|
-
|
317
|
+
@test_object.should respond_to(:remove_relationship)
|
312
318
|
end
|
313
319
|
|
314
320
|
describe '#remove_relationship' do
|
315
321
|
it 'should remove a relationship from the relationships hash' do
|
316
322
|
@test_object3 = ActiveFedora::Base.new()
|
317
|
-
@test_object3.stub(:pid
|
323
|
+
@test_object3.stub(:pid=>'7')
|
318
324
|
@test_object4 = ActiveFedora::Base.new()
|
319
|
-
@test_object4.stub(:pid
|
320
|
-
@test_object.add_relationship(:has_part
|
321
|
-
@test_object.add_relationship(:has_part
|
325
|
+
@test_object4.stub(:pid=>'8')
|
326
|
+
@test_object.add_relationship(:has_part,@test_object3)
|
327
|
+
@test_object.add_relationship(:has_part,@test_object4)
|
322
328
|
#check both are there
|
323
|
-
|
324
|
-
@test_object.remove_relationship(:has_part
|
329
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid,@test_object4.pid]
|
330
|
+
@test_object.remove_relationship(:has_part,@test_object3)
|
325
331
|
#check only one item removed
|
326
|
-
|
327
|
-
@test_object.remove_relationship(:has_part
|
332
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object4.pid]
|
333
|
+
@test_object.remove_relationship(:has_part,@test_object4)
|
328
334
|
#check last item removed and predicate removed since now emtpy
|
329
|
-
|
335
|
+
@test_object.relationships.size.should == 0
|
330
336
|
end
|
331
337
|
end
|
332
338
|
|
333
339
|
it 'should provide #relationships' do
|
334
|
-
|
340
|
+
@test_object.should respond_to(:relationships)
|
335
341
|
end
|
336
342
|
|
337
343
|
describe '#relationships' do
|
338
344
|
it 'should return a graph' do
|
339
|
-
|
340
|
-
|
345
|
+
@test_object.relationships.kind_of?(RDF::Graph).should be_true
|
346
|
+
@test_object.relationships.size.should == 0
|
341
347
|
end
|
342
348
|
end
|
343
349
|
|
344
350
|
describe '.assert_content_model' do
|
345
|
-
it
|
351
|
+
it "should default to the name of the class" do
|
346
352
|
stub_get(@this_pid)
|
347
353
|
stub_add_ds(@this_pid, ['RELS-EXT'])
|
348
354
|
@test_object.assert_content_model
|
349
|
-
|
355
|
+
@test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
|
350
356
|
|
351
357
|
end
|
352
358
|
end
|
353
359
|
|
354
360
|
describe '.save' do
|
355
|
-
it
|
361
|
+
it "should create a new record" do
|
356
362
|
@test_object.stub(:new_record? => true)
|
357
|
-
|
358
|
-
|
363
|
+
@test_object.should_receive(:assign_pid)
|
364
|
+
@test_object.should_receive(:serialize_datastreams)
|
365
|
+
@test_object.inner_object.should_receive(:save)
|
366
|
+
@test_object.should_receive(:update_index)
|
359
367
|
@test_object.save
|
360
368
|
end
|
361
369
|
|
362
|
-
it
|
370
|
+
it "should update an existing record" do
|
363
371
|
@test_object.stub(:new_record? => false)
|
364
|
-
|
365
|
-
|
372
|
+
@test_object.should_receive(:serialize_datastreams)
|
373
|
+
@test_object.inner_object.should_receive(:save)
|
374
|
+
@test_object.should_receive(:update_index)
|
366
375
|
@test_object.save
|
367
376
|
end
|
368
377
|
end
|
369
378
|
|
370
|
-
describe
|
371
|
-
it
|
379
|
+
describe "#create" do
|
380
|
+
it "should build a new record and save it" do
|
372
381
|
obj = double()
|
373
|
-
|
374
|
-
|
375
|
-
@hist = FooHistory.create(:fubar
|
382
|
+
obj.should_receive(:save)
|
383
|
+
FooHistory.should_receive(:new).and_return(obj)
|
384
|
+
@hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
|
376
385
|
end
|
377
386
|
|
378
387
|
end
|
379
388
|
|
380
|
-
describe
|
381
|
-
it
|
389
|
+
describe ".adapt_to" do
|
390
|
+
it "should return an adapted object of the requested type" do
|
382
391
|
@test_object = FooHistory.new()
|
383
|
-
|
392
|
+
@test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
|
384
393
|
end
|
385
|
-
it
|
394
|
+
it "should not make an additional call to fedora to create the adapted object" do
|
386
395
|
@test_object = FooHistory.new()
|
387
396
|
adapted = @test_object.adapt_to(FooAdaptation)
|
388
397
|
end
|
389
|
-
it
|
398
|
+
it "should propagate new datastreams to the adapted object" do
|
390
399
|
@test_object = FooHistory.new()
|
391
|
-
@test_object.add_file_datastream(
|
400
|
+
@test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
|
392
401
|
adapted = @test_object.adapt_to(FooAdaptation)
|
393
|
-
|
394
|
-
|
395
|
-
|
402
|
+
adapted.datastreams.keys.should include 'MY_DSID'
|
403
|
+
adapted.datastreams['MY_DSID'].content.should == "XXX"
|
404
|
+
adapted.datastreams['MY_DSID'].changed?.should be_true
|
396
405
|
end
|
397
|
-
it
|
406
|
+
it "should propagate modified datastreams to the adapted object" do
|
398
407
|
@test_object = FooHistory.new()
|
399
408
|
orig_ds = @test_object.datastreams['someData']
|
400
|
-
orig_ds.content
|
409
|
+
orig_ds.content="<YYY/>"
|
401
410
|
adapted = @test_object.adapt_to(FooAdaptation)
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
411
|
+
adapted.datastreams.keys.should include 'someData'
|
412
|
+
adapted.datastreams['someData'].should == orig_ds
|
413
|
+
adapted.datastreams['someData'].content.strip.should == "<YYY/>"
|
414
|
+
adapted.datastreams['someData'].changed?.should be_true
|
406
415
|
end
|
407
|
-
it
|
416
|
+
it "should use the datastream definitions from the adapted object" do
|
408
417
|
@test_object = FooHistory.new()
|
409
418
|
adapted = @test_object.adapt_to(FooAdaptation)
|
410
|
-
|
411
|
-
|
419
|
+
adapted.datastreams.keys.should include 'someData'
|
420
|
+
adapted.datastreams['someData'].class.should == ActiveFedora::OmDatastream
|
412
421
|
end
|
413
422
|
end
|
414
423
|
|
415
|
-
describe
|
424
|
+
describe ".adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel" do
|
416
425
|
subject { FooHistory.new }
|
417
426
|
|
418
|
-
it
|
419
|
-
|
420
|
-
|
427
|
+
it "should not cast to a random first cmodel if it has a specific cmodel already" do
|
428
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation])
|
429
|
+
subject.adapt_to_cmodel.should be_kind_of FooHistory
|
421
430
|
end
|
422
|
-
it
|
423
|
-
|
424
|
-
|
431
|
+
it "should cast to an inherited model over a random one" do
|
432
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
|
433
|
+
subject.adapt_to_cmodel.should be_kind_of FooInherited
|
425
434
|
end
|
426
|
-
it
|
427
|
-
|
428
|
-
|
435
|
+
it "should not cast when a cmodel is same as the class" do
|
436
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooHistory])
|
437
|
+
subject.adapt_to_cmodel.should === subject
|
429
438
|
end
|
430
439
|
end
|
431
440
|
|
432
|
-
describe
|
441
|
+
describe ".adapt_to_cmodel with ActiveFedora::Base" do
|
433
442
|
subject { ActiveFedora::Base.new }
|
434
443
|
|
435
|
-
it
|
436
|
-
|
437
|
-
|
444
|
+
it "should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)" do
|
445
|
+
ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
|
446
|
+
subject.adapt_to_cmodel.should be_kind_of FooAdaptation
|
438
447
|
end
|
439
448
|
end
|
440
449
|
|
441
450
|
|
442
|
-
describe
|
443
|
-
it
|
444
|
-
|
451
|
+
describe ".to_solr" do
|
452
|
+
it "should provide .to_solr" do
|
453
|
+
@test_object.should respond_to(:to_solr)
|
445
454
|
end
|
446
455
|
|
447
|
-
it
|
448
|
-
|
449
|
-
|
456
|
+
it "should add pid, system_create_date, system_modified_date and object_state from object attributes" do
|
457
|
+
@test_object.should_receive(:create_date).and_return("2012-03-04T03:12:02Z")
|
458
|
+
@test_object.should_receive(:modified_date).and_return("2012-03-07T03:12:02Z")
|
450
459
|
@test_object.stub(pid: 'changeme:123')
|
451
|
-
@test_object.state =
|
460
|
+
@test_object.state = "D"
|
452
461
|
solr_doc = @test_object.to_solr
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
462
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)].should eql("2012-03-04T03:12:02Z")
|
463
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_modified", :stored_sortable, type: :date)].should eql("2012-03-07T03:12:02Z")
|
464
|
+
solr_doc[ActiveFedora::SolrService.solr_name("object_state", :stored_sortable)].should eql("D")
|
465
|
+
solr_doc[:id].should eql("changeme:123")
|
457
466
|
end
|
458
467
|
|
459
|
-
it
|
460
|
-
@test_object.add_relationship(:has_part,
|
461
|
-
solr_doc = @test_object.to_solr(
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
468
|
+
it "should omit base metadata and RELS-EXT if :model_only==true" do
|
469
|
+
@test_object.add_relationship(:has_part, "foo", true)
|
470
|
+
solr_doc = @test_object.to_solr(Hash.new, :model_only => true)
|
471
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_create", type: :date)].should be_nil
|
472
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_modified", type: :date)].should be_nil
|
473
|
+
solr_doc["id"].should be_nil
|
474
|
+
solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)].should be_nil
|
466
475
|
end
|
467
476
|
|
468
|
-
it
|
477
|
+
it "should add self.class as the :active_fedora_model" do
|
469
478
|
stub_get(@this_pid)
|
470
479
|
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
471
480
|
@test_history = FooHistory.new()
|
472
481
|
solr_doc = @test_history.to_solr
|
473
|
-
|
482
|
+
solr_doc[ActiveFedora::SolrService.solr_name("active_fedora_model", :stored_sortable)].should eql("FooHistory")
|
474
483
|
end
|
475
484
|
|
476
|
-
it
|
477
|
-
mock1 = double(
|
478
|
-
mock2 = double(
|
479
|
-
ngds = double(
|
480
|
-
|
481
|
-
|
482
|
-
|
485
|
+
it "should call .to_solr on all SimpleDatastreams and OmDatastreams, passing the resulting document to solr" do
|
486
|
+
mock1 = double("ds1", :to_solr => {})
|
487
|
+
mock2 = double("ds2", :to_solr => {})
|
488
|
+
ngds = double("ngds", :to_solr => {})
|
489
|
+
ngds.should_receive(:solrize_profile)
|
490
|
+
mock1.should_receive(:solrize_profile)
|
491
|
+
mock2.should_receive(:solrize_profile)
|
483
492
|
|
484
|
-
|
485
|
-
|
493
|
+
@test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
|
494
|
+
@test_object.should_receive(:solrize_relationships)
|
486
495
|
@test_object.to_solr
|
487
496
|
end
|
488
|
-
it
|
489
|
-
mock = double(
|
490
|
-
|
497
|
+
it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
|
498
|
+
mock = double("ds1", :to_solr => {})
|
499
|
+
mock.should_receive(:solrize_profile)
|
491
500
|
|
492
|
-
|
493
|
-
|
501
|
+
@test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock})
|
502
|
+
@test_object.should_receive(:solrize_relationships)
|
494
503
|
@test_object.to_solr
|
495
504
|
end
|
496
505
|
|
497
|
-
it
|
498
|
-
@test_object.add_relationship(:has_collection_member,
|
506
|
+
it "should call .to_solr on the relationships rels-ext is dirty" do
|
507
|
+
@test_object.add_relationship(:has_collection_member, "info:fedora/test:member")
|
499
508
|
rels_ext = @test_object.rels_ext
|
500
|
-
|
501
|
-
|
509
|
+
rels_ext.should be_changed
|
510
|
+
@test_object.should_receive(:solrize_relationships)
|
502
511
|
@test_object.to_solr
|
503
512
|
end
|
504
513
|
|
505
514
|
end
|
506
515
|
|
507
|
-
describe
|
508
|
-
it
|
509
|
-
|
510
|
-
|
516
|
+
describe ".label" do
|
517
|
+
it "should return the label of the inner object" do
|
518
|
+
@test_object.inner_object.should_receive(:label).and_return("foo label")
|
519
|
+
@test_object.label.should == "foo label"
|
511
520
|
end
|
512
521
|
end
|
513
522
|
|
514
|
-
describe
|
515
|
-
it
|
516
|
-
|
517
|
-
@test_object.label =
|
518
|
-
|
523
|
+
describe ".label=" do
|
524
|
+
it "should set the label of the inner object" do
|
525
|
+
@test_object.label.should_not == "foo label"
|
526
|
+
@test_object.label = "foo label"
|
527
|
+
@test_object.label.should == "foo label"
|
519
528
|
end
|
520
529
|
end
|
521
|
-
|
522
|
-
|
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
|
-
end
|
529
|
-
end
|
530
|
-
|
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
|
-
|
537
|
-
ds_values_hash = {
|
538
|
-
'descMetadata' => { [{:person => 0}, :role] => {'0' => 'role1', '1' => 'role2', '2' => 'role3'} },
|
539
|
-
'properties' => { 'notes' => 'foo' }
|
540
|
-
}
|
541
|
-
m = FooHistory.new
|
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
|
-
m.update_datastream_attributes( ds_values_hash )
|
546
|
-
end
|
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
|
-
ds_values_hash = {
|
550
|
-
'nonexistentDatastream' => { 'notes' => 'foo' }
|
551
|
-
}
|
530
|
+
describe "update_attributes" do
|
531
|
+
it "should set the attributes and save" do
|
552
532
|
m = FooHistory.new
|
553
|
-
|
554
|
-
expect(m.update_datastream_attributes( ds_values_hash )).to eq({})
|
555
|
-
expect(m.to_xml).to eq(untouched_xml)
|
556
|
-
end
|
557
|
-
end
|
558
|
-
|
559
|
-
describe 'update_attributes' do
|
560
|
-
it 'should set the attributes and save' do
|
561
|
-
m = FooHistory.new
|
562
|
-
att = {'fubar' => '1234', 'baz' => 'stuff'}
|
533
|
+
att= {"fubar"=> '1234', "baz" =>'stuff'}
|
563
534
|
|
564
|
-
|
565
|
-
|
566
|
-
|
535
|
+
m.should_receive(:fubar=).with('1234')
|
536
|
+
m.should_receive(:baz=).with('stuff')
|
537
|
+
m.should_receive(:save)
|
567
538
|
m.update_attributes(att)
|
568
539
|
end
|
569
540
|
end
|
570
541
|
|
571
|
-
describe
|
572
|
-
it
|
542
|
+
describe "update" do
|
543
|
+
it "should set the attributes and save" do
|
573
544
|
m = FooHistory.new
|
574
|
-
att
|
545
|
+
att= {"fubar"=> '1234', "baz" =>'stuff'}
|
575
546
|
|
576
|
-
|
577
|
-
|
578
|
-
|
547
|
+
m.should_receive(:fubar=).with('1234')
|
548
|
+
m.should_receive(:baz=).with('stuff')
|
549
|
+
m.should_receive(:save)
|
579
550
|
m.update(att)
|
580
551
|
end
|
581
552
|
end
|
582
553
|
|
583
|
-
describe
|
584
|
-
|
585
|
-
expect(Deprecation).to receive(:warn).at_least(1).times
|
586
|
-
end
|
587
|
-
it 'should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams' do
|
588
|
-
m = FooHistory.new
|
589
|
-
att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
|
590
|
-
|
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
|
-
m.update_indexed_attributes(att)
|
595
|
-
end
|
596
|
-
it 'should take a :datastreams argument' do
|
597
|
-
att = {'fubar' => {'-1' => 'mork', '0' => 'york', '1' => 'mangle'}}
|
598
|
-
stub_get(@this_pid)
|
599
|
-
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
600
|
-
m = FooHistory.new()
|
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
|
-
|
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
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
describe '#relationships_by_name' do
|
616
|
-
before do
|
617
|
-
class MockNamedRelationships < ActiveFedora::Base
|
618
|
-
# has_relationship "testing", :has_part, :type=>ActiveFedora::Base
|
619
|
-
# has_relationship "testing2", :has_member, :type=>ActiveFedora::Base
|
620
|
-
# has_relationship "testing_inbound", :has_part, :type=>ActiveFedora::Base, :inbound=>true
|
621
|
-
end
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
describe '.solrize_relationships' do
|
626
|
-
it 'should serialize the relationships into a Hash' do
|
554
|
+
describe ".solrize_relationships" do
|
555
|
+
it "should serialize the relationships into a Hash" do
|
627
556
|
graph = RDF::Graph.new
|
628
|
-
subject = RDF::URI.new
|
557
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
629
558
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
630
559
|
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
631
560
|
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),
|
561
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
|
633
562
|
|
634
|
-
|
563
|
+
@test_object.should_receive(:relationships).and_return(graph)
|
635
564
|
solr_doc = @test_object.solrize_relationships
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
565
|
+
solr_doc[ActiveFedora::SolrService.solr_name("is_member_of", :symbol)].should == "info:fedora/demo:10"
|
566
|
+
solr_doc[ActiveFedora::SolrService.solr_name("is_part_of", :symbol)].should == "info:fedora/demo:11"
|
567
|
+
solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)].should == "info:fedora/demo:12"
|
568
|
+
solr_doc[ActiveFedora::SolrService.solr_name("conforms_to", :symbol)].should == "AnInterface"
|
640
569
|
end
|
641
570
|
end
|
642
571
|
end
|