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
@@ -4,8 +4,8 @@ describe ActiveFedora::DatastreamCollections do
|
|
4
4
|
before(:all) do
|
5
5
|
class MockAFBaseDatastream < ActiveFedora::Base
|
6
6
|
include ActiveFedora::DatastreamCollections
|
7
|
-
has_datastream :name
|
8
|
-
has_datastream :name
|
7
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
8
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -15,113 +15,113 @@ describe ActiveFedora::DatastreamCollections do
|
|
15
15
|
describe '#add_named_datastream' do
|
16
16
|
it 'should add a datastream with the given name to the object in fedora' do
|
17
17
|
@test_object2 = MockAFBaseDatastream.new
|
18
|
-
f = File.open(File.join( File.dirname(__FILE__),
|
19
|
-
f2 = File.open(File.join( File.dirname(__FILE__),
|
20
|
-
|
21
|
-
|
22
|
-
@test_object2.add_named_datastream(
|
23
|
-
@test_object2.add_named_datastream(
|
18
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
19
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
20
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
21
|
+
f.stub(:content_type).and_return("image/jpeg")
|
22
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
|
23
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
24
24
|
ds = @test_object2.thumbnail.first
|
25
25
|
ds2 = @test_object2.high.first
|
26
26
|
@test_object2.save
|
27
27
|
@test_object2 = MockAFBaseDatastream.find(@test_object2.pid)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
t2_thumb1 = @test_object2.named_datastreams[
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
t2_high1 = @test_object2.named_datastreams[
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
@test_object2.named_datastreams.keys.size.should == 2
|
29
|
+
@test_object2.named_datastreams.keys.include?("thumbnail").should == true
|
30
|
+
@test_object2.named_datastreams.keys.include?("high").should == true
|
31
|
+
@test_object2.named_datastreams["thumbnail"].size.should == 1
|
32
|
+
@test_object2.named_datastreams["high"].size.should == 1
|
33
|
+
t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
|
34
|
+
t2_thumb1.dsid.should == ds.dsid
|
35
|
+
t2_thumb1.mimeType.should == ds.mimeType
|
36
|
+
t2_thumb1.pid.should == ds.pid
|
37
|
+
t2_thumb1.dsLabel.should == ds.dsLabel
|
38
|
+
t2_thumb1.controlGroup.should == ds.controlGroup
|
39
|
+
t2_high1 = @test_object2.named_datastreams["high"].first
|
40
|
+
t2_high1.dsid.should == ds2.dsid
|
41
|
+
t2_high1.mimeType.should == ds2.mimeType
|
42
|
+
t2_high1.pid.should == ds2.pid
|
43
|
+
t2_high1.dsLabel.should == ds2.dsLabel
|
44
|
+
t2_high1.controlGroup.should == ds2.controlGroup
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
describe '#add_named_file_datastream' do
|
49
49
|
it 'should add a file datastream with the given name to the object in fedora' do
|
50
50
|
@test_object2 = MockAFBaseDatastream.new
|
51
|
-
f = File.open(File.join( File.dirname(__FILE__),
|
52
|
-
|
53
|
-
@test_object2.add_named_file_datastream(
|
51
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
52
|
+
f.stub(:content_type).and_return("image/jpeg")
|
53
|
+
@test_object2.add_named_file_datastream("thumbnail",f)
|
54
54
|
ds = @test_object2.thumbnail.first
|
55
55
|
@test_object2.save
|
56
56
|
@test_object2 = MockAFBaseDatastream.find(@test_object2.pid)
|
57
|
-
|
58
|
-
t2_thumb1 = @test_object2.named_datastreams[
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
@test_object2.named_datastreams["thumbnail"].size.should == 1
|
58
|
+
t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
|
59
|
+
t2_thumb1.dsid.should == "THUMB1"
|
60
|
+
t2_thumb1.mimeType.should == "image/jpeg"
|
61
|
+
t2_thumb1.pid.should == @test_object2.pid
|
62
|
+
t2_thumb1.dsLabel.should == "minivan.jpg"
|
63
|
+
t2_thumb1.controlGroup.should == "M"
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
describe '#update_named_datastream' do
|
68
68
|
it 'should update a named datastream to have a new file' do
|
69
69
|
@test_object2 = MockAFBaseDatastream.new
|
70
|
-
f = File.open(File.join( File.dirname(__FILE__),
|
70
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
71
71
|
minivan = f.read
|
72
72
|
f.rewind
|
73
|
-
f2 = File.open(File.join( File.dirname(__FILE__),
|
73
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
74
74
|
dino = f2.read
|
75
75
|
f2.rewind
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
f.stub(:content_type).and_return("image/jpeg")
|
77
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
78
|
+
f2.stub(:content_type).and_return("image/jpeg")
|
79
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
80
80
|
#check raise exception if dsid not supplied
|
81
|
-
@test_object2.add_named_datastream(
|
81
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
82
82
|
@test_object2.save
|
83
83
|
@test_object2 = MockAFBaseDatastream.find(@test_object2.pid)
|
84
|
-
|
85
|
-
|
86
|
-
@test_object2.thumbnail_ids == [
|
84
|
+
|
85
|
+
@test_object2.thumbnail.size.should == 1
|
86
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
87
87
|
ds = @test_object2.thumbnail.first
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
ds.dsid.should == "THUMB1"
|
89
|
+
ds.mimeType.should == "image/jpeg"
|
90
|
+
ds.pid.should == @test_object2.pid
|
91
|
+
ds.dsLabel.should == "minivan.jpg"
|
92
|
+
ds.controlGroup.should == "M"
|
93
93
|
|
94
|
-
|
95
|
-
@test_object2.update_named_datastream(
|
94
|
+
ds.content.should == minivan
|
95
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
|
96
96
|
@test_object2.save
|
97
97
|
@test_object2 = MockAFBaseDatastream.find(@test_object2.pid)
|
98
|
-
|
99
|
-
@test_object2.thumbnail_ids == [
|
98
|
+
@test_object2.thumbnail.size.should == 1
|
99
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
100
100
|
ds2 = @test_object2.thumbnail.first
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
101
|
+
ds2.dsid.should == "THUMB1"
|
102
|
+
ds2.mimeType.should == "image/jpeg"
|
103
|
+
ds2.pid.should == @test_object2.pid
|
104
|
+
ds2.dsLabel.should == "dino.jpg"
|
105
|
+
ds2.controlGroup.should == "M"
|
106
|
+
(ds2.content == dino).should be_true
|
107
107
|
end
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
describe '#named_datastreams_ids' do
|
111
111
|
it 'should return a hash of datastream name to an array of dsids' do
|
112
112
|
@test_object2 = MockAFBaseDatastream.new
|
113
|
-
f = File.open(File.join( File.dirname(__FILE__),
|
114
|
-
f2 = File.open(File.join( File.dirname(__FILE__),
|
115
|
-
@test_object2.add_named_datastream(
|
116
|
-
@test_object2.add_named_datastream(
|
113
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
114
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
115
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f})
|
116
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f2})
|
117
117
|
@test_object2.save
|
118
118
|
@test_object2 = MockAFBaseDatastream.find(@test_object2.pid)
|
119
119
|
named_datastreams_ids = @test_object2.named_datastreams_ids
|
120
120
|
|
121
121
|
expect(named_datastreams_ids.keys.sort).to eq(['high', 'thumbnail'])
|
122
122
|
expect(named_datastreams_ids['high']).to eq([])
|
123
|
-
expect(named_datastreams_ids['thumbnail'].sort).to eq([
|
123
|
+
expect(named_datastreams_ids['thumbnail'].sort).to eq(["THUMB1", "THUMB2"])
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
end
|
127
|
+
end
|
@@ -1,90 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'active_fedora'
|
4
|
-
require
|
4
|
+
require "rexml/document"
|
5
5
|
|
6
6
|
describe ActiveFedora::Datastream do
|
7
7
|
|
8
8
|
before(:all) do
|
9
9
|
class MockAFBase < ActiveFedora::Base
|
10
|
-
has_metadata :name =>
|
10
|
+
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream, :autocreate => true
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
before(:each) do
|
15
15
|
@test_object = MockAFBase.new
|
16
16
|
@test_object.save
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
after(:each) do
|
20
20
|
@test_object.delete
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
descMetadata = @test_object.datastreams[
|
25
|
-
|
26
|
-
|
23
|
+
it "should be able to access Datastreams using datastreams method" do
|
24
|
+
descMetadata = @test_object.datastreams["descMetadata"]
|
25
|
+
descMetadata.should be_a_kind_of(ActiveFedora::Datastream)
|
26
|
+
descMetadata.dsid.should eql("descMetadata")
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
descMetadata = @test_object.datastreams[
|
31
|
-
|
29
|
+
it "should be able to access Datastream content using content method" do
|
30
|
+
descMetadata = @test_object.datastreams["descMetadata"].content
|
31
|
+
descMetadata.should_not be_nil
|
32
32
|
end
|
33
|
-
|
34
|
-
it
|
35
|
-
xml_content = Nokogiri::XML::Document.parse(@test_object.datastreams[
|
36
|
-
title = Nokogiri::XML::Element.new
|
37
|
-
title.content =
|
33
|
+
|
34
|
+
it "should be able to update XML Datastream content and save to Fedora" do
|
35
|
+
xml_content = Nokogiri::XML::Document.parse(@test_object.datastreams["descMetadata"].content)
|
36
|
+
title = Nokogiri::XML::Element.new "title", xml_content
|
37
|
+
title.content = "Test Title"
|
38
38
|
xml_content.root.add_child title
|
39
|
-
|
40
|
-
|
41
|
-
@test_object.datastreams[
|
42
|
-
@test_object.datastreams[
|
43
|
-
|
39
|
+
|
40
|
+
@test_object.datastreams["descMetadata"].stub(:before_save)
|
41
|
+
@test_object.datastreams["descMetadata"].content = xml_content.to_s
|
42
|
+
@test_object.datastreams["descMetadata"].save
|
43
|
+
|
44
44
|
found = Nokogiri::XML::Document.parse(@test_object.class.find(@test_object.pid).datastreams['descMetadata'].content)
|
45
|
-
|
45
|
+
found.xpath('//dc/title/text()').first.inner_text.should == title.content
|
46
46
|
end
|
47
|
-
|
48
|
-
it
|
47
|
+
|
48
|
+
it "should be able to update Blob Datastream content and save to Fedora" do
|
49
49
|
dsid = "ds#{Time.now.to_i}"
|
50
50
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, dsid)
|
51
51
|
ds.content = fixture('dino.jpg')
|
52
|
-
|
52
|
+
@test_object.add_datastream(ds).should be_true
|
53
53
|
@test_object.save
|
54
|
-
|
55
|
-
to = ActiveFedora::Base.find(@test_object.pid)
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
@test_object.datastreams[dsid].should_not be_changed
|
55
|
+
to = ActiveFedora::Base.find(@test_object.pid)
|
56
|
+
to.should_not be_nil
|
57
|
+
to.datastreams[dsid].should_not be_nil
|
58
|
+
to.datastreams[dsid].content.should == fixture('dino.jpg').read
|
59
59
|
end
|
60
|
-
|
61
|
-
it
|
60
|
+
|
61
|
+
it "should be able to set the versionable attribute" do
|
62
62
|
dsid = "ds#{Time.now.to_i}"
|
63
|
-
v1 =
|
64
|
-
v2 =
|
63
|
+
v1 = "<version1>data</version1>"
|
64
|
+
v2 = "<version2>data</version2>"
|
65
65
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, dsid)
|
66
66
|
ds.content = v1
|
67
67
|
ds.versionable = false
|
68
|
-
|
68
|
+
@test_object.add_datastream(ds).should be_true
|
69
69
|
@test_object.save
|
70
70
|
to = ActiveFedora::Base.find(@test_object.pid)
|
71
71
|
ds = to.datastreams[dsid]
|
72
|
-
|
72
|
+
ds.versionable.should be_false
|
73
73
|
ds.versionable = true
|
74
74
|
to.save
|
75
75
|
ds.content = v2
|
76
76
|
to.save
|
77
77
|
versions = ds.versions
|
78
|
-
|
78
|
+
versions.length.should == 2
|
79
79
|
# order of versions not guaranteed
|
80
80
|
if versions[0].content == v2
|
81
|
-
|
82
|
-
|
81
|
+
versions[1].content.should == v1
|
82
|
+
versions[0].asOfDateTime.should be >= versions[1].asOfDateTime
|
83
83
|
else
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
versions[0].content.should == v1
|
85
|
+
versions[1].content.should == v2
|
86
|
+
versions[1].asOfDateTime.should be >= versions[0].asOfDateTime
|
87
87
|
end
|
88
|
-
|
88
|
+
ds.content.should == v2
|
89
89
|
end
|
90
90
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'active_fedora'
|
4
|
-
require
|
4
|
+
require "rexml/document"
|
5
5
|
|
6
6
|
describe ActiveFedora::Datastreams do
|
7
|
-
describe
|
7
|
+
describe "serializing datastreams" do
|
8
8
|
before :all do
|
9
9
|
class TestingMetadataSerializing < ActiveFedora::Base
|
10
|
-
has_metadata :name =>
|
11
|
-
has_metadata :name =>
|
10
|
+
has_metadata :name => "nokogiri_autocreate_on", :autocreate => true, :type => ActiveFedora::OmDatastream
|
11
|
+
has_metadata :name => "nokogiri_autocreate_off", :autocreate => false, :type => ActiveFedora::OmDatastream
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -18,115 +18,115 @@ describe ActiveFedora::Datastreams do
|
|
18
18
|
|
19
19
|
subject { TestingMetadataSerializing.new }
|
20
20
|
|
21
|
-
it
|
21
|
+
it "should work" do
|
22
22
|
subject.save(:validate => false)
|
23
|
-
|
24
|
-
|
23
|
+
subject.nokogiri_autocreate_on.should_not be_new
|
24
|
+
subject.nokogiri_autocreate_off.should be_new
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe "#has_metadata" do
|
30
30
|
before :all do
|
31
31
|
class HasMetadata < ActiveFedora::Base
|
32
|
-
has_metadata :name =>
|
33
|
-
has_metadata :name =>
|
32
|
+
has_metadata :name => "with_versions", :autocreate => true, :label => "Versioned DS", :type => ActiveFedora::SimpleDatastream
|
33
|
+
has_metadata :name => "without_versions", :autocreate => true, :versionable => false, :type => ActiveFedora::SimpleDatastream
|
34
34
|
end
|
35
35
|
end
|
36
36
|
after :all do
|
37
37
|
Object.send(:remove_const, :HasMetadata)
|
38
38
|
end
|
39
39
|
before :each do
|
40
|
-
@base = ActiveFedora::Base.new(:pid
|
41
|
-
@base.add_datastream(@base.create_datastream(ActiveFedora::Datastream,
|
42
|
-
@base.datastreams[
|
40
|
+
@base = ActiveFedora::Base.new(:pid=>"test:has_metadata_base")
|
41
|
+
@base.add_datastream(@base.create_datastream(ActiveFedora::Datastream, "testDS", :dsLabel => "Test DS"))
|
42
|
+
@base.datastreams["testDS"].content = "blah blah blah"
|
43
43
|
@base.save
|
44
|
-
@test = HasMetadata.new(:pid
|
44
|
+
@test = HasMetadata.new(:pid=>"test:has_metadata_model")
|
45
45
|
@test.save
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
after :each do
|
49
49
|
@base.delete
|
50
50
|
@test.delete
|
51
51
|
end
|
52
|
-
|
53
|
-
it
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@test.without_versions.content
|
52
|
+
|
53
|
+
it "should create datastreams from the spec on new objects" do
|
54
|
+
@test.without_versions.versionable.should be_false
|
55
|
+
@test.with_versions.versionable.should be_true
|
56
|
+
@test.with_versions.dsLabel.should == "Versioned DS"
|
57
|
+
@test.without_versions.content= "blah blah blah"
|
58
58
|
@test.save
|
59
|
-
|
59
|
+
HasMetadata.find(@test.pid).without_versions.versionable.should be_false
|
60
60
|
end
|
61
|
-
|
62
|
-
it
|
61
|
+
|
62
|
+
it "should use ds_specs and preserve existing datastreams on migrated objects" do
|
63
63
|
test_obj = HasMetadata.find(@base.pid)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
test_obj.datastreams["testDS"].dsLabel.should == "Test DS"
|
65
|
+
test_obj.datastreams["testDS"].new?.should be_false
|
66
|
+
test_obj.with_versions.dsLabel.should == "Versioned DS"
|
67
|
+
test_obj.without_versions.versionable.should be_false
|
68
|
+
test_obj.with_versions.new?.should be_true
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
end
|
72
|
-
|
73
|
-
describe
|
72
|
+
|
73
|
+
describe "#has_file_datastream" do
|
74
74
|
before :all do
|
75
75
|
class HasFile < ActiveFedora::Base
|
76
|
-
has_file_datastream :name =>
|
77
|
-
has_file_datastream :name =>
|
76
|
+
has_file_datastream :name => "file_ds", :versionable => false
|
77
|
+
has_file_datastream :name => "file_ds2", :versionable => false, :autocreate => false
|
78
78
|
end
|
79
79
|
end
|
80
80
|
after :all do
|
81
81
|
Object.send(:remove_const, :HasFile)
|
82
82
|
end
|
83
83
|
before :each do
|
84
|
-
@base = ActiveFedora::Base.new(:pid
|
84
|
+
@base = ActiveFedora::Base.new(:pid=>"test:ds_versionable_base")
|
85
85
|
@base.save
|
86
|
-
@base2 = ActiveFedora::Base.new(:pid
|
87
|
-
@base2.add_datastream(@base2.create_datastream(ActiveFedora::Datastream,
|
88
|
-
@base2.datastreams[
|
86
|
+
@base2 = ActiveFedora::Base.new(:pid=>"test:ds_versionable_base2")
|
87
|
+
@base2.add_datastream(@base2.create_datastream(ActiveFedora::Datastream,"file_ds", :versionable=>true,:dsLabel=>"Pre-existing DS"))
|
88
|
+
@base2.datastreams["file_ds"].content = "blah blah blah"
|
89
89
|
@base2.save
|
90
|
-
@has_file = HasFile.new(:pid
|
90
|
+
@has_file = HasFile.new(:pid=>"test:ds_versionable_has_file")
|
91
91
|
@has_file.save
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
after :each do
|
95
95
|
@base.delete
|
96
96
|
@base2.delete
|
97
97
|
@has_file.delete
|
98
98
|
end
|
99
|
-
|
100
|
-
it
|
101
|
-
|
102
|
-
@has_file.file_ds.content =
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
|
100
|
+
it "should create datastreams from the spec on new objects" do
|
101
|
+
@has_file.file_ds.versionable.should be_false
|
102
|
+
@has_file.file_ds.content = "blah blah blah"
|
103
|
+
@has_file.file_ds.changed?.should be_true
|
104
|
+
@has_file.file_ds2.changed?.should be_false # no autocreate
|
105
|
+
@has_file.file_ds2.new?.should be_true
|
106
106
|
@has_file.save
|
107
|
-
|
107
|
+
@has_file.file_ds.versionable.should be_false
|
108
108
|
test_obj = HasFile.find(@has_file.pid)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
test_obj.file_ds.versionable.should be_false
|
110
|
+
test_obj.rels_ext.changed?.should be_false
|
111
|
+
test_obj.file_ds.changed?.should be_false
|
112
|
+
test_obj.file_ds2.changed?.should be_false
|
113
|
+
test_obj.file_ds2.new?.should be_true
|
114
114
|
end
|
115
|
-
|
116
|
-
it
|
115
|
+
|
116
|
+
it "should use ds_specs on migrated objects" do
|
117
117
|
test_obj = HasFile.find(@base.pid)
|
118
|
-
|
119
|
-
|
120
|
-
test_obj.file_ds.content =
|
118
|
+
test_obj.file_ds.versionable.should be_false
|
119
|
+
test_obj.file_ds.new?.should be_true
|
120
|
+
test_obj.file_ds.content = "blah blah blah"
|
121
121
|
test_obj.save
|
122
|
-
|
122
|
+
test_obj.file_ds.versionable.should be_false
|
123
123
|
# look it up again to check datastream profile
|
124
124
|
test_obj = HasFile.find(@base.pid)
|
125
|
-
|
126
|
-
|
125
|
+
test_obj.file_ds.versionable.should be_false
|
126
|
+
test_obj.file_ds.dsLabel.should == "File Datastream"
|
127
127
|
test_obj = HasFile.find(@base2.pid)
|
128
|
-
|
129
|
-
|
128
|
+
test_obj.file_ds.versionable.should be_true
|
129
|
+
test_obj.file_ds.dsLabel.should == "Pre-existing DS"
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|