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,7 +2,7 @@ require 'rails/generators'
|
|
2
2
|
|
3
3
|
module ActiveFedora
|
4
4
|
class Config::SolrGenerator < Rails::Generators::Base
|
5
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
source_root ::File.expand_path('../templates', __FILE__)
|
6
6
|
|
7
7
|
def generate
|
8
8
|
# Overwrite the configuration files that Blacklight has installed
|
@@ -2,7 +2,7 @@ require 'rails/generators'
|
|
2
2
|
|
3
3
|
module ActiveFedora
|
4
4
|
class ModelGenerator < Rails::Generators::NamedBase
|
5
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
source_root ::File.expand_path('../templates', __FILE__)
|
6
6
|
check_class_collision
|
7
7
|
|
8
8
|
class_option :directory, :type => :string, :default => 'models', :desc => "Which directory to generate? (i.e. app/DIRECTORY)"
|
@@ -11,10 +11,10 @@ module ActiveFedora
|
|
11
11
|
class_option :descMetadata, :type => :string, :default => nil, :desc => "Add a descMetadata metadata datastream"
|
12
12
|
|
13
13
|
def install
|
14
|
-
template('model.rb.erb',File.join('app', directory, "#{file_name}.rb"))
|
15
|
-
template('datastream.rb.erb',File.join('app', datastream_directory, "#{file_name}_metadata.rb"))
|
16
|
-
template('model_spec.rb.erb',File.join('spec', directory, "#{file_name}_spec.rb"))
|
17
|
-
template('datastream_spec.rb.erb',File.join('spec', datastream_directory, "#{file_name}_metadata_spec.rb"))
|
14
|
+
template('model.rb.erb', ::File.join('app', directory, "#{file_name}.rb"))
|
15
|
+
template('datastream.rb.erb', ::File.join('app', datastream_directory, "#{file_name}_metadata.rb"))
|
16
|
+
template('model_spec.rb.erb', ::File.join('spec', directory, "#{file_name}_spec.rb"))
|
17
|
+
template('datastream_spec.rb.erb', ::File.join('spec', datastream_directory, "#{file_name}_metadata_spec.rb"))
|
18
18
|
end
|
19
19
|
|
20
20
|
protected
|
@@ -6,7 +6,7 @@ describe <%= class_name %>Metadata do
|
|
6
6
|
it 'should have a title' do
|
7
7
|
pending "Create a terminology for <%= class_name %>Metadata, then enable this test"
|
8
8
|
subject.title = 'War and Peace'
|
9
|
-
subject.title.
|
9
|
+
expect(subject.title).to eq ['War and Peace']
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -12,12 +12,12 @@ describe <%= class_name %> do
|
|
12
12
|
before { subject.save! }
|
13
13
|
after { subject.destroy }
|
14
14
|
it 'should exist' do
|
15
|
-
<%= class_name %>.exists?(subject.
|
15
|
+
expect(<%= class_name %>.exists?(subject.id)).to be true
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should have a descMetadata datastream' do
|
20
|
-
subject.descMetadata.
|
20
|
+
expect(subject.descMetadata).to be_kind_of <%= options['descMetadata'] ? options['descMetadata'] : "#{class_name}Metadata" %>
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
|
2
2
|
|
3
3
|
require 'jettywrapper'
|
4
|
-
JETTY_ZIP_BASENAME = '
|
4
|
+
JETTY_ZIP_BASENAME = 'fedora-4/master'
|
5
5
|
Jettywrapper.url = "https://github.com/projecthydra/hydra-jetty/archive/#{JETTY_ZIP_BASENAME}.zip"
|
6
6
|
|
7
7
|
namespace :active_fedora do
|
@@ -13,7 +13,7 @@ namespace :active_fedora do
|
|
13
13
|
doc_destination = File.join(project_root, 'doc')
|
14
14
|
|
15
15
|
YARD::Rake::YardocTask.new(:doc) do |yt|
|
16
|
-
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
|
16
|
+
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
|
17
17
|
[ '-', File.join(project_root, 'README.md')]
|
18
18
|
yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
|
19
19
|
end
|
@@ -26,47 +26,41 @@ namespace :active_fedora do
|
|
26
26
|
|
27
27
|
require 'rspec/core/rake_task'
|
28
28
|
RSpec::Core::RakeTask.new(:rspec) do |spec|
|
29
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
30
|
-
spec.pattern += FileList['spec/*_spec.rb']
|
31
29
|
spec.rspec_opts = ['--backtrace'] if ENV['CI']
|
32
30
|
end
|
33
31
|
|
34
32
|
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
-
spec.pattern += FileList['spec/*_spec.rb']
|
37
33
|
spec.rcov = true
|
38
34
|
end
|
39
35
|
|
40
36
|
desc "Copies the default SOLR config for the bundled Testing Server"
|
41
37
|
task :configure_jetty do
|
42
|
-
FileList['lib/generators/active_fedora/config/solr/templates/solr_conf/conf/*'].each do |f|
|
38
|
+
FileList['lib/generators/active_fedora/config/solr/templates/solr_conf/conf/*'].each do |f|
|
43
39
|
cp("#{f}", 'jetty/solr/development-core/conf/', :verbose => true)
|
44
40
|
cp("#{f}", 'jetty/solr/test-core/conf/', :verbose => true)
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
44
|
|
49
|
-
desc "CI build"
|
50
|
-
task :ci do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
45
|
+
desc "CI build"
|
46
|
+
task :ci do
|
47
|
+
ENV['environment'] = "test"
|
48
|
+
Rake::Task["active_fedora:configure_jetty"].invoke
|
49
|
+
jetty_params = Jettywrapper.load_config
|
50
|
+
error = Jettywrapper.wrap(jetty_params) do
|
51
|
+
Rake::Task['active_fedora:coverage'].invoke
|
52
|
+
end
|
53
|
+
raise "test failures: #{error}" if error
|
54
|
+
# Only create documentation if the tests have passed
|
55
|
+
Rake::Task["active_fedora:doc"].invoke
|
56
56
|
end
|
57
|
-
raise "test failures: #{error}" if error
|
58
|
-
# Only create documentation if the tests have passed
|
59
|
-
Rake::Task["active_fedora:doc"].invoke
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Execute specs with coverage"
|
63
|
-
task :coverage do
|
64
|
-
# Put spec opts in a file named .rspec in root
|
65
|
-
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
66
|
-
ENV['COVERAGE'] = 'true' unless ruby_engine == 'jruby'
|
67
57
|
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
desc "Execute specs with coverage"
|
59
|
+
task :coverage do
|
60
|
+
# Put spec opts in a file named .rspec in root
|
61
|
+
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
62
|
+
ENV['COVERAGE'] = 'true' unless ruby_engine == 'jruby'
|
63
|
+
Rake::Task["active_fedora:rspec"].invoke
|
64
|
+
end
|
71
65
|
|
72
66
|
end
|
data/spec/config_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
<
|
5
|
-
<
|
6
|
-
<
|
1
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/created> "2010-12-31"^^<http://www.w3.org/2001/XMLSchema#date> .
|
2
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/title> "Title of work" .
|
3
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
|
4
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
|
5
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
|
6
|
+
<http://localhost:8983/fedora/rest/test/test:1/content> <http://purl.org/dc/terms/title> "Title of datastream" .
|
7
7
|
|
@@ -1,23 +1,7 @@
|
|
1
|
-
#
|
2
|
-
:default_namespace: info:fedora/fedora-system:def/relations-external#
|
1
|
+
:default_namespace: http://fedora.info/definitions/v4/rels-ext#
|
3
2
|
|
4
|
-
# namespace mappings---
|
5
|
-
# you can add specific mappings for your institution by providing the following:
|
6
|
-
# namespace_uri:
|
7
|
-
# :relationship_symbol: relationship_identifier
|
8
|
-
#
|
9
|
-
# For example, if you have the following element in your rels_ext:
|
10
|
-
#
|
11
|
-
# <oai:itemID>oai:example.edu:changeme:500</oai:itemID>
|
12
|
-
#
|
13
|
-
# With the last two lines of this file uncommented, the relationships hash of your object will include:
|
14
|
-
# :oai_item_id => ["info:fedora/oai:example.edu:changeme:500"]
|
15
|
-
#
|
16
|
-
# With the last two lines of this file commented out, the relationships hash of your object will include:
|
17
|
-
# "oai_itemID" => ["info:fedora/oai:example.edu:changeme:500"]
|
18
|
-
#
|
19
3
|
:predicate_mapping:
|
20
|
-
info
|
4
|
+
http://fedora.info/definitions/v4/rels-ext#:
|
21
5
|
:is_derivation_of: isDerivationOf
|
22
6
|
:is_metadata_for: isMetadataFor
|
23
7
|
:is_member_of_collection: isMemberOfCollection
|
@@ -41,7 +25,7 @@
|
|
41
25
|
:has_description: hasDescription
|
42
26
|
:has_part: hasPart
|
43
27
|
:has_member: hasMember
|
44
|
-
info
|
28
|
+
http://fedora.info/definitions/v4/model#:
|
45
29
|
:has_model: hasModel
|
46
30
|
# http://www.openarchives.org/OAI/2.0/:
|
47
31
|
# :oai_item_id: itemID
|
@@ -1,7 +1,7 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
<
|
5
|
-
<
|
6
|
-
<
|
1
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/created> "2009-10-10"^^<http://www.w3.org/2001/XMLSchema#date> .
|
2
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/title> "fake-title" .
|
3
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://purl.org/dc/terms/publisher> "publisher1" .
|
4
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "coverage1" .
|
5
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "coverage2" .
|
6
|
+
<http://localhost:8983/fedora/rest/test/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://example.org/> .
|
7
7
|
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
describe "use a URI as the property" do
|
5
5
|
before do
|
6
|
-
class Book < ActiveFedora::Base
|
7
|
-
belongs_to :author, :
|
6
|
+
class Book < ActiveFedora::Base
|
7
|
+
belongs_to :author, predicate: ::RDF::DC.creator, class_name: 'Person'
|
8
8
|
end
|
9
9
|
|
10
10
|
class Person < ActiveFedora::Base
|
@@ -16,7 +16,7 @@ describe ActiveFedora::Base do
|
|
16
16
|
Object.send(:remove_const, :Person)
|
17
17
|
end
|
18
18
|
|
19
|
-
let(:person) { Person.create}
|
19
|
+
let(:person) { Person.create }
|
20
20
|
let(:book) { Book.new(author: person) }
|
21
21
|
|
22
22
|
it "should go" do
|
@@ -27,14 +27,14 @@ describe ActiveFedora::Base do
|
|
27
27
|
|
28
28
|
describe "complex example" do
|
29
29
|
before do
|
30
|
-
class Library < ActiveFedora::Base
|
31
|
-
has_many :books, :
|
30
|
+
class Library < ActiveFedora::Base
|
31
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.hasConstituent
|
32
32
|
end
|
33
33
|
|
34
|
-
class Book < ActiveFedora::Base
|
35
|
-
belongs_to :library, :
|
36
|
-
belongs_to :author, :
|
37
|
-
belongs_to :publisher, :
|
34
|
+
class Book < ActiveFedora::Base
|
35
|
+
belongs_to :library, predicate: ActiveFedora::RDF::RelsExt.hasConstituent
|
36
|
+
belongs_to :author, predicate: ActiveFedora::RDF::RelsExt.hasMember, class_name: 'Person'
|
37
|
+
belongs_to :publisher, predicate: ActiveFedora::RDF::RelsExt.hasMember
|
38
38
|
end
|
39
39
|
|
40
40
|
class Person < ActiveFedora::Base
|
@@ -66,7 +66,7 @@ describe ActiveFedora::Base do
|
|
66
66
|
expect(new_book).to be_new_record
|
67
67
|
expect(new_book).to be_kind_of Book
|
68
68
|
expect(new_book.library).to be_kind_of Library
|
69
|
-
expect(@library.books).to eq
|
69
|
+
expect(@library.books).to eq [new_book]
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should make a new child" do
|
@@ -74,7 +74,7 @@ describe ActiveFedora::Base do
|
|
74
74
|
expect(new_book).to be_new_record
|
75
75
|
expect(new_book).to be_kind_of Book
|
76
76
|
expect(new_book.library).to be_kind_of Library
|
77
|
-
expect(@library.books).to eq
|
77
|
+
expect(@library.books).to eq [new_book]
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should not create children if the parent isn't saved" do
|
@@ -84,63 +84,63 @@ describe ActiveFedora::Base do
|
|
84
84
|
it "should create children" do
|
85
85
|
@library.save!
|
86
86
|
new_book = @library.books.create({})
|
87
|
-
expect(new_book).
|
87
|
+
expect(new_book).to_not be_new_record
|
88
88
|
expect(new_book).to be_kind_of Book
|
89
|
-
expect(new_book.library).to eq
|
89
|
+
expect(new_book.library).to eq @library
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should build parent" do
|
93
93
|
new_library = @book.build_library({})
|
94
94
|
expect(new_library).to be_new_record
|
95
95
|
expect(new_library).to be_kind_of Library
|
96
|
-
expect(@book.library).to eq
|
96
|
+
expect(@book.library).to eq new_library
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should create parent" do
|
100
100
|
new_library = @book.create_library({})
|
101
|
-
expect(new_library).
|
101
|
+
expect(new_library).to_not be_new_record
|
102
102
|
expect(new_library).to be_kind_of Library
|
103
|
-
expect(@book.library).to eq
|
103
|
+
expect(@book.library).to eq new_library
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should let you shift onto the association" do
|
107
|
-
expect(@library
|
108
|
-
expect(@library.books.size).to eq
|
109
|
-
expect(@library.books).to eq
|
110
|
-
expect(@library.book_ids).to eq
|
107
|
+
expect(@library).to be_new_record
|
108
|
+
expect(@library.books.size).to eq 0
|
109
|
+
expect(@library.books).to eq []
|
110
|
+
expect(@library.book_ids).to eq []
|
111
111
|
@library.books << @book
|
112
|
-
expect(@library.books).to eq
|
113
|
-
expect(@library.book_ids).to eq
|
112
|
+
expect(@library.books).to eq [@book]
|
113
|
+
expect(@library.book_ids).to eq [@book.id]
|
114
114
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should let you set an array of objects" do
|
118
118
|
@library.books = [@book, @book2]
|
119
|
-
expect(@library.books).to eq
|
119
|
+
expect(@library.books).to eq [@book, @book2]
|
120
120
|
@library.save
|
121
121
|
|
122
122
|
@library.books = [@book]
|
123
|
-
expect(@library.books).to eq
|
124
|
-
|
123
|
+
expect(@library.books).to eq [@book]
|
124
|
+
|
125
125
|
end
|
126
126
|
it "should let you set an array of object ids" do
|
127
|
-
@library.book_ids = [@book.
|
128
|
-
expect(@library.books).to eq
|
127
|
+
@library.book_ids = [@book.id, @book2.id]
|
128
|
+
expect(@library.books).to eq [@book, @book2]
|
129
129
|
end
|
130
130
|
|
131
131
|
it "setter should wipe out previously saved relations" do
|
132
|
-
@library.book_ids = [@book.
|
133
|
-
@library.book_ids = [@book2.
|
134
|
-
expect(@library.books).to eq
|
135
|
-
|
132
|
+
@library.book_ids = [@book.id, @book2.id]
|
133
|
+
@library.book_ids = [@book2.id]
|
134
|
+
expect(@library.books).to eq [@book2]
|
135
|
+
|
136
136
|
end
|
137
137
|
|
138
138
|
it "saving the parent should save the relationships on the children" do
|
139
139
|
@library.save
|
140
140
|
@library.books = [@book, @book2]
|
141
141
|
@library.save
|
142
|
-
@library = Library.find(@library.
|
143
|
-
expect(@library.books).to eq
|
142
|
+
@library = Library.find(@library.id)
|
143
|
+
expect(@library.books).to eq [@book, @book2]
|
144
144
|
end
|
145
145
|
|
146
146
|
|
@@ -151,22 +151,16 @@ describe ActiveFedora::Base do
|
|
151
151
|
@book.save
|
152
152
|
@book2.save
|
153
153
|
|
154
|
-
@library = Library.find(@library.
|
155
|
-
expect(@library.books).to eq
|
156
|
-
|
157
|
-
solr_resp = @library.books(:response_format=>:solr)
|
158
|
-
expect(solr_resp.size).to eq(2)
|
159
|
-
expect(solr_resp[0]['id']).to eq(@book.pid)
|
160
|
-
expect(solr_resp[1]['id']).to eq(@book2.pid)
|
161
|
-
|
162
|
-
end
|
163
|
-
|
154
|
+
@library = Library.find(@library.id)
|
155
|
+
expect(@library.books).to eq [@book, @book2]
|
164
156
|
|
157
|
+
solr_resp = @library.books(:response_format=>:solr)
|
158
|
+
expect(solr_resp.size).to eq 2
|
159
|
+
expect(solr_resp[0]['id']).to eq @book.id
|
160
|
+
expect(solr_resp[1]['id']).to eq @book2.id
|
165
161
|
|
166
|
-
after do
|
167
|
-
@book.delete
|
168
|
-
@book2.delete
|
169
162
|
end
|
163
|
+
|
170
164
|
end
|
171
165
|
|
172
166
|
describe "of belongs to" do
|
@@ -180,16 +174,12 @@ describe ActiveFedora::Base do
|
|
180
174
|
@book.library_id = nil
|
181
175
|
end
|
182
176
|
it "should be settable from the book side" do
|
183
|
-
@book.library_id = @library.
|
184
|
-
expect(@book.library).to eq
|
185
|
-
expect(@book.library.
|
186
|
-
@book.attributes= {:library_id =>
|
177
|
+
@book.library_id = @library.id
|
178
|
+
expect(@book.library).to eq @library
|
179
|
+
expect(@book.library.id).to eq @library.id
|
180
|
+
@book.attributes= {:library_id => nil }
|
187
181
|
expect(@book.library_id).to be_nil
|
188
182
|
end
|
189
|
-
after do
|
190
|
-
@library.delete
|
191
|
-
@book.delete
|
192
|
-
end
|
193
183
|
end
|
194
184
|
end
|
195
185
|
|
@@ -208,39 +198,45 @@ describe ActiveFedora::Base do
|
|
208
198
|
it "should have many books once it has been saved" do
|
209
199
|
@library.books << @book
|
210
200
|
|
211
|
-
expect(@book.library.
|
201
|
+
expect(@book.library.id).to eq @library.id
|
212
202
|
@library.books.reload
|
213
|
-
expect(@library.books).to eq
|
203
|
+
expect(@library.books).to eq [@book]
|
214
204
|
|
215
|
-
@library2 = Library.find(@library.
|
216
|
-
expect(@library2.books).to eq
|
205
|
+
@library2 = Library.find(@library.id)
|
206
|
+
expect(@library2.books).to eq [@book]
|
217
207
|
end
|
218
208
|
|
219
209
|
it "should have a count once it has been saved" do
|
220
|
-
@
|
210
|
+
@book_2 = Book.create
|
211
|
+
@library.books << @book << @book_2
|
221
212
|
@library.save
|
222
213
|
|
223
|
-
@library2 = Library.find(@library.
|
224
|
-
expect(@library2.books.size).to eq
|
214
|
+
@library2 = Library.find(@library.id)
|
215
|
+
expect(@library2.books.size).to eq 2
|
216
|
+
@book_2.reload
|
217
|
+
@book_2.delete
|
225
218
|
end
|
226
219
|
|
227
220
|
it "should respect the :class_name parameter" do
|
228
221
|
@book.author = @person
|
229
222
|
@book.save
|
230
|
-
|
231
|
-
expect(
|
223
|
+
new_book = Book.find(@book.id)
|
224
|
+
expect(new_book.author_id).to eq @person.id
|
225
|
+
expect(new_book.author).to be_kind_of Person
|
232
226
|
end
|
233
227
|
|
234
228
|
it "should respect multiple associations that share the same :property and respect associated class" do
|
235
229
|
@book.author = @person
|
236
230
|
@book.publisher = @publisher
|
237
231
|
@book.save
|
238
|
-
|
239
|
-
expect(Book.find(@book.id).publisher_id).to eq(@publisher.pid)
|
240
|
-
expect(Book.find(@book.id).publisher).to be_kind_of Publisher
|
241
232
|
|
242
|
-
|
243
|
-
|
233
|
+
new_book = Book.find(@book.id)
|
234
|
+
|
235
|
+
expect(new_book.publisher_id).to eq @publisher.id
|
236
|
+
expect(new_book.publisher).to be_kind_of Publisher
|
237
|
+
|
238
|
+
expect(new_book.author_id).to eq @person.id
|
239
|
+
expect(new_book.author).to be_kind_of Person
|
244
240
|
end
|
245
241
|
|
246
242
|
describe "when changing the belonger" do
|
@@ -250,22 +246,11 @@ describe ActiveFedora::Base do
|
|
250
246
|
@library2 = Library.create
|
251
247
|
end
|
252
248
|
it "should replace an existing instance" do
|
253
|
-
expect(@book.library_id).to eq
|
249
|
+
expect(@book.library_id).to eq @library.id
|
254
250
|
@book.library = @library2
|
255
251
|
@book.save
|
256
|
-
expect(Book.find(@book.id).library_id).to eq
|
252
|
+
expect(Book.find(@book.id).library_id).to eq @library2.id
|
257
253
|
end
|
258
|
-
after do
|
259
|
-
@library2.delete
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
|
264
|
-
after do
|
265
|
-
@library.delete
|
266
|
-
@book.delete
|
267
|
-
@person.delete
|
268
|
-
@publisher.delete
|
269
254
|
end
|
270
255
|
end
|
271
256
|
end
|
@@ -282,11 +267,11 @@ describe ActiveFedora::Base do
|
|
282
267
|
end
|
283
268
|
it "should set the association" do
|
284
269
|
@book.library = @library
|
285
|
-
expect(@book.library.
|
270
|
+
expect(@book.library.id).to eq @library.id
|
286
271
|
@book.save
|
287
272
|
|
288
273
|
|
289
|
-
expect(Book.find(@book.
|
274
|
+
expect(Book.find(@book.id).library.id).to eq@library.id
|
290
275
|
|
291
276
|
end
|
292
277
|
it "should clear the association" do
|
@@ -294,8 +279,7 @@ describe ActiveFedora::Base do
|
|
294
279
|
@book.library = nil
|
295
280
|
@book.save
|
296
281
|
|
297
|
-
expect(Book.find(@book.
|
298
|
-
|
282
|
+
expect(Book.find(@book.id).library).to be_nil
|
299
283
|
end
|
300
284
|
|
301
285
|
it "should replace the association" do
|
@@ -305,7 +289,7 @@ describe ActiveFedora::Base do
|
|
305
289
|
@book.save
|
306
290
|
@book.library = @library2
|
307
291
|
@book.save
|
308
|
-
expect(Book.find(@book.
|
292
|
+
expect(Book.find(@book.id).library.id).to eq @library2.id
|
309
293
|
|
310
294
|
end
|
311
295
|
|
@@ -315,13 +299,14 @@ describe ActiveFedora::Base do
|
|
315
299
|
|
316
300
|
@book.publisher = @publisher
|
317
301
|
@book.author = @author
|
318
|
-
@book.save
|
302
|
+
@book.save!
|
319
303
|
|
320
304
|
@book.publisher = @publisher2
|
321
|
-
@book.save
|
305
|
+
@book.save!
|
322
306
|
|
323
|
-
|
324
|
-
expect(
|
307
|
+
new_book = Book.find(@book.id)
|
308
|
+
expect(new_book.publisher.id).to eq @publisher2.id
|
309
|
+
expect(new_book.author.id).to eq @author.id
|
325
310
|
end
|
326
311
|
|
327
312
|
it "should only clear the matching class association" do
|
@@ -332,38 +317,30 @@ describe ActiveFedora::Base do
|
|
332
317
|
@book.author = nil
|
333
318
|
@book.save
|
334
319
|
|
335
|
-
expect(Book.find(@book.
|
336
|
-
expect(Book.find(@book.
|
320
|
+
expect(Book.find(@book.id).author).to be_nil
|
321
|
+
expect(Book.find(@book.id).publisher.id).to eq @publisher.id
|
337
322
|
end
|
338
323
|
|
339
324
|
it "should be able to be set by id" do
|
340
|
-
@book.library_id = @library.
|
341
|
-
expect(@book.library_id).to eq
|
342
|
-
expect(@book.library.
|
325
|
+
@book.library_id = @library.id
|
326
|
+
expect(@book.library_id).to eq @library.id
|
327
|
+
expect(@book.library.id).to eq @library.id
|
343
328
|
@book.save
|
344
|
-
expect(Book.find(@book.
|
329
|
+
expect(Book.find(@book.id).library_id).to eq @library.id
|
345
330
|
end
|
346
331
|
|
347
|
-
after do
|
348
|
-
@library.delete
|
349
|
-
@book.delete
|
350
|
-
@author.delete
|
351
|
-
@publisher.delete
|
352
|
-
@library2.delete if @library2
|
353
|
-
@publisher2.delete if @publisher2
|
354
|
-
end
|
355
332
|
end
|
356
333
|
end
|
357
334
|
|
358
335
|
describe "single direction habtm" do
|
359
336
|
before :all do
|
360
337
|
class Course < ActiveFedora::Base
|
361
|
-
has_and_belongs_to_many :textbooks, :
|
338
|
+
has_and_belongs_to_many :textbooks, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
362
339
|
end
|
363
340
|
class Textbook < ActiveFedora::Base
|
364
|
-
has_many :courses, :
|
341
|
+
has_many :courses, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
365
342
|
end
|
366
|
-
|
343
|
+
|
367
344
|
end
|
368
345
|
after :all do
|
369
346
|
Object.send(:remove_const, :Course)
|
@@ -380,17 +357,17 @@ describe ActiveFedora::Base do
|
|
380
357
|
end
|
381
358
|
|
382
359
|
it "should load the association stored in the parent" do
|
383
|
-
@reloaded_course = Course.find(@course.
|
384
|
-
expect(@reloaded_course.textbooks).to eq
|
360
|
+
@reloaded_course = Course.find(@course.id)
|
361
|
+
expect(@reloaded_course.textbooks).to eq [@t1, @t2]
|
385
362
|
end
|
386
363
|
|
387
364
|
it "should allow a parent to be deleted from the has_many association" do
|
388
|
-
@reloaded_course = Course.find(@course.
|
365
|
+
@reloaded_course = Course.find(@course.id)
|
389
366
|
@t1.courses.delete(@reloaded_course)
|
390
367
|
@reloaded_course.save
|
391
368
|
|
392
|
-
@reloaded_course = Course.find(@course.
|
393
|
-
expect(@reloaded_course.textbooks).to eq
|
369
|
+
@reloaded_course = Course.find(@course.id)
|
370
|
+
expect(@reloaded_course.textbooks).to eq [@t2]
|
394
371
|
end
|
395
372
|
|
396
373
|
it "should allow replacing the children" do
|
@@ -399,17 +376,17 @@ describe ActiveFedora::Base do
|
|
399
376
|
@course.textbooks = [@t3, @t4]
|
400
377
|
@course.save
|
401
378
|
|
402
|
-
expect(@course.reload.textbooks).to eq
|
379
|
+
expect(@course.reload.textbooks).to eq [@t3, @t4]
|
403
380
|
end
|
404
381
|
|
405
382
|
it "should allow a child to be deleted from the has_and_belongs_to_many association" do
|
406
|
-
@reloaded_course = Course.find(@course.
|
383
|
+
@reloaded_course = Course.find(@course.id)
|
407
384
|
@reloaded_course.textbooks.delete(@t1)
|
408
385
|
@reloaded_course.save
|
409
386
|
@t1.save
|
410
387
|
|
411
|
-
@reloaded_course = Course.find(@course.
|
412
|
-
expect(@reloaded_course.textbooks).to eq
|
388
|
+
@reloaded_course = Course.find(@course.id)
|
389
|
+
expect(@reloaded_course.textbooks).to eq [@t2]
|
413
390
|
end
|
414
391
|
end
|
415
392
|
end
|
@@ -418,24 +395,27 @@ describe ActiveFedora::Base do
|
|
418
395
|
describe "for habtm" do
|
419
396
|
before :all do
|
420
397
|
class LibraryBook < ActiveFedora::Base
|
421
|
-
has_and_belongs_to_many :pages, :
|
398
|
+
has_and_belongs_to_many :pages, predicate: ActiveFedora::RDF::RelsExt.isPartOf, after_remove: :after_hook, before_remove: :before_hook
|
422
399
|
|
423
400
|
def before_hook(m)
|
424
401
|
say_hi(m)
|
425
|
-
m.reload.library_books.count
|
402
|
+
before_count(m.reload.library_books.count)
|
426
403
|
end
|
427
404
|
|
428
405
|
def after_hook(m)
|
429
406
|
say_hi(m)
|
430
|
-
m.reload.library_books.count
|
407
|
+
after_count(m.reload.library_books.count)
|
408
|
+
end
|
409
|
+
|
410
|
+
def say_hi(var)
|
431
411
|
end
|
432
412
|
|
433
413
|
|
434
414
|
end
|
435
415
|
class Page < ActiveFedora::Base
|
436
|
-
has_many :library_books, :
|
416
|
+
has_many :library_books, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
437
417
|
end
|
438
|
-
|
418
|
+
|
439
419
|
end
|
440
420
|
after :all do
|
441
421
|
Object.send(:remove_const, :LibraryBook)
|
@@ -451,6 +431,8 @@ describe ActiveFedora::Base do
|
|
451
431
|
subject.save!
|
452
432
|
end
|
453
433
|
it "should save between the before and after hooks" do
|
434
|
+
expect(subject).to receive(:before_count).with(1)
|
435
|
+
expect(subject).to receive(:after_count).with(0)
|
454
436
|
expect(subject).to receive(:say_hi).with(@p2).twice
|
455
437
|
subject.pages.delete(@p2)
|
456
438
|
end
|
@@ -459,14 +441,14 @@ describe ActiveFedora::Base do
|
|
459
441
|
describe "for has_many" do
|
460
442
|
before :all do
|
461
443
|
class LibraryBook < ActiveFedora::Base
|
462
|
-
has_many :pages, :
|
444
|
+
has_many :pages, predicate: ActiveFedora::RDF::RelsExt.isPartOf, after_remove: :say_hi
|
463
445
|
|
464
446
|
end
|
465
447
|
class Page < ActiveFedora::Base
|
466
|
-
belongs_to :library_book, :
|
448
|
+
belongs_to :library_book, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
467
449
|
end
|
468
|
-
|
469
450
|
end
|
451
|
+
|
470
452
|
after :all do
|
471
453
|
Object.send(:remove_const, :LibraryBook)
|
472
454
|
Object.send(:remove_const, :Page)
|
@@ -490,7 +472,7 @@ describe ActiveFedora::Base do
|
|
490
472
|
describe "when an object doesn't have a property, and the class_name is predictable" do
|
491
473
|
before (:all) do
|
492
474
|
class Bauble < ActiveFedora::Base
|
493
|
-
belongs_to :media_object,
|
475
|
+
belongs_to :media_object, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
494
476
|
end
|
495
477
|
class MediaObject < ActiveFedora::Base
|
496
478
|
has_many :baubles
|
@@ -502,63 +484,68 @@ describe ActiveFedora::Base do
|
|
502
484
|
end
|
503
485
|
|
504
486
|
it "it should find the predicate" do
|
505
|
-
expect(MediaObject.new.association(:baubles).send(:find_predicate)).to eq
|
487
|
+
expect(MediaObject.new.association(:baubles).send(:find_predicate)).to eq 'http://fedora.info/definitions/v4/rels-ext#isPartOf'
|
506
488
|
end
|
507
489
|
end
|
508
490
|
|
509
491
|
describe "when an object doesn't have a property, but has a class_name" do
|
510
|
-
before
|
492
|
+
before :all do
|
511
493
|
class MasterFile < ActiveFedora::Base
|
512
|
-
belongs_to :media_object,
|
494
|
+
belongs_to :media_object, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
513
495
|
end
|
514
496
|
class MediaObject < ActiveFedora::Base
|
515
|
-
has_many :parts, :
|
497
|
+
has_many :parts, class_name: 'MasterFile'
|
516
498
|
end
|
517
499
|
end
|
500
|
+
|
518
501
|
after :all do
|
519
502
|
Object.send(:remove_const, :MasterFile)
|
520
503
|
Object.send(:remove_const, :MediaObject)
|
521
504
|
end
|
522
505
|
|
523
506
|
it "it should find the predicate" do
|
524
|
-
expect(MediaObject.new.association(:parts).send(:find_predicate)).to eq
|
507
|
+
expect(MediaObject.new.association(:parts).send(:find_predicate)).to eq 'http://fedora.info/definitions/v4/rels-ext#isPartOf'
|
525
508
|
end
|
526
509
|
end
|
527
510
|
|
528
511
|
describe "an object has an explicity property" do
|
529
|
-
before
|
512
|
+
before :all do
|
530
513
|
class Bauble < ActiveFedora::Base
|
531
|
-
belongs_to :media_object,
|
514
|
+
belongs_to :media_object, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
532
515
|
end
|
533
516
|
class MediaObject < ActiveFedora::Base
|
534
|
-
has_many :baubles,
|
517
|
+
has_many :baubles, predicate: ActiveFedora::RDF::RelsExt.hasEquivalent
|
535
518
|
end
|
536
519
|
end
|
520
|
+
|
537
521
|
after :all do
|
538
522
|
Object.send(:remove_const, :Bauble)
|
539
523
|
Object.send(:remove_const, :MediaObject)
|
540
524
|
end
|
541
525
|
|
542
526
|
it "it should find the predicate" do
|
543
|
-
expect(MediaObject.new.association(:baubles).send(:find_predicate)).to eq
|
527
|
+
expect(MediaObject.new.association(:baubles).send(:find_predicate)).to eq 'http://fedora.info/definitions/v4/rels-ext#hasEquivalent'
|
544
528
|
end
|
545
529
|
end
|
530
|
+
|
546
531
|
describe "an object doesn't have a property" do
|
547
|
-
before
|
532
|
+
before :all do
|
548
533
|
class Bauble < ActiveFedora::Base
|
549
|
-
belongs_to :media_object,
|
534
|
+
belongs_to :media_object, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
550
535
|
end
|
536
|
+
|
551
537
|
class MediaObject < ActiveFedora::Base
|
552
538
|
has_many :shoes
|
553
539
|
end
|
554
540
|
end
|
541
|
+
|
555
542
|
after :all do
|
556
543
|
Object.send(:remove_const, :Bauble)
|
557
544
|
Object.send(:remove_const, :MediaObject)
|
558
545
|
end
|
559
546
|
|
560
547
|
it "it should find the predicate" do
|
561
|
-
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, "No :
|
548
|
+
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, "No :predicate attribute was set or could be inferred for has_many :shoes on MediaObject"
|
562
549
|
end
|
563
550
|
end
|
564
551
|
end
|
@@ -567,19 +554,19 @@ describe ActiveFedora::Base do
|
|
567
554
|
describe "for habtm" do
|
568
555
|
before :all do
|
569
556
|
class Novel < ActiveFedora::Base
|
570
|
-
has_and_belongs_to_many :contents,
|
557
|
+
has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
571
558
|
end
|
572
559
|
class TextBook < ActiveFedora::Base
|
573
|
-
has_and_belongs_to_many :contents,
|
560
|
+
has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
574
561
|
end
|
575
562
|
class Text < ActiveFedora::Base
|
576
|
-
has_many :books,
|
563
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
577
564
|
end
|
578
565
|
class Image < ActiveFedora::Base
|
579
|
-
has_many :books,
|
566
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
|
580
567
|
end
|
581
|
-
|
582
568
|
end
|
569
|
+
|
583
570
|
after :all do
|
584
571
|
Object.send(:remove_const, :Novel)
|
585
572
|
Object.send(:remove_const, :TextBook)
|
@@ -602,19 +589,12 @@ describe ActiveFedora::Base do
|
|
602
589
|
book2.save!
|
603
590
|
|
604
591
|
expect(book1.reload.contents).to include(text1, image1)
|
605
|
-
expect(text1.reload.books).to eq
|
606
|
-
expect(image1.reload.books).to eq
|
592
|
+
expect(text1.reload.books).to eq [book1]
|
593
|
+
expect(image1.reload.books).to eq [book1]
|
607
594
|
|
608
595
|
expect(book2.reload.contents).to include(text2, image2)
|
609
|
-
expect(text2.reload.books).to eq
|
610
|
-
expect(image2.reload.books).to eq
|
611
|
-
end
|
612
|
-
|
613
|
-
it "should work when added via the has_many" do
|
614
|
-
text2.books << book2
|
615
|
-
book2.save
|
616
|
-
expect(book2.reload.contents).to eq([text2])
|
617
|
-
expect(text2.reload.books).to eq([book2])
|
596
|
+
expect(text2.reload.books).to eq [book2]
|
597
|
+
expect(image2.reload.books).to eq [book2]
|
618
598
|
end
|
619
599
|
end
|
620
600
|
end
|