active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Objects should be serialized to JSON" do
|
4
4
|
it "should have json results" do
|
5
|
-
expect(ActiveFedora::Base.new.to_json).to eq
|
5
|
+
expect(ActiveFedora::Base.new.to_json).to eq "{\"id\":null}"
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
context "with properties and datastream attributes" do
|
9
9
|
before do
|
10
10
|
class Foo < ActiveFedora::Base
|
11
11
|
has_metadata 'descMetadata', type: ActiveFedora::SimpleDatastream do |m|
|
@@ -14,18 +14,60 @@ describe "Objects should be serialized to JSON" do
|
|
14
14
|
end
|
15
15
|
has_attributes :foo, datastream: 'descMetadata', multiple: true
|
16
16
|
has_attributes :bar, datastream: 'descMetadata', multiple: false
|
17
|
+
property :title, predicate: ::RDF::DC.title
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
19
21
|
after do
|
20
22
|
Object.send(:remove_const, :Foo)
|
21
23
|
end
|
22
|
-
|
23
|
-
|
24
|
+
|
25
|
+
let(:obj) { Foo.new(foo: ["baz"], bar: 'quix', title: ['My Title']) }
|
26
|
+
|
27
|
+
before { allow(obj).to receive(:id).and_return('test-123') }
|
28
|
+
|
29
|
+
subject { JSON.parse(obj.to_json)}
|
30
|
+
|
24
31
|
it "should have to_json" do
|
25
|
-
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
32
|
+
expect(subject['id']).to eq "test-123"
|
33
|
+
expect(subject['foo']).to eq ["baz"]
|
34
|
+
expect(subject['bar']).to eq "quix"
|
35
|
+
expect(subject['title']).to eq ["My Title"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with nested nodes" do
|
40
|
+
before do
|
41
|
+
class DummySubnode < ActiveTriples::Resource
|
42
|
+
property :relation, predicate: ::RDF::DC[:relation]
|
43
|
+
end
|
44
|
+
|
45
|
+
class DummyResource < ActiveFedora::RDFDatastream
|
46
|
+
property :license, predicate: ::RDF::DC[:license], class_name: DummySubnode do |index|
|
47
|
+
index.as :searchable, :displayable
|
48
|
+
end
|
49
|
+
def serialization_format
|
50
|
+
:ntriples
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class DummyAsset < ActiveFedora::Base
|
55
|
+
has_metadata 'descMetadata', type: DummyResource
|
56
|
+
has_attributes :relation, datastream: 'descMetadata', at: [:license, :relation], multiple: false
|
57
|
+
end
|
29
58
|
end
|
59
|
+
|
60
|
+
after do
|
61
|
+
Object.send(:remove_const, "DummyAsset")
|
62
|
+
Object.send(:remove_const, "DummyResource")
|
63
|
+
Object.send(:remove_const, "DummySubnode")
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:obj) { DummyAsset.new { |a| a.relation = 'Great Grandchild' } }
|
67
|
+
before { allow(obj).to receive(:id).and_return('test-123') }
|
68
|
+
|
69
|
+
subject { JSON.parse(obj.to_json)}
|
70
|
+
|
71
|
+
it { should eq("id"=>"test-123", "relation"=>"Great Grandchild") }
|
30
72
|
end
|
31
73
|
end
|
@@ -7,7 +7,7 @@ describe ActiveFedora::Model do
|
|
7
7
|
|
8
8
|
class Base < ActiveFedora::Base
|
9
9
|
include ActiveFedora::Model
|
10
|
-
def self.
|
10
|
+
def self.id_namespace
|
11
11
|
"foo"
|
12
12
|
end
|
13
13
|
has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream, :autocreate => true
|
@@ -31,42 +31,25 @@ describe ActiveFedora::Model do
|
|
31
31
|
result = ModelIntegrationSpec::Basic.all.to_a
|
32
32
|
expect(result).to be_instance_of(Array)
|
33
33
|
# this test is meaningless if the array length is zero
|
34
|
-
expect(result
|
34
|
+
expect(result).to_not be_empty
|
35
35
|
result.each do |obj|
|
36
|
-
expect(obj.class).to eq
|
36
|
+
expect(obj.class).to eq ModelIntegrationSpec::Basic
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#find' do
|
42
|
-
describe "#find with a valid
|
43
|
-
subject { ActiveFedora::Base.find(@test_instance.
|
44
|
-
it {
|
42
|
+
describe "#find with a valid id without cast" do
|
43
|
+
subject { ActiveFedora::Base.find(@test_instance.id) }
|
44
|
+
it { should be_instance_of ModelIntegrationSpec::Basic }
|
45
45
|
end
|
46
|
-
describe "#find with a valid
|
47
|
-
subject { ActiveFedora::Base.find(@test_instance.
|
48
|
-
it {
|
46
|
+
describe "#find with a valid id with cast of false" do
|
47
|
+
subject { ActiveFedora::Base.find(@test_instance.id, cast: false) }
|
48
|
+
it { should be_instance_of ActiveFedora::Base }
|
49
49
|
end
|
50
|
-
describe "#find with a valid
|
51
|
-
subject { ModelIntegrationSpec::Basic.find(@test_instance.
|
52
|
-
it {
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#load_instance_from_solr" do
|
57
|
-
describe "with a valid pid" do
|
58
|
-
subject { ActiveFedora::Base.load_instance_from_solr(@test_instance.pid) }
|
59
|
-
it { is_expected.to be_instance_of ModelIntegrationSpec::Basic}
|
60
|
-
end
|
61
|
-
describe "with metadata datastream spec" do
|
62
|
-
subject { ActiveFedora::Base.load_instance_from_solr(@test_instance.pid) }
|
63
|
-
it "should create an xml datastream" do
|
64
|
-
expect(subject.datastreams['properties']).to be_kind_of ActiveFedora::SimpleDatastream
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should know the datastreams properties" do
|
68
|
-
expect(subject.properties.dsSize).to eq(9)
|
69
|
-
end
|
50
|
+
describe "#find with a valid id without cast on a model extending Base" do
|
51
|
+
subject { ModelIntegrationSpec::Basic.find(@test_instance.id) }
|
52
|
+
it { should be_instance_of ModelIntegrationSpec::Basic }
|
70
53
|
end
|
71
54
|
end
|
72
55
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "NestedAttribute behavior" do
|
4
4
|
before do
|
5
5
|
class Bar < ActiveFedora::Base
|
6
|
-
belongs_to :car, :
|
6
|
+
belongs_to :car, predicate: ActiveFedora::RDF::RelsExt.hasMember
|
7
7
|
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
8
8
|
m.field "uno", :string
|
9
9
|
m.field "dos", :string
|
@@ -13,7 +13,7 @@ describe "NestedAttribute behavior" do
|
|
13
13
|
|
14
14
|
# base Car class, used in test for association updates and :allow_destroy flag
|
15
15
|
class Car < ActiveFedora::Base
|
16
|
-
has_many :bars, :
|
16
|
+
has_many :bars, predicate: ActiveFedora::RDF::RelsExt.hasMember
|
17
17
|
accepts_nested_attributes_for :bars, :allow_destroy=>true
|
18
18
|
end
|
19
19
|
|
@@ -41,52 +41,60 @@ describe "NestedAttribute behavior" do
|
|
41
41
|
accepts_nested_attributes_for :bars, :limit => 1
|
42
42
|
end
|
43
43
|
end
|
44
|
+
after do
|
45
|
+
Object.send(:remove_const, :Bar)
|
46
|
+
Object.send(:remove_const, :CarAllBlank)
|
47
|
+
Object.send(:remove_const, :CarProc)
|
48
|
+
Object.send(:remove_const, :CarSymbol)
|
49
|
+
Object.send(:remove_const, :CarWithLimit)
|
50
|
+
Object.send(:remove_const, :Car)
|
51
|
+
end
|
44
52
|
|
45
53
|
it "should have _destroy" do
|
46
|
-
expect(Bar.new._destroy).to
|
54
|
+
expect(Bar.new._destroy).to be_nil
|
47
55
|
end
|
48
56
|
|
49
57
|
it "should update the child objects" do
|
50
58
|
@car, @bar1, @bar2 = create_car_with_bars
|
51
59
|
|
52
|
-
@car.
|
53
|
-
expect(Bar.find(@bar1.
|
54
|
-
expect(Bar.where(:id => @bar2.
|
55
|
-
expect(Bar.where(:uno => "newbar uno").first).
|
60
|
+
@car.update bars_attributes: [{id: @bar1.id, uno: "bar1 uno"}, {uno: "newbar uno"}, {id: @bar2.id, _destroy: '1', uno: 'bar2 uno'}]
|
61
|
+
expect(Bar.find(@bar1.id).uno).to eq 'bar1 uno'
|
62
|
+
expect(Bar.where(:id => @bar2.id).first).to be_nil
|
63
|
+
expect(Bar.where(:uno => "newbar uno").first).to_not be_nil
|
56
64
|
|
57
65
|
bars = @car.bars(true)
|
58
66
|
expect(bars).to include(@bar1)
|
59
|
-
expect(bars).
|
67
|
+
expect(bars).to_not include(@bar2)
|
60
68
|
end
|
61
69
|
|
62
70
|
it "should reject attributes when all blank" do
|
63
71
|
@car, @bar1, @bar2 = create_car_with_bars(CarAllBlank)
|
64
72
|
|
65
|
-
expect(@car.bars.count).to eq
|
66
|
-
@car.
|
67
|
-
expect(@car.bars(true).count).to eq
|
73
|
+
expect(@car.bars.count).to eq 2
|
74
|
+
@car.update bars_attributes: [{}, {:id=>@bar1.id, :uno=>"bar1 uno"}]
|
75
|
+
expect(@car.bars(true).count).to eq 2
|
68
76
|
|
69
77
|
@bar1.reload
|
70
|
-
expect(@bar1.uno).to eq
|
78
|
+
expect(@bar1.uno).to eq "bar1 uno"
|
71
79
|
end
|
72
80
|
|
73
81
|
it "should reject attributes based on proc" do
|
74
82
|
@car, @bar1, @bar2 = create_car_with_bars(CarProc)
|
75
83
|
|
76
|
-
@car.
|
84
|
+
@car.update bars_attributes: [{}, {:id=>@bar1.id, :uno=>"bar1 uno"}, {:id=>@bar2.id, :dos=>"bar2 dos"}]
|
77
85
|
@bar1.reload
|
78
86
|
@bar2.reload
|
79
|
-
expect(@bar1.uno).to eq
|
87
|
+
expect(@bar1.uno).to eq "bar1 uno"
|
80
88
|
expect(@bar2.dos).to be_nil
|
81
89
|
end
|
82
90
|
|
83
91
|
it "should reject attributes base on method name" do
|
84
92
|
@car, @bar1, @bar2 = create_car_with_bars(CarSymbol)
|
85
93
|
|
86
|
-
@car.
|
94
|
+
@car.update bars_attributes: [{}, {:id=>@bar1.id, :uno=>"bar1 uno"}, {:id=>@bar2.id, :dos=>"bar2 dos"}]
|
87
95
|
@bar1.reload
|
88
96
|
@bar2.reload
|
89
|
-
expect(@bar1.uno).to eq
|
97
|
+
expect(@bar1.uno).to eq "bar1 uno"
|
90
98
|
expect(@bar2.dos).to be_nil
|
91
99
|
end
|
92
100
|
|
@@ -95,7 +103,7 @@ describe "NestedAttribute behavior" do
|
|
95
103
|
|
96
104
|
expect {
|
97
105
|
@car.attributes = {:bars_attributes=>[{}]}
|
98
|
-
}.
|
106
|
+
}.to_not raise_exception
|
99
107
|
|
100
108
|
expect {
|
101
109
|
@car.attributes = {:bars_attributes=>[{}, {}]}
|
@@ -111,10 +119,10 @@ describe "NestedAttribute behavior" do
|
|
111
119
|
#
|
112
120
|
# @return [car,bar,bar] returns 1 Car and 2 Bars
|
113
121
|
def create_car_with_bars(car_class = Car, bar_class = Bar)
|
114
|
-
car = car_class.new; car.save
|
122
|
+
car = car_class.new; car.save!
|
115
123
|
|
116
|
-
bar1 = bar_class.new(:car
|
117
|
-
bar2 = bar_class.new(:car
|
124
|
+
bar1 = bar_class.new(car: car); bar1.save!
|
125
|
+
bar2 = bar_class.new(car: car); bar2.save!
|
118
126
|
[car, bar1, bar2]
|
119
127
|
end
|
120
128
|
|
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::NtriplesRDFDatastream do
|
4
4
|
before do
|
5
|
-
|
5
|
+
|
6
6
|
class FileVocabulary < RDF::Vocabulary("http://downlode.org/Code/RDF/File_Properties/schema#")
|
7
7
|
property :size
|
8
8
|
end
|
9
9
|
|
10
10
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
11
|
-
property :title, predicate: RDF::DC.title do |index|
|
11
|
+
property :title, predicate: ::RDF::DC.title do |index|
|
12
12
|
index.as :stored_searchable, :facetable
|
13
13
|
end
|
14
|
-
property :date_uploaded, predicate: RDF::DC.dateSubmitted do |index|
|
14
|
+
property :date_uploaded, predicate: ::RDF::DC.dateSubmitted do |index|
|
15
15
|
index.type :date
|
16
16
|
index.as :stored_searchable, :sortable
|
17
17
|
end
|
@@ -19,11 +19,12 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
19
19
|
index.type :integer
|
20
20
|
index.as :stored_sortable
|
21
21
|
end
|
22
|
-
property :part, predicate: RDF::DC.hasPart
|
23
|
-
property :based_near, predicate: RDF::FOAF.based_near
|
24
|
-
property :related_url, predicate: RDF::RDFS.seeAlso
|
22
|
+
property :part, predicate: ::RDF::DC.hasPart
|
23
|
+
property :based_near, predicate: ::RDF::FOAF.based_near
|
24
|
+
property :related_url, predicate: ::RDF::RDFS.seeAlso
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
class RdfTest < ActiveFedora::Base
|
27
28
|
has_metadata 'rdf', type: MyDatastream
|
28
29
|
has_attributes :based_near, :related_url, :part, :date_uploaded, datastream: 'rdf', multiple: true
|
29
30
|
has_attributes :title, :filesize, datastream: 'rdf', multiple: false
|
@@ -46,19 +47,19 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should save content properly upon save" do
|
49
|
-
foo = RdfTest.new(
|
50
|
+
foo = RdfTest.new('test:1') #ID needs to match the subject in the loaded file
|
50
51
|
foo.title = 'Hamlet'
|
51
52
|
foo.save
|
52
|
-
expect(foo.title).to eq
|
53
|
+
expect(foo.title).to eq 'Hamlet'
|
53
54
|
foo.rdf.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
54
55
|
foo.save
|
55
|
-
expect(foo.title).to eq
|
56
|
+
expect(foo.title).to eq 'Title of work'
|
56
57
|
end
|
57
58
|
|
58
59
|
it "should delegate as_json to the fields" do
|
59
60
|
@subject = RdfTest.new(title: "Title of work")
|
60
|
-
expect(@subject.rdf.title.as_json).to eq
|
61
|
-
expect(@subject.rdf.title.to_json).to eq
|
61
|
+
expect(@subject.rdf.title.as_json).to eq ["Title of work"]
|
62
|
+
expect(@subject.rdf.title.to_json).to eq "\[\"Title of work\"\]"
|
62
63
|
end
|
63
64
|
|
64
65
|
it "should solrize even when the object is not new" do
|
@@ -66,10 +67,10 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
66
67
|
expect(foo).to receive(:update_index).once
|
67
68
|
foo.title = "title1"
|
68
69
|
foo.save
|
69
|
-
foo = RdfTest.find(foo.
|
70
|
+
foo = RdfTest.find(foo.id)
|
70
71
|
expect(foo).to receive(:update_index).once
|
71
72
|
foo.title = "The Work2"
|
72
|
-
foo.save
|
73
|
+
foo.save
|
73
74
|
end
|
74
75
|
|
75
76
|
describe "serializing" do
|
@@ -77,21 +78,21 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
77
78
|
subject.date_uploaded = [Date.parse('2012-11-02')]
|
78
79
|
expect(subject.date_uploaded.first).to be_kind_of Date
|
79
80
|
solr_document = subject.to_solr
|
80
|
-
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__date_uploaded', type: :date)]).to eq
|
81
|
+
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__date_uploaded', type: :date)]).to eq ['2012-11-02T00:00:00Z']
|
81
82
|
end
|
82
83
|
it "should handle integers" do
|
83
84
|
subject.filesize = 12345
|
84
85
|
expect(subject.filesize).to be_kind_of Fixnum
|
85
86
|
solr_document = subject.to_solr
|
86
|
-
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__filesize', :stored_sortable, type: :integer)]).to eq
|
87
|
+
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__filesize', :stored_sortable, type: :integer)]).to eq '12345'
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
90
91
|
it "should produce a solr document" do
|
91
92
|
@subject = RdfTest.new(title: "War and Peace")
|
92
93
|
solr_document = @subject.to_solr
|
93
|
-
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__title', :facetable)]).to eq
|
94
|
-
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__title', type: :string)]).to eq
|
94
|
+
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__title', :facetable)]).to eq ["War and Peace"]
|
95
|
+
expect(solr_document[ActiveFedora::SolrService.solr_name('rdf__title', type: :string)]).to eq ["War and Peace"]
|
95
96
|
end
|
96
97
|
|
97
98
|
it "should set and recall values" do
|
@@ -101,11 +102,12 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
101
102
|
@subject.related_url = ["http://en.wikipedia.org/wiki/War_and_Peace"]
|
102
103
|
@subject.part = ["this is a part"]
|
103
104
|
@subject.save
|
104
|
-
expect(@subject.title).to eq
|
105
|
-
expect(@subject.based_near).to eq
|
106
|
-
expect(@subject.related_url).to eq
|
107
|
-
expect(@subject.part).to eq
|
105
|
+
expect(@subject.title).to eq 'War and Peace'
|
106
|
+
expect(@subject.based_near).to eq ["Moscow, Russia"]
|
107
|
+
expect(@subject.related_url).to eq ["http://en.wikipedia.org/wiki/War_and_Peace"]
|
108
|
+
expect(@subject.part).to eq ["this is a part"]
|
108
109
|
end
|
110
|
+
|
109
111
|
it "should set, persist, and recall values" do
|
110
112
|
@subject.title = 'War and Peace'
|
111
113
|
@subject.based_near = ["Moscow, Russia"]
|
@@ -113,25 +115,27 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
113
115
|
@subject.part = ["this is a part"]
|
114
116
|
@subject.save
|
115
117
|
|
116
|
-
loaded = RdfTest.find(@subject.
|
117
|
-
expect(loaded.title).to eq
|
118
|
-
expect(loaded.based_near).to eq
|
119
|
-
expect(loaded.related_url).to eq
|
120
|
-
expect(loaded.part).to eq
|
118
|
+
loaded = RdfTest.find(@subject.id)
|
119
|
+
expect(loaded.title).to eq 'War and Peace'
|
120
|
+
expect(loaded.based_near).to eq ['Moscow, Russia']
|
121
|
+
expect(loaded.related_url).to eq ['http://en.wikipedia.org/wiki/War_and_Peace']
|
122
|
+
expect(loaded.part).to eq ['this is a part']
|
121
123
|
end
|
124
|
+
|
122
125
|
it "should set multiple values" do
|
123
126
|
@subject.part = ["part 1", "part 2"]
|
124
127
|
@subject.save
|
125
128
|
|
126
|
-
loaded = RdfTest.find(@subject.
|
127
|
-
expect(loaded.part).to eq
|
129
|
+
loaded = RdfTest.find(@subject.id)
|
130
|
+
expect(loaded.part).to eq ['part 1', 'part 2']
|
128
131
|
end
|
132
|
+
|
129
133
|
it "should append values" do
|
130
134
|
@subject.part = ["thing 1"]
|
131
135
|
@subject.save
|
132
136
|
|
133
137
|
@subject.part << "thing 2"
|
134
|
-
expect(@subject.part).to eq
|
138
|
+
expect(@subject.part).to eq ["thing 1", "thing 2"]
|
135
139
|
end
|
136
140
|
|
137
141
|
it "should be able to save a blank document" do
|
@@ -144,30 +148,30 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
144
148
|
<http://oregondigital.org/ns/62> <http://purl.org/dc/terms/spatial> "Benton County (Ore.)" .
|
145
149
|
'
|
146
150
|
@subject.rdf.content = ntrip
|
147
|
-
expect(@subject.rdf.graph.dump(:ntriples)).to eq
|
151
|
+
expect(@subject.rdf.graph.dump(:ntriples)).to eq ntrip
|
148
152
|
end
|
149
153
|
|
150
154
|
describe "using rdf_subject" do
|
151
155
|
before do
|
152
156
|
# reopening existing class
|
153
157
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
154
|
-
rdf_subject { |ds| RDF::URI.new("http://oregondigital.org/ns/#{ds.
|
155
|
-
property :dctype, predicate: RDF::DC.type
|
156
|
-
property :spatial, predicate: RDF::DC.spatial
|
158
|
+
rdf_subject { |ds| RDF::URI.new("http://oregondigital.org/ns/#{parent_uri(ds).split('/')[-1].split(':')[1]}") }
|
159
|
+
property :dctype, predicate: ::RDF::DC.type
|
157
160
|
end
|
161
|
+
subject.rdf.dctype = "Frog"
|
162
|
+
subject.save!
|
158
163
|
end
|
164
|
+
|
159
165
|
after do
|
160
|
-
|
166
|
+
subject.destroy
|
161
167
|
end
|
162
168
|
|
163
|
-
|
164
|
-
@subject.inner_object.pid = 'test:99'
|
165
|
-
@subject.rdf.dctype = "Frog"
|
166
|
-
@subject.save!
|
167
|
-
@subject.reload
|
168
|
-
expect(@subject.rdf.graph.dump(:ntriples)).to eq("<http://oregondigital.org/ns/99> <http://purl.org/dc/terms/type> \"Frog\" .\n")
|
169
|
-
@subject.rdf.dctype == ['Frog']
|
169
|
+
subject { RdfTest.new('/test:99') }
|
170
170
|
|
171
|
+
it "should write rdf with proper subjects" do
|
172
|
+
subject.reload
|
173
|
+
expect(subject.rdf.graph.dump(:ntriples)).to eq "<http://oregondigital.org/ns/99> <http://purl.org/dc/terms/type> \"Frog\" .\n"
|
174
|
+
subject.rdf.dctype == ['Frog']
|
171
175
|
end
|
172
176
|
|
173
177
|
end
|
@@ -178,37 +182,37 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
178
182
|
@subject.related_url = ["http://psu.edu/"]
|
179
183
|
@subject.related_url << "http://projecthydra.org/"
|
180
184
|
|
181
|
-
expect(@subject.title).to eq
|
185
|
+
expect(@subject.title).to eq "Hamlet"
|
182
186
|
expect(@subject.related_url).to include("http://psu.edu/")
|
183
187
|
expect(@subject.related_url).to include("http://projecthydra.org/")
|
184
188
|
|
185
189
|
@subject.title = "" #empty string can be meaningful, don't assume delete.
|
186
|
-
expect(@subject.title).to eq
|
190
|
+
expect(@subject.title).to eq ''
|
187
191
|
|
188
192
|
@subject.title = nil
|
189
193
|
@subject.related_url.delete("http://projecthydra.org/")
|
190
194
|
|
191
195
|
expect(@subject.title).to be_nil
|
192
|
-
expect(@subject.related_url).to eq
|
196
|
+
expect(@subject.related_url).to eq ["http://psu.edu/"]
|
193
197
|
end
|
194
198
|
it "should delete multiple values at once" do
|
195
199
|
@subject.part = ["MacBeth"]
|
196
200
|
@subject.part << "Hamlet"
|
197
201
|
@subject.part << "Romeo & Juliet"
|
198
|
-
expect(@subject.part.first).to eq
|
202
|
+
expect(@subject.part.first).to eq "MacBeth"
|
199
203
|
@subject.part.delete("MacBeth", "Romeo & Juliet")
|
200
|
-
expect(@subject.part).to eq
|
201
|
-
expect(@subject.part.first).to eq
|
204
|
+
expect(@subject.part).to eq ["Hamlet"]
|
205
|
+
expect(@subject.part.first).to eq "Hamlet"
|
202
206
|
end
|
203
207
|
it "should ignore values to be deleted that do not exist" do
|
204
208
|
@subject.part = ["title1", "title2", "title3"]
|
205
209
|
@subject.part.delete("title2", "title4", "title6")
|
206
|
-
expect(@subject.part).to eq
|
210
|
+
expect(@subject.part).to eq ["title1", "title3"]
|
207
211
|
end
|
208
212
|
describe "term proxy methods" do
|
209
213
|
before(:each) do
|
210
214
|
class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
|
211
|
-
property :title, predicate: RDF::DC.title
|
215
|
+
property :title, predicate: ::RDF::DC.title
|
212
216
|
end
|
213
217
|
class Foobar < ActiveFedora::Base
|
214
218
|
has_metadata 'rdf', type: TitleDatastream
|
@@ -224,25 +228,24 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
224
228
|
end
|
225
229
|
|
226
230
|
it "should support the count method to determine # of values" do
|
227
|
-
expect(@subject.title.count).to eq
|
231
|
+
expect(@subject.title.count).to eq 3
|
228
232
|
end
|
229
233
|
it "should iterate over multiple values" do
|
230
234
|
expect(@subject.title).to respond_to(:each)
|
231
235
|
end
|
232
236
|
it "should get the first value" do
|
233
|
-
expect(@subject.title.first).to eq
|
237
|
+
expect(@subject.title.first).to eq "title1"
|
234
238
|
end
|
235
239
|
it "should evaluate equality predictably" do
|
236
|
-
expect(@subject.title).to eq
|
240
|
+
expect(@subject.title).to eq ["title1", "title2", "title3"]
|
237
241
|
end
|
238
242
|
it "should support the empty? method" do
|
239
|
-
expect(@subject.title).
|
240
|
-
expect(@subject.title.empty?).to be_falsey
|
243
|
+
expect(@subject.title).to_not be_empty
|
241
244
|
@subject.title.delete("title1", "title2", "title3")
|
242
|
-
expect(@subject.title
|
245
|
+
expect(@subject.title).to be_empty
|
243
246
|
end
|
244
247
|
it "should support the is_a? method" do
|
245
|
-
expect(@subject.title.is_a?(Array)).to eq
|
248
|
+
expect(@subject.title.is_a?(Array)).to eq true
|
246
249
|
end
|
247
250
|
end
|
248
251
|
end
|