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
@@ -2,24 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::NtriplesRDFDatastream do
|
4
4
|
before do
|
5
|
+
|
6
|
+
class FileVocabulary < RDF::Vocabulary("http://downlode.org/Code/RDF/File_Properties/schema#")
|
7
|
+
property :size
|
8
|
+
end
|
9
|
+
|
5
10
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
6
11
|
map_predicates do |map|
|
7
|
-
map.title(:
|
12
|
+
map.title(in: RDF::DC) do |index|
|
8
13
|
index.as :stored_searchable, :facetable
|
9
14
|
end
|
10
|
-
map.date_uploaded(:
|
15
|
+
map.date_uploaded(to: "dateSubmitted", in: RDF::DC) do |index|
|
11
16
|
index.type :date
|
12
17
|
index.as :stored_searchable, :sortable
|
13
18
|
end
|
14
|
-
map.
|
15
|
-
|
16
|
-
|
19
|
+
map.size(in: FileVocabulary) do |index|
|
20
|
+
index.type :integer
|
21
|
+
index.as :stored_sortable
|
22
|
+
end
|
23
|
+
map.part(to: "hasPart", in: RDF::DC)
|
24
|
+
map.based_near(in: RDF::FOAF)
|
25
|
+
map.related_url(to: "seeAlso", in: RDF::RDFS)
|
17
26
|
end
|
18
27
|
end
|
19
|
-
class RdfTest < ActiveFedora::Base
|
20
|
-
has_metadata :name
|
21
|
-
|
22
|
-
|
28
|
+
class RdfTest < ActiveFedora::Base
|
29
|
+
has_metadata :name=>'rdf', :type=>MyDatastream
|
30
|
+
has_attributes :based_near, :related_url, :part, :date_uploaded, datastream: 'rdf', multiple: true
|
31
|
+
has_attributes :title, :size, datastream: 'rdf', multiple: false
|
23
32
|
end
|
24
33
|
@subject = RdfTest.new
|
25
34
|
end
|
@@ -31,107 +40,116 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
31
40
|
after do
|
32
41
|
Object.send(:remove_const, :RdfTest)
|
33
42
|
Object.send(:remove_const, :MyDatastream)
|
43
|
+
Object.send(:remove_const, :FileVocabulary)
|
34
44
|
end
|
35
45
|
|
36
|
-
it
|
46
|
+
it "should not try to send an empty datastream" do
|
37
47
|
@subject.save
|
38
48
|
end
|
39
49
|
|
40
|
-
it
|
41
|
-
foo = RdfTest.new(:pid
|
50
|
+
it "should save content properly upon save" do
|
51
|
+
foo = RdfTest.new(:pid=>'test:1') #Pid needs to match the subject in the loaded file
|
42
52
|
foo.title = 'Hamlet'
|
43
53
|
foo.save
|
44
|
-
|
54
|
+
foo.title.should == 'Hamlet'
|
45
55
|
foo.rdf.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
46
56
|
foo.save
|
47
|
-
|
57
|
+
foo.title.should == 'Title of work'
|
48
58
|
end
|
49
59
|
|
50
|
-
it
|
51
|
-
@subject = RdfTest.new(title:
|
52
|
-
|
53
|
-
|
60
|
+
it "should delegate as_json to the fields" do
|
61
|
+
@subject = RdfTest.new(title: "Title of work")
|
62
|
+
@subject.rdf.title.as_json.should == ["Title of work"]
|
63
|
+
@subject.rdf.title.to_json.should == "\[\"Title of work\"\]"
|
54
64
|
end
|
55
65
|
|
56
|
-
it
|
66
|
+
it "should solrize even when the object is not new" do
|
57
67
|
foo = RdfTest.new
|
58
|
-
|
59
|
-
foo.title =
|
68
|
+
foo.should_receive(:update_index).once
|
69
|
+
foo.title = "title1"
|
60
70
|
foo.save
|
61
71
|
foo = RdfTest.find(foo.pid)
|
62
|
-
|
63
|
-
foo.title =
|
64
|
-
foo.save
|
72
|
+
foo.should_receive(:update_index).once
|
73
|
+
foo.title = "The Work2"
|
74
|
+
foo.save
|
65
75
|
end
|
66
76
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
77
|
+
describe "serializing" do
|
78
|
+
it "should handle dates" do
|
79
|
+
subject.date_uploaded = Date.parse('2012-11-02')
|
80
|
+
subject.date_uploaded.first.should be_kind_of Date
|
81
|
+
solr_document = subject.to_solr
|
82
|
+
solr_document[ActiveFedora::SolrService.solr_name('rdf__date_uploaded', type: :date)].should == ['2012-11-02T00:00:00Z']
|
83
|
+
end
|
84
|
+
it "should handle integers" do
|
85
|
+
subject.size = 12345
|
86
|
+
subject.size.should be_kind_of Fixnum
|
87
|
+
solr_document = subject.to_solr
|
88
|
+
solr_document[ActiveFedora::SolrService.solr_name('rdf__size', :stored_sortable, type: :integer)].should == '12345'
|
89
|
+
end
|
72
90
|
end
|
73
91
|
|
74
|
-
it
|
75
|
-
@subject = RdfTest.new(title:
|
92
|
+
it "should produce a solr document" do
|
93
|
+
@subject = RdfTest.new(title: "War and Peace")
|
76
94
|
solr_document = @subject.to_solr
|
77
|
-
|
78
|
-
|
95
|
+
solr_document[ActiveFedora::SolrService.solr_name('rdf__title', :facetable)].should == ["War and Peace"]
|
96
|
+
solr_document[ActiveFedora::SolrService.solr_name('rdf__title', type: :string)].should == ["War and Peace"]
|
79
97
|
end
|
80
98
|
|
81
|
-
it
|
99
|
+
it "should set and recall values" do
|
82
100
|
@subject.title = 'War and Peace'
|
83
|
-
|
84
|
-
@subject.based_near =
|
85
|
-
@subject.related_url =
|
86
|
-
@subject.part =
|
101
|
+
@subject.rdf.should be_changed
|
102
|
+
@subject.based_near = "Moscow, Russia"
|
103
|
+
@subject.related_url = "http://en.wikipedia.org/wiki/War_and_Peace"
|
104
|
+
@subject.part = "this is a part"
|
87
105
|
@subject.save
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
106
|
+
@subject.title.should == 'War and Peace'
|
107
|
+
@subject.based_near.should == ["Moscow, Russia"]
|
108
|
+
@subject.related_url.should == ["http://en.wikipedia.org/wiki/War_and_Peace"]
|
109
|
+
@subject.part.should == ["this is a part"]
|
92
110
|
end
|
93
|
-
it
|
111
|
+
it "should set, persist, and recall values" do
|
94
112
|
@subject.title = 'War and Peace'
|
95
|
-
@subject.based_near =
|
96
|
-
@subject.related_url =
|
97
|
-
@subject.part =
|
113
|
+
@subject.based_near = "Moscow, Russia"
|
114
|
+
@subject.related_url = "http://en.wikipedia.org/wiki/War_and_Peace"
|
115
|
+
@subject.part = "this is a part"
|
98
116
|
@subject.save
|
99
117
|
|
100
118
|
loaded = RdfTest.find(@subject.pid)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
119
|
+
loaded.title.should == 'War and Peace'
|
120
|
+
loaded.based_near.should == ['Moscow, Russia']
|
121
|
+
loaded.related_url.should == ['http://en.wikipedia.org/wiki/War_and_Peace']
|
122
|
+
loaded.part.should == ['this is a part']
|
105
123
|
end
|
106
|
-
it
|
107
|
-
@subject.part = [
|
124
|
+
it "should set multiple values" do
|
125
|
+
@subject.part = ["part 1", "part 2"]
|
108
126
|
@subject.save
|
109
127
|
|
110
128
|
loaded = RdfTest.find(@subject.pid)
|
111
|
-
|
129
|
+
loaded.part.should == ['part 1', 'part 2']
|
112
130
|
end
|
113
|
-
it
|
114
|
-
@subject.part =
|
131
|
+
it "should append values" do
|
132
|
+
@subject.part = "thing 1"
|
115
133
|
@subject.save
|
116
134
|
|
117
|
-
@subject.part <<
|
118
|
-
|
135
|
+
@subject.part << "thing 2"
|
136
|
+
@subject.part.should == ["thing 1", "thing 2"]
|
119
137
|
end
|
120
138
|
|
121
|
-
it
|
122
|
-
@subject.title =
|
139
|
+
it "should be able to save a blank document" do
|
140
|
+
@subject.title = ""
|
123
141
|
@subject.save
|
124
142
|
end
|
125
143
|
|
126
|
-
it
|
144
|
+
it "should load n-triples into the graph" do
|
127
145
|
ntrip = '<http://oregondigital.org/ns/62> <http://purl.org/dc/terms/type> "Image" .
|
128
146
|
<http://oregondigital.org/ns/62> <http://purl.org/dc/terms/spatial> "Benton County (Ore.)" .
|
129
147
|
'
|
130
148
|
@subject.rdf.content = ntrip
|
131
|
-
|
149
|
+
@subject.rdf.graph.dump(:ntriples).should == ntrip
|
132
150
|
end
|
133
151
|
|
134
|
-
describe
|
152
|
+
describe "using rdf_subject" do
|
135
153
|
before do
|
136
154
|
# reopening existing class
|
137
155
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
@@ -146,12 +164,12 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
146
164
|
@subject.destroy
|
147
165
|
end
|
148
166
|
|
149
|
-
it
|
167
|
+
it "should write rdf with proper subjects" do
|
150
168
|
@subject.inner_object.pid = 'test:99'
|
151
|
-
@subject.rdf.type =
|
169
|
+
@subject.rdf.type = "Frog"
|
152
170
|
@subject.save!
|
153
171
|
@subject.reload
|
154
|
-
|
172
|
+
@subject.rdf.graph.dump(:ntriples).should == "<http://oregondigital.org/ns/99> <http://purl.org/dc/terms/type> \"Frog\" .\n"
|
155
173
|
@subject.rdf.type == ['Frog']
|
156
174
|
|
157
175
|
end
|
@@ -159,49 +177,49 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
159
177
|
end
|
160
178
|
|
161
179
|
|
162
|
-
it
|
163
|
-
@subject.title =
|
164
|
-
@subject.related_url =
|
165
|
-
@subject.related_url <<
|
180
|
+
it "should delete values" do
|
181
|
+
@subject.title = "Hamlet"
|
182
|
+
@subject.related_url = "http://psu.edu/"
|
183
|
+
@subject.related_url << "http://projecthydra.org/"
|
166
184
|
|
167
|
-
|
168
|
-
|
169
|
-
|
185
|
+
@subject.title.should == "Hamlet"
|
186
|
+
@subject.related_url.should include("http://psu.edu/")
|
187
|
+
@subject.related_url.should include("http://projecthydra.org/")
|
170
188
|
|
171
|
-
@subject.title =
|
172
|
-
|
189
|
+
@subject.title = "" #empty string can be meaningful, don't assume delete.
|
190
|
+
@subject.title.should == ''
|
173
191
|
|
174
192
|
@subject.title = nil
|
175
|
-
@subject.related_url.delete(
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
end
|
180
|
-
it
|
181
|
-
@subject.part =
|
182
|
-
@subject.part <<
|
183
|
-
@subject.part <<
|
184
|
-
|
185
|
-
@subject.part.delete(
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
it
|
190
|
-
@subject.part = [
|
191
|
-
@subject.part.delete(
|
192
|
-
|
193
|
-
end
|
194
|
-
describe
|
193
|
+
@subject.related_url.delete("http://projecthydra.org/")
|
194
|
+
|
195
|
+
@subject.title.should be_nil
|
196
|
+
@subject.related_url.should == ["http://psu.edu/"]
|
197
|
+
end
|
198
|
+
it "should delete multiple values at once" do
|
199
|
+
@subject.part = "MacBeth"
|
200
|
+
@subject.part << "Hamlet"
|
201
|
+
@subject.part << "Romeo & Juliet"
|
202
|
+
@subject.part.first.should == "MacBeth"
|
203
|
+
@subject.part.delete("MacBeth", "Romeo & Juliet")
|
204
|
+
@subject.part.should == ["Hamlet"]
|
205
|
+
@subject.part.first.should == "Hamlet"
|
206
|
+
end
|
207
|
+
it "should ignore values to be deleted that do not exist" do
|
208
|
+
@subject.part = ["title1", "title2", "title3"]
|
209
|
+
@subject.part.delete("title2", "title4", "title6")
|
210
|
+
@subject.part.should == ["title1", "title3"]
|
211
|
+
end
|
212
|
+
describe "term proxy methods" do
|
195
213
|
before(:each) do
|
196
214
|
class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
|
197
215
|
map_predicates { |map| map.title(:in => RDF::DC) }
|
198
216
|
end
|
199
|
-
class Foobar < ActiveFedora::Base
|
200
|
-
has_metadata :name
|
201
|
-
|
217
|
+
class Foobar < ActiveFedora::Base
|
218
|
+
has_metadata :name=>'rdf', :type=>TitleDatastream
|
219
|
+
has_attributes :title, datastream: 'rdf', multiple: true
|
202
220
|
end
|
203
221
|
@subject = Foobar.new
|
204
|
-
@subject.title = [
|
222
|
+
@subject.title = ["title1", "title2", "title3"]
|
205
223
|
end
|
206
224
|
|
207
225
|
after(:each) do
|
@@ -209,26 +227,26 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
209
227
|
Object.send(:remove_const, :TitleDatastream)
|
210
228
|
end
|
211
229
|
|
212
|
-
it
|
213
|
-
|
230
|
+
it "should support the count method to determine # of values" do
|
231
|
+
@subject.title.count.should == 3
|
214
232
|
end
|
215
|
-
it
|
216
|
-
|
233
|
+
it "should iterate over multiple values" do
|
234
|
+
@subject.title.should respond_to(:each)
|
217
235
|
end
|
218
|
-
it
|
219
|
-
|
236
|
+
it "should get the first value" do
|
237
|
+
@subject.title.first.should == "title1"
|
220
238
|
end
|
221
|
-
it
|
222
|
-
|
239
|
+
it "should evaluate equality predictably" do
|
240
|
+
@subject.title.should == ["title1", "title2", "title3"]
|
223
241
|
end
|
224
|
-
it
|
225
|
-
|
226
|
-
|
227
|
-
@subject.title.delete(
|
228
|
-
|
242
|
+
it "should support the empty? method" do
|
243
|
+
@subject.title.should respond_to(:empty?)
|
244
|
+
@subject.title.empty?.should be_false
|
245
|
+
@subject.title.delete("title1", "title2", "title3")
|
246
|
+
@subject.title.empty?.should be_true
|
229
247
|
end
|
230
|
-
it
|
231
|
-
|
248
|
+
it "should support the is_a? method" do
|
249
|
+
@subject.title.is_a?(Array).should == true
|
232
250
|
end
|
233
251
|
end
|
234
252
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "solrizer"
|
3
3
|
|
4
4
|
describe ActiveFedora::OmDatastream do
|
5
|
-
|
6
|
-
describe
|
7
|
-
before(:all) do
|
5
|
+
|
6
|
+
describe "a new instance with an inline datastream" do
|
7
|
+
before(:all) do
|
8
8
|
class ModsArticle3 < ActiveFedora::Base
|
9
9
|
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
10
|
-
has_metadata
|
10
|
+
has_metadata :name => "descMetadata", :type => Hydra::ModsArticleDatastream, :control_group => 'X', :autocreate => true
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -25,38 +25,38 @@ describe ActiveFedora::OmDatastream do
|
|
25
25
|
@obj.destroy
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
|
28
|
+
it "should report being inline" do
|
29
|
+
@obj.descMetadata.should be_inline
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
|
32
|
+
it "should not be changed when no fields have been set" do
|
33
|
+
@obj.descMetadata.should_not be_content_changed
|
34
34
|
end
|
35
|
-
it
|
35
|
+
it "should be changed when a field has been set" do
|
36
36
|
@obj.descMetadata.title = 'Foobar'
|
37
|
-
|
37
|
+
@obj.descMetadata.should be_content_changed
|
38
38
|
end
|
39
|
-
describe
|
40
|
-
it
|
39
|
+
describe "#changed?" do
|
40
|
+
it "should not be changed if the new xml matches the old xml" do
|
41
41
|
@obj.descMetadata.content = @obj.descMetadata.content
|
42
|
-
|
42
|
+
@obj.descMetadata.should_not be_changed
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
@obj.descMetadata.content =
|
45
|
+
it "should not be changed if there are minor differences in whitespace" do
|
46
|
+
@obj.descMetadata.content = "<a><b>1</b></a>"
|
47
47
|
@obj.save
|
48
|
-
|
48
|
+
@obj.descMetadata.should_not be_changed
|
49
49
|
@obj.descMetadata.content = "<a>\n<b>1</b>\n</a>"
|
50
|
-
|
50
|
+
@obj.descMetadata.should_not be_changed
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe "an instance that is a managed datastream" do
|
56
56
|
before(:all) do
|
57
57
|
class ModsArticle2 < ActiveFedora::Base
|
58
58
|
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
59
|
-
has_metadata
|
59
|
+
has_metadata :name => "descMetadata", :type => Hydra::ModsArticleDatastream, :autocreate => true
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -74,28 +74,28 @@ describe ActiveFedora::OmDatastream do
|
|
74
74
|
@obj.destroy
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
78
|
-
|
77
|
+
it "should not report being inline" do
|
78
|
+
@obj.descMetadata.should be_managed
|
79
79
|
end
|
80
80
|
|
81
|
-
describe
|
82
|
-
it
|
81
|
+
describe "#changed?" do
|
82
|
+
it "should not be changed if the new xml matches the old xml" do
|
83
83
|
@obj.descMetadata.content = @obj.descMetadata.content
|
84
|
-
|
84
|
+
@obj.descMetadata.should_not be_changed
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
@obj.descMetadata.content =
|
87
|
+
it "should be changed if there are minor differences in whitespace" do
|
88
|
+
@obj.descMetadata.content = "<a><b>1</b></a>"
|
89
89
|
@obj.save
|
90
|
-
|
90
|
+
@obj.descMetadata.should_not be_changed
|
91
91
|
@obj.descMetadata.content = "<a>\n<b>1</b>\n</a>"
|
92
|
-
|
92
|
+
@obj.descMetadata.should be_changed
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
it
|
98
|
-
@obj.descMetadata.content =
|
96
|
+
describe "empty datastream content" do
|
97
|
+
it "should not break when there is empty datastream content" do
|
98
|
+
@obj.descMetadata.content = ""
|
99
99
|
@obj.save
|
100
100
|
end
|
101
101
|
end
|
@@ -108,35 +108,35 @@ describe ActiveFedora::OmDatastream do
|
|
108
108
|
@solr_obj = ActiveFedora::Base.load_instance_from_solr(@obj.pid)
|
109
109
|
end
|
110
110
|
|
111
|
-
it
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
ar = @solr_obj.datastreams[
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
ar = @obj.datastreams[
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
111
|
+
it "should return the same values whether getting from solr or Fedora" do
|
112
|
+
@solr_obj.datastreams["descMetadata"].term_values(:name,:role,:text).should == ["Creator","Contributor","Funder","Host"]
|
113
|
+
@solr_obj.datastreams["descMetadata"].term_values({:name=>0},:role,:text).should == ["Creator"]
|
114
|
+
@solr_obj.datastreams["descMetadata"].term_values({:name=>1},:role,:text).should == ["Contributor"]
|
115
|
+
@solr_obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Creator"]
|
116
|
+
@solr_obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text).should == ["Contributor"]
|
117
|
+
@solr_obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text).should == []
|
118
|
+
ar = @solr_obj.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
119
|
+
ar.length.should == 4
|
120
|
+
ar.include?("Creator").should == true
|
121
|
+
ar.include?("Contributor").should == true
|
122
|
+
ar.include?("Funder").should == true
|
123
|
+
ar.include?("Host").should == true
|
124
|
+
|
125
|
+
@obj.datastreams["descMetadata"].term_values(:name,:role,:text).should == ["Creator","Contributor","Funder","Host"]
|
126
|
+
@obj.datastreams["descMetadata"].term_values({:name=>0},:role,:text).should == ["Creator"]
|
127
|
+
@obj.datastreams["descMetadata"].term_values({:name=>1},:role,:text).should == ["Contributor"]
|
128
|
+
@obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Creator"]
|
129
|
+
@obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text).should == ["Contributor"]
|
130
|
+
@obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text).should == []
|
131
|
+
ar = @obj.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
132
|
+
ar.length.should == 4
|
133
|
+
ar.include?("Creator").should == true
|
134
|
+
ar.include?("Contributor").should == true
|
135
|
+
ar.include?("Funder").should == true
|
136
|
+
ar.include?("Host").should == true
|
137
137
|
end
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
describe '.update_values' do
|
141
141
|
before do
|
142
142
|
@obj.descMetadata.content = File.read(fixture('mods_articles/mods_article1.xml'))
|
@@ -144,24 +144,24 @@ describe ActiveFedora::OmDatastream do
|
|
144
144
|
@obj.reload
|
145
145
|
end
|
146
146
|
|
147
|
-
it
|
148
|
-
@obj.datastreams[
|
149
|
-
|
147
|
+
it "should not be dirty after .update_values is saved" do
|
148
|
+
@obj.datastreams["descMetadata"].update_values([{:name=>0},{:role=>0},:text] =>"Funder")
|
149
|
+
@obj.datastreams["descMetadata"].should be_changed
|
150
150
|
@obj.save
|
151
|
-
|
152
|
-
|
153
|
-
end
|
151
|
+
@obj.datastreams["descMetadata"].should_not be_changed
|
152
|
+
@obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Funder"]
|
153
|
+
end
|
154
154
|
end
|
155
155
|
|
156
156
|
|
157
|
-
describe
|
157
|
+
describe ".to_solr" do
|
158
158
|
before do
|
159
159
|
@obj.descMetadata.journal.issue.publication_date = Date.parse('2012-11-02')
|
160
160
|
@obj.save!
|
161
161
|
@obj.reload
|
162
162
|
end
|
163
163
|
it "should solrize terms with :type=>'date' to *_dt solr terms" do
|
164
|
-
|
164
|
+
@obj.to_solr[ActiveFedora::SolrService.solr_name('journal_issue_publication_date', type: :date)].should == ['2012-11-02T00:00:00Z']
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|