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,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "delegating attributes" do
|
4
4
|
before :all do
|
5
5
|
class TitledObject < ActiveFedora::Base
|
6
6
|
has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
|
7
|
-
m.field
|
7
|
+
m.field "title", :string
|
8
8
|
end
|
9
9
|
has_attributes :title, datastream: 'foo', multiple: false
|
10
10
|
end
|
@@ -13,20 +13,21 @@ describe 'delegating attributes' do
|
|
13
13
|
Object.send(:remove_const, :TitledObject)
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe "save" do
|
17
17
|
subject do
|
18
|
-
obj = TitledObject.create
|
19
|
-
obj.title =
|
18
|
+
obj = TitledObject.create
|
19
|
+
obj.title = "Hydra for Dummies"
|
20
20
|
obj.save
|
21
21
|
obj
|
22
22
|
end
|
23
|
-
it
|
24
|
-
|
25
|
-
|
23
|
+
it "should keep a list of changes after a successful save" do
|
24
|
+
subject.previous_changes.should_not be_empty
|
25
|
+
subject.previous_changes.keys.should include("title")
|
26
26
|
end
|
27
|
-
it
|
28
|
-
|
29
|
-
|
27
|
+
it "should clean out changes" do
|
28
|
+
subject.title_changed?.should be_false
|
29
|
+
subject.changes.should be_empty
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
@@ -12,18 +12,18 @@ describe ActiveFedora::Auditable do
|
|
12
12
|
after(:all) do
|
13
13
|
@test_object.delete
|
14
14
|
end
|
15
|
-
it
|
16
|
-
|
15
|
+
it "should have the correct number of audit records" do
|
16
|
+
@test_object.audit_trail.records.length.should == 1
|
17
17
|
end
|
18
|
-
it
|
18
|
+
it "should return all the data from each audit record" do
|
19
19
|
record = @test_object.audit_trail.records.last
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
record.id.should == "AUDREC1"
|
21
|
+
record.process_type.should == "Fedora API-M"
|
22
|
+
record.action.should == "addDatastream"
|
23
|
+
record.component_id.should == "RELS-EXT"
|
24
|
+
record.responsibility.should == "fedoraAdmin"
|
25
|
+
record.date.should == @test_object.modified_date
|
26
|
+
record.justification.should == ""
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
before :all do
|
5
|
+
class MockAFBaseRelationship < ActiveFedora::Base
|
6
|
+
has_metadata :name=>'foo', :type=>Hydra::ModsArticleDatastream
|
7
|
+
end
|
8
|
+
end
|
9
|
+
after :all do
|
10
|
+
Object.send(:remove_const, :MockAFBaseRelationship)
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { MockAFBaseRelationship.new }
|
14
|
+
|
15
|
+
context '#changed_for_autosave?' do
|
16
|
+
before(:each) do
|
17
|
+
subject.stub(:new_record?).and_return(false)
|
18
|
+
subject.stub(:changed?).and_return(false)
|
19
|
+
subject.stub(:marked_for_destruction?).and_return(false)
|
20
|
+
end
|
21
|
+
it {
|
22
|
+
expect { subject.changed_for_autosave? }.to_not raise_error
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
@@ -1,73 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "A base object with metadata" do
|
4
4
|
before :all do
|
5
5
|
class MockAFBaseRelationship < ActiveFedora::Base
|
6
|
-
has_metadata :name
|
6
|
+
has_metadata :name=>'foo', :type=>Hydra::ModsArticleDatastream
|
7
7
|
end
|
8
8
|
end
|
9
9
|
after :all do
|
10
10
|
Object.send(:remove_const, :MockAFBaseRelationship)
|
11
11
|
end
|
12
|
-
describe
|
12
|
+
describe "a new document" do
|
13
13
|
before do
|
14
14
|
@obj = MockAFBaseRelationship.new
|
15
15
|
|
16
|
-
@obj.foo.person =
|
16
|
+
@obj.foo.person = "bob"
|
17
17
|
@obj.save
|
18
18
|
end
|
19
|
-
it
|
20
|
-
obj = ActiveFedora::Base.find(@obj.pid
|
21
|
-
|
22
|
-
|
19
|
+
it "should save the datastream." do
|
20
|
+
obj = ActiveFedora::Base.find(@obj.pid)
|
21
|
+
obj.foo.should_not be_new
|
22
|
+
obj.foo.person.should == ['bob']
|
23
23
|
person_field = ActiveFedora::SolrService.solr_name('person', type: :string)
|
24
|
-
|
24
|
+
ActiveFedora::SolrService.query("{!raw f=id}#{@obj.pid}", :fl=>"id #{person_field}").first.should == {"id"=>@obj.pid, person_field =>['bob']}
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
29
|
-
it
|
28
|
+
describe "setting object state" do
|
29
|
+
it "should store it" do
|
30
30
|
obj = MockAFBaseRelationship.create
|
31
|
-
obj.state
|
31
|
+
obj.state='D'
|
32
32
|
obj.save!
|
33
33
|
obj.reload
|
34
|
-
|
34
|
+
obj.state.should == 'D'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
38
|
+
describe "that already exists in the repo" do
|
39
39
|
before do
|
40
40
|
@release = MockAFBaseRelationship.create()
|
41
41
|
@release.add_relationship(:is_governed_by, 'info:fedora/test:catalog-fixture')
|
42
42
|
@release.add_relationship(:is_part_of, 'info:fedora/test:777')
|
43
|
-
@release.foo.person =
|
43
|
+
@release.foo.person = "test foo content"
|
44
44
|
@release.save
|
45
45
|
end
|
46
|
-
describe
|
46
|
+
describe "and has been changed" do
|
47
47
|
before do
|
48
48
|
@release.foo.person = 'frank'
|
49
49
|
@release.save!
|
50
50
|
end
|
51
|
-
it
|
52
|
-
|
51
|
+
it "should save the datastream." do
|
52
|
+
MockAFBaseRelationship.find(@release.pid).foo.person.should == ['frank']
|
53
53
|
person_field = ActiveFedora::SolrService.solr_name('person', type: :string)
|
54
|
-
|
54
|
+
ActiveFedora::SolrService.query("id:#{@release.pid.gsub(":", "\\:")}", :fl=>"id #{person_field}").first.should == {"id"=>@release.pid, person_field =>['frank']}
|
55
55
|
end
|
56
56
|
end
|
57
|
-
describe
|
57
|
+
describe "clone_into a new object" do
|
58
58
|
before do
|
59
59
|
begin
|
60
60
|
new_object = MockAFBaseRelationship.find('test:999')
|
61
61
|
new_object.delete
|
62
62
|
rescue ActiveFedora::ObjectNotFoundError
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
new_object = MockAFBaseRelationship.create(:pid => 'test:999')
|
66
66
|
@release.clone_into(new_object)
|
67
67
|
@new_object = MockAFBaseRelationship.find('test:999')
|
68
68
|
end
|
69
|
-
it
|
70
|
-
|
69
|
+
it "should have all the assertions" do
|
70
|
+
@new_object.rels_ext.content.should be_equivalent_to '<rdf:RDF xmlns:ns1="info:fedora/fedora-system:def/model#" xmlns:ns2="info:fedora/fedora-system:def/relations-external#" xmlns:ns0="http://projecthydra.org/ns/relations#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
71
71
|
<rdf:Description rdf:about="info:fedora/test:999">
|
72
72
|
<ns0:isGovernedBy rdf:resource="info:fedora/test:catalog-fixture"/>
|
73
73
|
<ns1:hasModel rdf:resource="info:fedora/afmodel:MockAFBaseRelationship"/>
|
@@ -76,18 +76,18 @@ describe 'A base object with metadata' do
|
|
76
76
|
</rdf:Description>
|
77
77
|
</rdf:RDF>'
|
78
78
|
end
|
79
|
-
it
|
80
|
-
|
81
|
-
|
79
|
+
it "should have the other datastreams too" do
|
80
|
+
@new_object.datastreams.keys.should include "foo"
|
81
|
+
@new_object.foo.content.should be_equivalent_to @release.foo.content
|
82
82
|
end
|
83
83
|
end
|
84
|
-
describe
|
84
|
+
describe "clone" do
|
85
85
|
before do
|
86
86
|
@new_object = @release.clone
|
87
87
|
end
|
88
|
-
it
|
89
|
-
|
90
|
-
<rdf:Description rdf:about="info:fedora/'
|
88
|
+
it "should have all the assertions" do
|
89
|
+
@new_object.rels_ext.content.should be_equivalent_to '<rdf:RDF xmlns:ns1="info:fedora/fedora-system:def/model#" xmlns:ns2="info:fedora/fedora-system:def/relations-external#" xmlns:ns0="http://projecthydra.org/ns/relations#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
90
|
+
<rdf:Description rdf:about="info:fedora/'+ @new_object.pid+'">
|
91
91
|
<ns0:isGovernedBy rdf:resource="info:fedora/test:catalog-fixture"/>
|
92
92
|
<ns1:hasModel rdf:resource="info:fedora/afmodel:MockAFBaseRelationship"/>
|
93
93
|
<ns2:isPartOf rdf:resource="info:fedora/test:777"/>
|
@@ -95,9 +95,9 @@ describe 'A base object with metadata' do
|
|
95
95
|
</rdf:Description>
|
96
96
|
</rdf:RDF>'
|
97
97
|
end
|
98
|
-
it
|
99
|
-
|
100
|
-
|
98
|
+
it "should have the other datastreams too" do
|
99
|
+
@new_object.datastreams.keys.should include "foo"
|
100
|
+
@new_object.foo.content.should be_equivalent_to @release.foo.content
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -115,12 +115,12 @@ describe 'A base object with metadata' do
|
|
115
115
|
end
|
116
116
|
it 'should requery Fedora' do
|
117
117
|
@object.reload
|
118
|
-
|
118
|
+
@object.foo.person.should == ['dave']
|
119
119
|
end
|
120
120
|
it 'should raise an error if not persisted' do
|
121
121
|
@object = MockAFBaseRelationship.new
|
122
122
|
# You will want this stub or else it will be really chatty in your STDERR
|
123
|
-
|
123
|
+
@object.inner_object.logger.stub(:error)
|
124
124
|
expect {
|
125
125
|
@object.reload
|
126
126
|
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
@@ -128,26 +128,26 @@ describe 'A base object with metadata' do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
describe
|
131
|
+
describe "Datastreams synched together" do
|
132
132
|
before do
|
133
133
|
class DSTest < ActiveFedora::Base
|
134
134
|
def load_datastreams
|
135
135
|
super
|
136
136
|
unless self.datastreams.keys.include? 'test_ds'
|
137
|
-
add_file_datastream(
|
137
|
+
add_file_datastream("XXX",:dsid=>'test_ds', :mimeType=>'text/html')
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
|
-
it
|
142
|
+
it "Should update datastream" do
|
143
143
|
@nc = DSTest.new
|
144
144
|
@nc.save
|
145
|
-
|
145
|
+
@nc.test_ds.content.should == 'XXX'
|
146
146
|
ds = @nc.datastreams['test_ds']
|
147
|
-
ds.content =
|
147
|
+
ds.content = "Foobar"
|
148
148
|
@nc.save
|
149
|
-
|
150
|
-
|
149
|
+
DSTest.find(@nc.pid).datastreams['test_ds'].content.should == 'Foobar'
|
150
|
+
DSTest.find(@nc.pid).test_ds.content.should == 'Foobar'
|
151
151
|
end
|
152
152
|
|
153
153
|
end
|
@@ -161,21 +161,21 @@ describe ActiveFedora::Base do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
class MockAFBaseFromSolr < ActiveFedora::Base
|
164
|
-
has_metadata :name =>
|
165
|
-
m.field
|
164
|
+
has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
|
165
|
+
m.field "holding_id", :string
|
166
166
|
end
|
167
|
-
|
168
|
-
has_metadata :name =>
|
169
|
-
m.field
|
170
|
-
m.field
|
171
|
-
m.field
|
167
|
+
|
168
|
+
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
169
|
+
m.field "created", :date, :xml_node => "created"
|
170
|
+
m.field "language", :string, :xml_node => "language"
|
171
|
+
m.field "creator", :string, :xml_node => "creator"
|
172
172
|
# Created remaining fields
|
173
|
-
m.field
|
174
|
-
m.field
|
173
|
+
m.field "geography", :string, :xml_node => "geography"
|
174
|
+
m.field "title", :string, :xml_node => "title"
|
175
175
|
end
|
176
176
|
end
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
before(:all) do
|
180
180
|
ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
|
181
181
|
end
|
@@ -183,12 +183,12 @@ describe ActiveFedora::Base do
|
|
183
183
|
after :all do
|
184
184
|
Object.send(:remove_const, :MockAFBaseRelationship)
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
before(:each) do
|
188
188
|
@test_object = ActiveFedora::Base.new
|
189
189
|
@test_object.save
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
after(:each) do
|
193
193
|
begin
|
194
194
|
@test_object.delete
|
@@ -211,15 +211,15 @@ describe ActiveFedora::Base do
|
|
211
211
|
rescue
|
212
212
|
end
|
213
213
|
end
|
214
|
-
|
215
|
-
describe
|
216
|
-
it
|
217
|
-
|
218
|
-
|
214
|
+
|
215
|
+
describe ".initialize" do
|
216
|
+
it "calling constructor should create a new Fedora Object" do
|
217
|
+
@test_object.should have(0).errors
|
218
|
+
@test_object.pid.should_not be_nil
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
222
|
-
describe
|
221
|
+
|
222
|
+
describe "#save" do
|
223
223
|
before(:each) do
|
224
224
|
@test_object2 = ActiveFedora::Base.new
|
225
225
|
end
|
@@ -227,167 +227,167 @@ describe ActiveFedora::Base do
|
|
227
227
|
after(:each) do
|
228
228
|
@test_object2.delete
|
229
229
|
end
|
230
|
-
|
231
|
-
it
|
232
|
-
@test_object2 = ActiveFedora::Base.new({:namespace
|
230
|
+
|
231
|
+
it "passing namespace to constructor with no pid should generate a pid with the supplied namespace" do
|
232
|
+
@test_object2 = ActiveFedora::Base.new({:namespace=>"randomNamespace"})
|
233
233
|
# will be nil if match failed, otherwise will equal pid
|
234
234
|
@test_object2.save
|
235
|
-
|
235
|
+
@test_object2.pid.match('randomNamespace:\d+').to_a.first.should == @test_object2.pid
|
236
236
|
end
|
237
237
|
|
238
|
-
it
|
238
|
+
it "should set the CMA hasModel relationship in the Rels-EXT" do
|
239
239
|
@test_object2.save
|
240
|
-
rexml = REXML::Document.new(@test_object2.datastreams[
|
240
|
+
rexml = REXML::Document.new(@test_object2.datastreams["RELS-EXT"].content)
|
241
241
|
# Purpose: confirm that the isMemberOf entries exist and have real RDF in them
|
242
|
-
|
242
|
+
rexml.root.elements["rdf:Description/ns0:hasModel"].attributes["rdf:resource"].should == 'info:fedora/afmodel:ActiveFedora_Base'
|
243
243
|
end
|
244
|
-
it
|
244
|
+
it "should merge attributes from fedora into attributes hash" do
|
245
245
|
@test_object2.save
|
246
246
|
inner_object = @test_object2.inner_object
|
247
|
-
|
248
|
-
|
247
|
+
inner_object.pid.should == @test_object2.pid
|
248
|
+
inner_object.should respond_to(:lastModifiedDate)
|
249
249
|
end
|
250
250
|
end
|
251
|
-
|
252
|
-
describe
|
253
|
-
it
|
251
|
+
|
252
|
+
describe ".datastreams" do
|
253
|
+
it "should return a Hash of datastreams from fedora" do
|
254
254
|
datastreams = @test_object.datastreams
|
255
|
-
|
256
|
-
datastreams.each_value do |ds|
|
257
|
-
|
255
|
+
datastreams.should be_a_kind_of(Hash)
|
256
|
+
datastreams.each_value do |ds|
|
257
|
+
ds.should be_a_kind_of(ActiveFedora::Datastream)
|
258
258
|
end
|
259
|
-
|
260
|
-
|
261
|
-
|
259
|
+
@test_object.datastreams["DC"].should be_an_instance_of(ActiveFedora::Datastream)
|
260
|
+
datastreams["DC"].should_not be_nil
|
261
|
+
datastreams["DC"].should be_an_instance_of(ActiveFedora::Datastream)
|
262
262
|
end
|
263
|
-
it
|
263
|
+
it "should initialize the datastream pointers with @new_object=false" do
|
264
264
|
datastreams = @test_object.datastreams
|
265
|
-
datastreams.each_value do |ds|
|
266
|
-
|
265
|
+
datastreams.each_value do |ds|
|
266
|
+
ds.should_not be_new
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
270
|
-
|
271
|
-
describe
|
272
|
-
it
|
273
|
-
mds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object,
|
274
|
-
mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object,
|
275
|
-
fds = ActiveFedora::Datastream.new(@test_object.inner_object,
|
270
|
+
|
271
|
+
describe ".metadata_streams" do
|
272
|
+
it "should return all of the datastreams from the object that are kinds of OmDatastream " do
|
273
|
+
mds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, "md1")
|
274
|
+
mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object, "qdc")
|
275
|
+
fds = ActiveFedora::Datastream.new(@test_object.inner_object, "fds")
|
276
276
|
@test_object.add_datastream(mds1)
|
277
277
|
@test_object.add_datastream(mds2)
|
278
|
-
@test_object.add_datastream(fds)
|
279
|
-
|
278
|
+
@test_object.add_datastream(fds)
|
279
|
+
|
280
280
|
result = @test_object.metadata_streams
|
281
|
-
|
282
|
-
|
283
|
-
|
281
|
+
result.length.should == 2
|
282
|
+
result.should include(mds1)
|
283
|
+
result.should include(mds2)
|
284
284
|
end
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
describe '.rels_ext' do
|
288
|
-
it
|
289
|
-
|
288
|
+
it "should retrieve RelsExtDatastream object via rels_ext method" do
|
289
|
+
@test_object.rels_ext.should be_instance_of(ActiveFedora::RelsExtDatastream)
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it 'should create the RELS-EXT datastream if it doesnt exist' do
|
293
293
|
test_object = ActiveFedora::Base.new
|
294
|
-
#
|
294
|
+
#test_object.datastreams["RELS-EXT"].should == nil
|
295
295
|
test_object.rels_ext
|
296
|
-
|
297
|
-
|
296
|
+
test_object.datastreams["RELS-EXT"].should_not == nil
|
297
|
+
test_object.datastreams["RELS-EXT"].class.should == ActiveFedora::RelsExtDatastream
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
301
|
describe '.add_relationship' do
|
302
|
-
it
|
303
|
-
@test_object.add_relationship(:is_member_of,
|
304
|
-
@test_object.add_relationship(:is_member_of,
|
305
|
-
@test_object.add_relationship(:conforms_to,
|
302
|
+
it "should update the RELS-EXT datastream and relationships should end up in Fedora when the object is saved" do
|
303
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
304
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
305
|
+
@test_object.add_relationship(:conforms_to, "info:fedora/afmodel:OralHistory")
|
306
306
|
@test_object.save
|
307
|
-
rexml = REXML::Document.new(@test_object.datastreams[
|
307
|
+
rexml = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
|
308
308
|
# Purpose: confirm that the isMemberOf entries exist and have real RDF in them
|
309
|
-
|
310
|
-
|
311
|
-
|
309
|
+
rexml.root.attributes["xmlns:ns1"].should == 'info:fedora/fedora-system:def/relations-external#'
|
310
|
+
rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:5']"].should_not be_nil
|
311
|
+
rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:10']"].should_not be_nil
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
315
315
|
describe '.add_file_datastream' do
|
316
316
|
|
317
|
-
it
|
318
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
317
|
+
it "should set the correct mimeType if :mime_type, :mimeType, or :content_type passed in and path does not contain correct extension" do
|
318
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
|
319
319
|
@test_object.add_file_datastream(f)
|
320
320
|
@test_object.save
|
321
321
|
test_obj = ActiveFedora::Base.find(@test_object.pid)
|
322
322
|
#check case where nothing passed in does not have correct mime type
|
323
|
-
|
323
|
+
test_obj.datastreams["DS1"].mimeType.should == "application/octet-stream"
|
324
324
|
@test_object2 = ActiveFedora::Base.new
|
325
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
326
|
-
@test_object2.add_file_datastream(f,
|
325
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
|
326
|
+
@test_object2.add_file_datastream(f,{:mimeType=>"image/jpeg"})
|
327
327
|
@test_object2.save
|
328
328
|
test_obj = ActiveFedora::Base.find(@test_object2.pid)
|
329
|
-
|
329
|
+
test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
|
330
330
|
@test_object3 = ActiveFedora::Base.new
|
331
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
332
|
-
@test_object3.add_file_datastream(f,
|
331
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
|
332
|
+
@test_object3.add_file_datastream(f,{:mime_type=>"image/jpeg"})
|
333
333
|
@test_object3.save
|
334
334
|
test_obj = ActiveFedora::Base.find(@test_object3.pid)
|
335
|
-
|
335
|
+
test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
|
336
336
|
@test_object4 = ActiveFedora::Base.new
|
337
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
338
|
-
@test_object4.add_file_datastream(f,
|
337
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
|
338
|
+
@test_object4.add_file_datastream(f,{:content_type=>"image/jpeg"})
|
339
339
|
@test_object4.save
|
340
340
|
test_obj = ActiveFedora::Base.find(@test_object4.pid)
|
341
|
-
|
341
|
+
test_obj.datastreams["DS1"].mimeType.should == "image/jpeg"
|
342
342
|
end
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
describe '.add_datastream' do
|
346
|
-
|
347
|
-
it
|
346
|
+
|
347
|
+
it "should be able to add datastreams" do
|
348
348
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
349
|
-
|
349
|
+
@test_object.add_datastream(ds).should be_true
|
350
350
|
end
|
351
|
-
|
352
|
-
it
|
353
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
351
|
+
|
352
|
+
it "adding and saving should add the datastream to the datastreams array" do
|
353
|
+
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
354
354
|
ds.content = fixture('dino.jpg').read
|
355
|
-
|
355
|
+
@test_object.datastreams.should_not have_key("DS1")
|
356
356
|
@test_object.add_datastream(ds)
|
357
357
|
ds.save
|
358
|
-
|
358
|
+
@test_object.datastreams.should have_key("DS1")
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
end
|
362
|
-
|
363
|
-
it
|
362
|
+
|
363
|
+
it "should retrieve blobs that match the saved blobs" do
|
364
364
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
365
|
-
ds.content =
|
365
|
+
ds.content = "foo"
|
366
366
|
new_ds = ds.save
|
367
367
|
@test_object.add_datastream(new_ds)
|
368
|
-
|
368
|
+
@test_object.class.find(@test_object.pid).datastreams["DS1"].content.should == new_ds.content
|
369
369
|
end
|
370
|
-
|
371
|
-
describe
|
372
|
-
it
|
373
|
-
|
370
|
+
|
371
|
+
describe ".create_date" do
|
372
|
+
it "should return W3C date" do
|
373
|
+
@test_object.create_date.should_not be_nil
|
374
374
|
end
|
375
375
|
end
|
376
|
-
|
377
|
-
describe
|
378
|
-
it
|
379
|
-
|
380
|
-
end
|
376
|
+
|
377
|
+
describe ".modified_date" do
|
378
|
+
it "should return nil before saving and a W3C date after saving" do
|
379
|
+
@test_object.modified_date.should_not be_nil
|
380
|
+
end
|
381
381
|
end
|
382
|
-
|
383
|
-
describe
|
384
|
-
|
385
|
-
it
|
382
|
+
|
383
|
+
describe "delete" do
|
384
|
+
|
385
|
+
it "should delete the object from Fedora and Solr" do
|
386
386
|
@test_object.save
|
387
|
-
|
387
|
+
ActiveFedora::Base.find_with_conditions(:id=>@test_object.pid).first["id"].should == @test_object.pid
|
388
388
|
pid = @test_object.pid # store so we can access it after deletion
|
389
389
|
@test_object.delete
|
390
|
-
|
390
|
+
ActiveFedora::Base.find_with_conditions(:id=>pid).should be_empty
|
391
391
|
end
|
392
392
|
end
|
393
393
|
|
@@ -395,7 +395,7 @@ describe ActiveFedora::Base do
|
|
395
395
|
it 'should remove a relationship from an object after a save' do
|
396
396
|
@test_object2 = ActiveFedora::Base.new
|
397
397
|
@test_object2.save
|
398
|
-
@test_object.add_relationship(:has_part
|
398
|
+
@test_object.add_relationship(:has_part,@test_object2)
|
399
399
|
@test_object.save
|
400
400
|
@pid = @test_object.pid
|
401
401
|
begin
|
@@ -404,28 +404,28 @@ describe ActiveFedora::Base do
|
|
404
404
|
puts "#{e.message}\n#{e.backtrace}"
|
405
405
|
raise e
|
406
406
|
end
|
407
|
-
|
408
|
-
@test_object.remove_relationship(:has_part
|
407
|
+
@test_object.object_relations[:has_part].should include @test_object2.internal_uri
|
408
|
+
@test_object.remove_relationship(:has_part,@test_object2)
|
409
409
|
@test_object.save
|
410
410
|
@test_object = ActiveFedora::Base.find(@pid)
|
411
|
-
|
411
|
+
@test_object.object_relations[:has_part].should be_empty
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
415
|
-
|
416
|
-
describe
|
417
|
-
it
|
415
|
+
|
416
|
+
describe "#exists?" do
|
417
|
+
it "should return true for objects that exist" do
|
418
418
|
@obj = ActiveFedora::Base.create
|
419
|
-
|
419
|
+
ActiveFedora::Base.exists?(@obj.pid).should be_true
|
420
420
|
end
|
421
421
|
it "should return false for objects that don't exist" do
|
422
|
-
|
422
|
+
ActiveFedora::Base.exists?('test:missing_object').should be_false
|
423
423
|
end
|
424
|
-
it
|
425
|
-
|
424
|
+
it "should return false for nil" do
|
425
|
+
ActiveFedora::Base.exists?(nil).should be_false
|
426
426
|
end
|
427
|
-
it
|
428
|
-
|
427
|
+
it "should return false for empty" do
|
428
|
+
ActiveFedora::Base.exists?('').should be_false
|
429
429
|
end
|
430
430
|
end
|
431
431
|
end
|