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,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "persisting objects" do
|
4
4
|
before :all do
|
5
5
|
class MockAFBaseRelationship < ActiveFedora::Base
|
6
|
-
has_metadata :type
|
7
|
-
m.field
|
6
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"foo" do |m|
|
7
|
+
m.field "name", :string
|
8
8
|
end
|
9
|
-
|
9
|
+
has_attributes :name, datastream: 'foo', multiple: false
|
10
10
|
validates :name, presence: true
|
11
11
|
end
|
12
12
|
end
|
@@ -14,9 +14,9 @@ describe 'persisting objects' do
|
|
14
14
|
Object.send(:remove_const, :MockAFBaseRelationship)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
|
17
|
+
describe "#create!" do
|
18
|
+
it "should validate" do
|
19
|
+
lambda { MockAFBaseRelationship.create!}.should raise_error ActiveFedora::RecordInvalid, "Validation failed: Name can't be blank"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
before do
|
7
|
-
class DummyMADS < RDF::Vocabulary(
|
3
|
+
describe "Nesting attribute behavior of RDFDatastream" do
|
4
|
+
describe ".attributes=" do
|
5
|
+
describe "complex properties" do
|
6
|
+
before do
|
7
|
+
class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
|
8
8
|
# componentList and Types of components
|
9
9
|
property :componentList
|
10
10
|
property :Topic
|
@@ -12,8 +12,8 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
12
12
|
property :PersonalName
|
13
13
|
property :CorporateName
|
14
14
|
property :ComplexSubject
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
|
17
17
|
# elementList and elementList values
|
18
18
|
property :elementList
|
19
19
|
property :elementValue
|
@@ -26,8 +26,8 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
26
26
|
|
27
27
|
class ComplexRDFDatastream < ActiveFedora::NtriplesRDFDatastream
|
28
28
|
map_predicates do |map|
|
29
|
-
map.topic(in: DummyMADS, to:
|
30
|
-
map.personalName(in: DummyMADS, to:
|
29
|
+
map.topic(in: DummyMADS, to: "Topic", class_name:"Topic")
|
30
|
+
map.personalName(in: DummyMADS, to: "PersonalName", class_name:"PersonalName")
|
31
31
|
map.title(in: RDF::DC)
|
32
32
|
end
|
33
33
|
|
@@ -36,15 +36,15 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
36
36
|
class Topic
|
37
37
|
include ActiveFedora::RdfObject
|
38
38
|
map_predicates do |map|
|
39
|
-
map.elementList(in: DummyMADS, class_name:
|
39
|
+
map.elementList(in: DummyMADS, class_name:"ComplexRDFDatastream::ElementList")
|
40
40
|
end
|
41
41
|
accepts_nested_attributes_for :elementList
|
42
42
|
end
|
43
43
|
class PersonalName
|
44
44
|
include ActiveFedora::RdfObject
|
45
45
|
map_predicates do |map|
|
46
|
-
map.elementList(in: DummyMADS, to:
|
47
|
-
map.extraProperty(in: DummyMADS, to:
|
46
|
+
map.elementList(in: DummyMADS, to: "elementList", class_name:"ComplexRDFDatastream::ElementList")
|
47
|
+
map.extraProperty(in: DummyMADS, to: "elementValue", class_name:"ComplexRDFDatastream::Topic")
|
48
48
|
end
|
49
49
|
accepts_nested_attributes_for :elementList, :extraProperty
|
50
50
|
end
|
@@ -52,11 +52,11 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
52
52
|
include ActiveFedora::RdfList
|
53
53
|
rdf_type DummyMADS.elementList
|
54
54
|
map_predicates do |map|
|
55
|
-
map.topicElement(in: DummyMADS, to:
|
56
|
-
map.temporalElement(in: DummyMADS, to:
|
57
|
-
map.fullNameElement(in: DummyMADS, to:
|
58
|
-
map.dateNameElement(in: DummyMADS, to:
|
59
|
-
map.nameElement(in: DummyMADS, to:
|
55
|
+
map.topicElement(in: DummyMADS, to: "TopicElement", :class_name => "MadsTopicElement")
|
56
|
+
map.temporalElement(in: DummyMADS, to: "TemporalElement")
|
57
|
+
map.fullNameElement(in: DummyMADS, to: "FullNameElement")
|
58
|
+
map.dateNameElement(in: DummyMADS, to: "DateNameElement")
|
59
|
+
map.nameElement(in: DummyMADS, to: "NameElement")
|
60
60
|
map.elementValue(in: DummyMADS)
|
61
61
|
end
|
62
62
|
accepts_nested_attributes_for :topicElement
|
@@ -74,58 +74,58 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
74
74
|
Object.send(:remove_const, :ComplexRDFDatastream)
|
75
75
|
Object.send(:remove_const, :DummyMADS)
|
76
76
|
end
|
77
|
-
subject { ComplexRDFDatastream.new(double('inner object', :pid
|
78
|
-
let(:params) do
|
79
|
-
{ myResource:
|
77
|
+
subject { ComplexRDFDatastream.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMetadata') }
|
78
|
+
let(:params) do
|
79
|
+
{ myResource:
|
80
80
|
{
|
81
81
|
topic_attributes: {
|
82
82
|
'0' =>
|
83
83
|
{
|
84
84
|
elementList_attributes: [{
|
85
|
-
topicElement_attributes: [{elementValue:
|
85
|
+
topicElement_attributes: [{elementValue:"Cosmology"}]
|
86
86
|
}]
|
87
87
|
},
|
88
88
|
'1' =>
|
89
89
|
{
|
90
90
|
elementList_attributes: [{
|
91
|
-
topicElement_attributes: {'0' => {elementValue:
|
91
|
+
topicElement_attributes: {'0' => {elementValue:"Quantum Behavior"}}
|
92
92
|
}]
|
93
93
|
}
|
94
94
|
},
|
95
95
|
personalName_attributes: [
|
96
|
-
{
|
96
|
+
{
|
97
97
|
elementList_attributes: [{
|
98
|
-
fullNameElement:
|
99
|
-
dateNameElement:
|
98
|
+
fullNameElement: "Jefferson, Thomas",
|
99
|
+
dateNameElement: "1743-1826"
|
100
100
|
}]
|
101
|
-
}
|
101
|
+
}
|
102
102
|
#, "Hemings, Sally"
|
103
|
-
]
|
103
|
+
],
|
104
104
|
}
|
105
105
|
}
|
106
106
|
end
|
107
107
|
|
108
|
-
describe
|
109
|
-
subject { ComplexRDFDatastream::PersonalName.new(RDF::Graph.new) }
|
110
|
-
it
|
111
|
-
subject.elementList_attributes = [{ topicElement_attributes: {'0' => { elementValue:
|
112
|
-
|
113
|
-
|
108
|
+
describe "on lists" do
|
109
|
+
subject { ComplexRDFDatastream::PersonalName.new(RDF::Graph.new) }
|
110
|
+
it "should accept a hash" do
|
111
|
+
subject.elementList_attributes = [{ topicElement_attributes: {'0' => { elementValue:"Quantum Behavior" }, '1' => { elementValue:"Wave Function" }}}]
|
112
|
+
subject.elementList.first[0].elementValue.should == ["Quantum Behavior"]
|
113
|
+
subject.elementList.first[1].elementValue.should == ["Wave Function"]
|
114
114
|
|
115
115
|
end
|
116
|
-
it
|
117
|
-
subject.elementList_attributes = [{ topicElement_attributes: [{ elementValue:
|
118
|
-
|
119
|
-
|
116
|
+
it "should accept an array" do
|
117
|
+
subject.elementList_attributes = [{ topicElement_attributes: [{ elementValue:"Quantum Behavior" }, { elementValue:"Wave Function" }]}]
|
118
|
+
subject.elementList.first[0].elementValue.should == ["Quantum Behavior"]
|
119
|
+
subject.elementList.first[1].elementValue.should == ["Wave Function"]
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
123
|
+
it "should create nested objects" do
|
124
124
|
# Replace the graph's contents with the Hash
|
125
125
|
subject.attributes = params[:myResource]
|
126
126
|
|
127
127
|
# Here's how this would happen if we didn't have attributes=
|
128
|
-
# personal_name = subject.personalName.build
|
128
|
+
# personal_name = subject.personalName.build
|
129
129
|
# elem_list = personal_name.elementList.build
|
130
130
|
# elem_list.fullNameElement = "Jefferson, Thomas"
|
131
131
|
# elem_list.dateNameElement = "1743-1826"
|
@@ -133,35 +133,35 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
133
133
|
# elem_list = topic.elementList.build
|
134
134
|
# elem_list.fullNameElement = 'Cosmology'
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
subject.topic[0].elementList.first[0].elementValue.should == ["Cosmology"]
|
137
|
+
subject.topic[1].elementList.first[0].elementValue.should == ["Quantum Behavior"]
|
138
|
+
subject.personalName.first.elementList.first.fullNameElement.should == ["Jefferson, Thomas"]
|
139
|
+
subject.personalName.first.elementList.first.dateNameElement.should == ["1743-1826"]
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
describe
|
144
|
-
before(:each) do
|
143
|
+
describe "with an existing object" do
|
144
|
+
before(:each) do
|
145
145
|
class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
|
146
146
|
map_predicates do |map|
|
147
|
-
map.parts(:in
|
147
|
+
map.parts(:in=> RDF::DC, :to=>'hasPart', :class_name=>'Component')
|
148
148
|
end
|
149
149
|
accepts_nested_attributes_for :parts, allow_destroy: true
|
150
150
|
|
151
151
|
class Component
|
152
152
|
include ActiveFedora::RdfObject
|
153
153
|
map_predicates do |map|
|
154
|
-
map.label(:in
|
154
|
+
map.label(:in=> RDF::DC, :to=>'title')
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
after(:each) do
|
162
162
|
Object.send(:remove_const, :SpecDatastream)
|
163
163
|
end
|
164
|
-
subject { SpecDatastream.new(double('inner object', :pid
|
164
|
+
subject { SpecDatastream.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMetadata') }
|
165
165
|
before do
|
166
166
|
subject.attributes = { parts_attributes: [
|
167
167
|
{label: 'Alternator'},
|
@@ -172,16 +172,16 @@ describe 'Nesting attribute behavior of RDFDatastream' do
|
|
172
172
|
let (:replace_object_id) { subject.parts[1].rdf_subject.to_s }
|
173
173
|
let (:remove_object_id) { subject.parts[3].rdf_subject.to_s }
|
174
174
|
|
175
|
-
it
|
176
|
-
subject.parts_attributes
|
175
|
+
it "should update nested objects" do
|
176
|
+
subject.parts_attributes= [{id: replace_object_id, label: "Universal Joint"}, {label:"Oil Pump"}, {id: remove_object_id, _destroy: '1', label: "bar1 uno"}]
|
177
177
|
|
178
|
-
|
178
|
+
subject.parts.map{|p| p.label.first}.should == ['Alternator', 'Universal Joint', 'Transmission', 'Oil Pump']
|
179
179
|
|
180
180
|
end
|
181
|
-
it
|
182
|
-
subject.parts_attributes
|
183
|
-
|
181
|
+
it "create a new object when the id is provided" do
|
182
|
+
subject.parts_attributes= [{id: 'http://example.com/part#1', label: "Universal Joint"}]
|
183
|
+
subject.parts.last.rdf_subject.should == 'http://example.com/part#1'
|
184
184
|
end
|
185
|
-
end
|
185
|
+
end
|
186
186
|
end
|
187
187
|
end
|
@@ -1,65 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Model do
|
4
|
-
|
5
|
-
before(:all) do
|
4
|
+
|
5
|
+
before(:all) do
|
6
6
|
module ModelIntegrationSpec
|
7
7
|
class Basic < ActiveFedora::Base
|
8
|
-
has_metadata :name =>
|
9
|
-
m.field
|
10
|
-
m.field
|
11
|
-
m.field
|
8
|
+
has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
|
9
|
+
m.field "foo", :string
|
10
|
+
m.field "bar", :string
|
11
|
+
m.field "baz", :string
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
has_attributes :foo, :bar, :baz, datastream: 'properties', multiple: true
|
15
15
|
|
16
16
|
def to_solr(doc = {})
|
17
17
|
doc = super
|
18
18
|
doc[ActiveFedora::SolrService.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrService.solr_name('foo', type: :string)]
|
19
19
|
doc
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
after(:all) do
|
28
27
|
Object.send(:remove_const, :ModelIntegrationSpec)
|
29
28
|
end
|
30
29
|
|
31
30
|
|
32
|
-
describe
|
33
|
-
let!(:instance1){ ModelIntegrationSpec::Basic.create!(:foo
|
34
|
-
let!(:instance2){ ModelIntegrationSpec::Basic.create!(:foo
|
35
|
-
let!(:instance3){ ModelIntegrationSpec::Basic.create!(:foo
|
31
|
+
describe "with multiple objects" do
|
32
|
+
let!(:instance1){ ModelIntegrationSpec::Basic.create!(:foo=>'Beta', :bar=>'Chips')}
|
33
|
+
let!(:instance2){ ModelIntegrationSpec::Basic.create!(:foo=>'Alpha', :bar=>'Peanuts')}
|
34
|
+
let!(:instance3){ ModelIntegrationSpec::Basic.create!(:foo=>'Sigma', :bar=>'Peanuts')}
|
36
35
|
|
37
36
|
after { ModelIntegrationSpec::Basic.delete_all }
|
38
37
|
|
39
38
|
subject { ModelIntegrationSpec::Basic.where(bar: 'Peanuts') }
|
40
39
|
|
41
|
-
it
|
42
|
-
|
40
|
+
it "should map" do
|
41
|
+
subject.map(&:id).should == [instance2.id, instance3.id]
|
43
42
|
end
|
44
43
|
|
45
|
-
it
|
46
|
-
|
44
|
+
it "should collect" do
|
45
|
+
subject.collect(&:id).should == [instance2.id, instance3.id]
|
47
46
|
end
|
48
47
|
|
49
|
-
it
|
48
|
+
it "should have each" do
|
50
49
|
t = double
|
51
|
-
|
50
|
+
t.should_receive(:foo).twice
|
52
51
|
subject.each { t.foo }
|
53
52
|
end
|
54
53
|
|
55
|
-
it
|
56
|
-
expect(subject.all? { |t| t.foo == ['Alpha']}).to
|
57
|
-
expect(subject.all? { |t| t.bar == ['Peanuts']}).to
|
54
|
+
it "should have all?" do
|
55
|
+
expect(subject.all? { |t| t.foo == ['Alpha']}).to be_false
|
56
|
+
expect(subject.all? { |t| t.bar == ['Peanuts']}).to be_true
|
58
57
|
end
|
59
58
|
|
60
|
-
it
|
61
|
-
expect(subject.include?(instance1)).to
|
62
|
-
expect(subject.include?(instance2)).to
|
59
|
+
it "should have include?" do
|
60
|
+
expect(subject.include?(instance1)).to be_false
|
61
|
+
expect(subject.include?(instance2)).to be_true
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
65
|
+
|
66
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
before :all do
|
5
|
+
class Library < ActiveFedora::Base
|
6
|
+
has_many :books, property: :has_member
|
7
|
+
end
|
8
|
+
class Book < ActiveFedora::Base; end
|
9
|
+
end
|
10
|
+
after :all do
|
11
|
+
Library.delete_all
|
12
|
+
Object.send(:remove_const, :Library)
|
13
|
+
Object.send(:remove_const, :Book)
|
14
|
+
end
|
15
|
+
|
16
|
+
subject {Library.all}
|
17
|
+
its(:class) {should eq ActiveFedora::Relation }
|
18
|
+
|
19
|
+
describe "#find" do
|
20
|
+
before do
|
21
|
+
Library.create
|
22
|
+
@library = Library.create
|
23
|
+
end
|
24
|
+
it "should find one of them" do
|
25
|
+
expect(subject.find(@library.id)).to eq @library
|
26
|
+
end
|
27
|
+
it "should find with a block" do
|
28
|
+
expect(subject.find { |l| l.id == @library.id}).to eq @library
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#select" do
|
33
|
+
before do
|
34
|
+
Library.create
|
35
|
+
@library = Library.create
|
36
|
+
end
|
37
|
+
it "should find with a block" do
|
38
|
+
expect(subject.select { |l| l.id == @library.id}).to eq [@library]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'active_fedora'
|
4
|
-
require
|
4
|
+
require "rexml/document"
|
5
5
|
|
6
6
|
|
7
7
|
describe ActiveFedora::RelsExtDatastream do
|
8
|
-
|
8
|
+
|
9
9
|
before(:all) do
|
10
|
-
@sample_relationships_hash = Hash.new(:is_member_of => [
|
10
|
+
@sample_relationships_hash = Hash.new(:is_member_of => ["info:fedora/demo:5", "info:fedora/demo:10"])
|
11
11
|
@sample_xml_string = <<-EOS
|
12
12
|
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
13
13
|
<rdf:Description rdf:about="info:fedora/changeme:475">
|
@@ -16,17 +16,17 @@ describe ActiveFedora::RelsExtDatastream do
|
|
16
16
|
</rdf:Description>
|
17
17
|
</rdf:RDF>
|
18
18
|
EOS
|
19
|
-
|
19
|
+
|
20
20
|
@sample_xml = REXML::Document.new(@sample_xml_string)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
before(:each) do
|
24
24
|
@test_object = ActiveFedora::Base.new
|
25
25
|
@test_datastream = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
26
26
|
@test_datastream.model = @test_object
|
27
27
|
@test_object.save
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
after(:each) do
|
31
31
|
begin
|
32
32
|
@test_object.delete
|
@@ -49,34 +49,34 @@ describe ActiveFedora::RelsExtDatastream do
|
|
49
49
|
rescue
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
|
54
54
|
describe '#serialize!' do
|
55
|
-
|
56
|
-
it
|
55
|
+
|
56
|
+
it "should generate new rdf/xml as the datastream content" do
|
57
57
|
@test_object.add_datastream(@test_datastream)
|
58
|
-
@test_object.add_relationship(:is_member_of,
|
59
|
-
@test_object.add_relationship(:is_member_of,
|
58
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
59
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
60
60
|
rexml1 = REXML::Document.new(@test_datastream.to_rels_ext())
|
61
61
|
@test_datastream.serialize!
|
62
|
-
rexml2 = REXML::Document.new(@test_object.datastreams[
|
63
|
-
|
62
|
+
rexml2 = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
|
63
|
+
rexml1.root.elements["rdf:Description"].inspect.should eql(rexml2.root.elements["rdf:Description"].inspect)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
67
|
-
|
68
|
-
it
|
67
|
+
|
68
|
+
it "should load relationships from fedora into parent object" do
|
69
69
|
class SpecNode; include ActiveFedora::SemanticNode; end
|
70
|
-
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].each_key do |p|
|
70
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].each_key do |p|
|
71
71
|
@test_object.add_relationship(p, "info:fedora/demo:#{rand(100)}")
|
72
72
|
end
|
73
73
|
@test_object.save
|
74
74
|
# make sure that _something_ was actually added to the object's relationships hash
|
75
|
-
|
75
|
+
@test_object.ids_for_outbound(:is_member_of).size.should == 1
|
76
76
|
new_rels = ActiveFedora::Base.find(@test_object.pid).relationships
|
77
77
|
# This stopped working, need to push an issue into the rdf library. (when dumping ntriples, the order of assertions changed)
|
78
78
|
#new_rels.should == @test_object.relationships
|
79
|
-
|
79
|
+
new_rels.dump(:rdfxml).should == @test_object.relationships.dump(:rdfxml)
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|