active-fedora 6.7.8 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- 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/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- 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 +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- 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 +75 -69
- 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 +59 -59
- 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 +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
data/.travis.yml
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
sudo: false
|
|
1
2
|
language: ruby
|
|
2
3
|
rvm:
|
|
3
|
-
-
|
|
4
|
-
- 2.
|
|
5
|
-
|
|
6
|
-
gemfile:
|
|
7
|
-
- gemfiles/gemfile.rails3
|
|
8
|
-
- gemfiles/gemfile.rails4
|
|
4
|
+
- 2.2.5
|
|
5
|
+
- 2.3.1
|
|
9
6
|
|
|
10
7
|
notifications:
|
|
11
8
|
irc: "irc.freenode.org#projecthydra"
|
|
12
9
|
|
|
13
10
|
before_install:
|
|
14
11
|
- gem install bundler
|
|
12
|
+
|
|
13
|
+
jdk: oraclejdk8
|
data/Gemfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
source "
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
# Bundler will rely on active-fedora.gemspec for dependency information.
|
|
4
4
|
|
|
@@ -10,3 +10,5 @@ group :development, :test do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
gem 'jruby-openssl', :platform=> :jruby
|
|
13
|
+
|
|
14
|
+
gem 'activemodel', '~> 4.2'
|
data/Rakefile
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
require 'rake/clean'
|
|
2
2
|
require 'rubygems'
|
|
3
3
|
require 'bundler'
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'active-fedora'
|
|
6
6
|
|
|
7
7
|
Bundler::GemHelper.install_tasks
|
|
8
8
|
|
|
9
|
+
# peg to an expected-to-match version of jetty, if not specified
|
|
10
|
+
ZIP_URL ||= ENV['ZIP_URL'] || 'https://github.com/projecthydra/hydra-jetty/archive/v7.2.0.zip'
|
|
11
|
+
|
|
9
12
|
# load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
|
|
10
|
-
load
|
|
13
|
+
load 'lib/tasks/active_fedora_dev.rake' if defined?(Rake)
|
|
11
14
|
|
|
12
15
|
CLEAN.include %w[**/.DS_Store tmp *.log *.orig *.tmp **/*~]
|
|
13
16
|
|
|
14
|
-
task :ci
|
|
17
|
+
task :ci => ['jetty:clean', 'active_fedora:ci']
|
|
15
18
|
task :spec => ['active_fedora:rspec']
|
|
16
19
|
task :rcov => ['active_fedora:rcov']
|
|
17
20
|
|
|
18
|
-
|
|
19
21
|
task :default => [:ci]
|
data/active-fedora.gemspec
CHANGED
|
@@ -15,24 +15,24 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
s.required_ruby_version = '>= 1.9.3'
|
|
16
16
|
|
|
17
17
|
s.add_dependency('rsolr')
|
|
18
|
-
s.add_dependency('om', '~> 3.0
|
|
18
|
+
s.add_dependency('om', '~> 3.0')
|
|
19
19
|
s.add_dependency('nom-xml', '>=0.5.1')
|
|
20
|
-
s.add_dependency("activesupport", '>= 3
|
|
20
|
+
s.add_dependency("activesupport", '>= 3')
|
|
21
21
|
s.add_dependency("mediashelf-loggable")
|
|
22
|
-
s.add_dependency("rubydora", '~> 1.
|
|
23
|
-
s.add_dependency("rdf", '~> 1.1.1.1')
|
|
24
|
-
s.add_dependency("rdf-rdfxml", '1.
|
|
22
|
+
s.add_dependency("rubydora", '~>1.6', '>= 1.6.5')
|
|
23
|
+
s.add_dependency("rdf", '~> 1.1', '>= 1.1.1.1')
|
|
24
|
+
s.add_dependency("rdf-rdfxml", '~>1.1')
|
|
25
25
|
s.add_dependency("deprecation")
|
|
26
26
|
s.add_development_dependency("rdoc")
|
|
27
27
|
s.add_development_dependency("yard")
|
|
28
28
|
s.add_development_dependency("RedCloth") # for RDoc formatting
|
|
29
29
|
s.add_development_dependency("rake")
|
|
30
30
|
s.add_development_dependency("jettywrapper", ">=1.4.0")
|
|
31
|
-
s.add_development_dependency("rspec", "~> 2.
|
|
31
|
+
s.add_development_dependency("rspec", "~> 2.99")
|
|
32
32
|
s.add_development_dependency("equivalent-xml")
|
|
33
33
|
s.add_development_dependency("rest-client")
|
|
34
34
|
s.add_development_dependency("webmock")
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
s.files = `git ls-files`.split("\n")
|
|
37
37
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
38
38
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
@@ -43,4 +43,3 @@ Gem::Specification.new do |s|
|
|
|
43
43
|
s.require_paths = ["lib"]
|
|
44
44
|
|
|
45
45
|
end
|
|
46
|
-
|
|
@@ -1,80 +1,49 @@
|
|
|
1
|
-
require 'uri'
|
|
2
1
|
require 'rdf/rdfxml'
|
|
3
2
|
|
|
4
3
|
module ActiveFedora
|
|
5
4
|
# This class ensures that the RELS-EXT datastream is always serialized
|
|
6
5
|
# with an rdf:Description container for the properties
|
|
7
6
|
# the default behavior for RDF:RDFXML::Writer is to change that element if
|
|
8
|
-
# an rdf:type assertion is present; this is incompatible with Fedora
|
|
7
|
+
# an rdf:type assertion is present; this is incompatible with Fedora 3
|
|
9
8
|
class RDFXMLWriter < RDF::RDFXML::Writer
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
# Display a subject.
|
|
10
|
+
#
|
|
11
|
+
# If the Haml template contains an entry matching the subject's rdf:type URI, that entry will be used as the template for this subject and it's properties.
|
|
12
|
+
#
|
|
13
|
+
# @example Displays a subject as a Resource Definition:
|
|
14
|
+
# <div typeof="rdfs:Resource" about="http://example.com/resource">
|
|
15
|
+
# <h1 property="dc:title">label</h1>
|
|
16
|
+
# <ul>
|
|
17
|
+
# <li content="2009-04-30T06:15:51Z" property="dc:created">2009-04-30T06:15:51+00:00</li>
|
|
18
|
+
# </ul>
|
|
19
|
+
# </div>
|
|
20
|
+
#
|
|
21
|
+
# @param [RDF::Resource] subject
|
|
22
|
+
# @param [Hash{Symbol => Object}] options
|
|
23
|
+
# @option options [:li, nil] :element(:div)
|
|
24
|
+
# Serialize using <li> rather than template default element
|
|
25
|
+
# @option options [RDF::Resource] :rel (nil)
|
|
26
|
+
# Optional @rel property
|
|
27
|
+
# @return [Nokogiri::XML::Element, {Namespace}]
|
|
28
|
+
#
|
|
29
|
+
def subject(subject, options = {})
|
|
30
|
+
return if is_done?(subject)
|
|
20
31
|
|
|
21
|
-
parent_node.add_child(node) if node
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def force_about(subject, parent_node)
|
|
27
|
-
add_debug {"subject: #{subject.inspect}, force about"}
|
|
28
|
-
node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
|
|
29
|
-
if subject.is_a?(RDF::Node)
|
|
30
|
-
node["rdf:nodeID"] = subject.id
|
|
31
|
-
else
|
|
32
|
-
node["rdf:about"] = relativize(subject)
|
|
33
|
-
end
|
|
34
|
-
node
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def subject_not_done(subject, parent_node)
|
|
38
32
|
subject_done(subject)
|
|
39
|
-
properties = @graph.properties(subject)
|
|
40
|
-
add_debug {"subject: #{subject.inspect}, props: #{properties.inspect}"}
|
|
41
|
-
|
|
42
|
-
@graph.query(:subject => subject).each do |st|
|
|
43
|
-
raise RDF::WriterError, "Illegal use of predicate #{st.predicate.inspect}, not supported in RDF/XML" unless st.predicate.uri?
|
|
44
|
-
end
|
|
45
33
|
|
|
34
|
+
properties = properties_for_subject(subject)
|
|
35
|
+
typeof = type_of(properties[RDF.type.to_s], subject)
|
|
46
36
|
prop_list = order_properties(properties)
|
|
47
|
-
add_debug {"=> property order: #{prop_list.to_sentence}"}
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
prefixes[:rdf] = RDF.to_uri
|
|
38
|
+
add_debug {"subject: #{curie.inspect}, typeof: #{typeof.inspect}, props: #{prop_list.inspect}"}
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if subject.is_a?(RDF::Node)
|
|
55
|
-
# Only need nodeID if it's referenced elsewhere
|
|
56
|
-
if ref_count(subject) > (@depth == 0 ? 0 : 1)
|
|
57
|
-
node["rdf:nodeID"] = subject.id
|
|
58
|
-
else
|
|
59
|
-
node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{subject}")) if RDF::RDFXML::debug?
|
|
60
|
-
end
|
|
61
|
-
else
|
|
62
|
-
node["rdf:about"] = relativize(subject)
|
|
63
|
-
end
|
|
40
|
+
render_opts = {:typeof => typeof, :property_values => properties}.merge(options)
|
|
64
41
|
|
|
65
|
-
prop_list
|
|
66
|
-
prop_ref = RDF::URI.intern(prop)
|
|
67
|
-
|
|
68
|
-
properties[prop].each do |object|
|
|
69
|
-
raise RDF::WriterError, "Illegal use of object #{object.inspect}, not supported in RDF/XML" unless object.resource? || object.literal?
|
|
70
|
-
|
|
71
|
-
@depth += 1
|
|
72
|
-
predicate(prop_ref, object, node, properties[prop].length == 1)
|
|
73
|
-
@depth -= 1
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
node
|
|
42
|
+
render_subject_template(subject, prop_list, render_opts)
|
|
77
43
|
end
|
|
78
44
|
|
|
45
|
+
def type_of(type, subject)
|
|
46
|
+
""
|
|
47
|
+
end
|
|
79
48
|
end
|
|
80
49
|
end
|
data/spec/config_helper.rb
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
def mock_yaml(hash, path)
|
|
2
|
-
mock_file = double(path.split(
|
|
3
|
-
File.
|
|
4
|
-
File.
|
|
5
|
-
YAMLAdaptor.
|
|
2
|
+
mock_file = double(path.split('/')[-1])
|
|
3
|
+
allow(File).to receive(:exist?).with(path).and_return(true)
|
|
4
|
+
allow(File).to receive(:open).with(path).and_return(mock_file)
|
|
5
|
+
allow(YAMLAdaptor).to receive(:load).and_return(hash)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def default_predicate_mapping_file
|
|
9
|
-
File.expand_path(File.join(File.dirname(__FILE__),
|
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'predicate_mappings.yml'))
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def stub_rails(opts={})
|
|
13
|
-
Object.const_set(
|
|
14
|
-
Rails.send(:undef_method
|
|
15
|
-
Rails.send(:undef_method
|
|
16
|
-
opts.each { |k,v| Rails.send(:define_method,k){ return v } }
|
|
12
|
+
def stub_rails(opts = {})
|
|
13
|
+
Object.const_set('Rails', Class)
|
|
14
|
+
Rails.send(:undef_method, :env) if Rails.respond_to?(:env)
|
|
15
|
+
Rails.send(:undef_method, :root) if Rails.respond_to?(:root)
|
|
16
|
+
opts.each { |k, v| Rails.send(:define_method, k){ return v } }
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def unstub_rails
|
|
20
|
-
Object.send(:remove_const
|
|
20
|
+
Object.send(:remove_const, :Rails) if defined?(Rails)
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def setup_pretest_env
|
|
24
|
-
ENV['RAILS_ENV']='test'
|
|
25
|
-
ENV['environment']='test'
|
|
24
|
+
ENV['RAILS_ENV'] = 'test'
|
|
25
|
+
ENV['environment'] = 'test'
|
|
26
26
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::Base do
|
|
4
|
-
describe
|
|
4
|
+
describe 'use a URI as the property' do
|
|
5
5
|
before do
|
|
6
|
-
class Book < ActiveFedora::Base
|
|
7
|
-
belongs_to :author, :property=>RDF::DC.creator, :class_name=>'Person'
|
|
6
|
+
class Book < ActiveFedora::Base
|
|
7
|
+
belongs_to :author, :property => RDF::DC.creator, :class_name => 'Person'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
class Person < ActiveFedora::Base
|
|
@@ -19,24 +19,24 @@ describe ActiveFedora::Base do
|
|
|
19
19
|
let(:person) { Person.create}
|
|
20
20
|
let(:book) { Book.new(author: person) }
|
|
21
21
|
|
|
22
|
-
it
|
|
22
|
+
it 'should go' do
|
|
23
23
|
book.save
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
describe
|
|
28
|
+
describe 'complex example' do
|
|
29
29
|
before do
|
|
30
|
-
class Library < ActiveFedora::Base
|
|
31
|
-
has_many :books, :property
|
|
30
|
+
class Library < ActiveFedora::Base
|
|
31
|
+
has_many :books, :property => :has_constituent
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
class Book < ActiveFedora::Base
|
|
35
|
-
belongs_to :library, :property
|
|
36
|
-
belongs_to :author, :property
|
|
37
|
-
belongs_to :publisher, :property
|
|
38
|
-
has_and_belongs_to_many :topics, :property
|
|
39
|
-
has_and_belongs_to_many :collections, :property
|
|
34
|
+
class Book < ActiveFedora::Base
|
|
35
|
+
belongs_to :library, :property => :has_constituent
|
|
36
|
+
belongs_to :author, :property => :has_member, :class_name => 'Person'
|
|
37
|
+
belongs_to :publisher, :property => :has_member
|
|
38
|
+
has_and_belongs_to_many :topics, :property => :has_topic, :inverse_of => :is_topic_of
|
|
39
|
+
has_and_belongs_to_many :collections, :property => :is_member_of_collection
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
class SpecialInheritedBook < Book
|
|
@@ -51,8 +51,8 @@ describe ActiveFedora::Base do
|
|
|
51
51
|
class Collection < ActiveFedora::Base
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
class Topic < ActiveFedora::Base
|
|
55
|
-
has_and_belongs_to_many :books, :property
|
|
54
|
+
class Topic < ActiveFedora::Base
|
|
55
|
+
has_and_belongs_to_many :books, :property => :is_topic_of
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -65,8 +65,8 @@ describe ActiveFedora::Base do
|
|
|
65
65
|
Object.send(:remove_const, :SpecialInheritedBook)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
describe
|
|
69
|
-
describe
|
|
68
|
+
describe 'an unsaved instance' do
|
|
69
|
+
describe 'of has_many' do
|
|
70
70
|
before do
|
|
71
71
|
@library = Library.new()
|
|
72
72
|
@book = Book.new
|
|
@@ -75,85 +75,85 @@ describe ActiveFedora::Base do
|
|
|
75
75
|
@book2.save
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
it
|
|
78
|
+
it 'should build child' do
|
|
79
79
|
new_book = @library.books.build({})
|
|
80
|
-
new_book.
|
|
81
|
-
new_book.
|
|
82
|
-
new_book.library.
|
|
83
|
-
@library.books.
|
|
84
|
-
#TODO save the associated children too, requires something like ActiveRecord::AutosaveAssociation (ver 3.0.12)
|
|
80
|
+
expect(new_book).to be_new_record
|
|
81
|
+
expect(new_book).to be_kind_of Book
|
|
82
|
+
expect(new_book.library).to be_nil
|
|
83
|
+
expect(@library.books).to eq([new_book])
|
|
84
|
+
#TODO save the associated children too, requires something like ActiveRecord::AutosaveAssociation (ver 3.0.12)
|
|
85
85
|
#@library.save
|
|
86
86
|
#new_book.library.should == @library
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "should not create children if the parent isn't saved" do
|
|
90
|
-
|
|
90
|
+
expect {@library.books.create({})}.to raise_error ActiveFedora::RecordNotSaved, 'You cannot call create unless the parent is saved'
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
it
|
|
93
|
+
it 'should create children' do
|
|
94
94
|
@library.save!
|
|
95
95
|
new_book = @library.books.create({})
|
|
96
|
-
new_book.
|
|
97
|
-
new_book.
|
|
98
|
-
new_book.library.
|
|
96
|
+
expect(new_book).not_to be_new_record
|
|
97
|
+
expect(new_book).to be_kind_of Book
|
|
98
|
+
expect(new_book.library).to eq(@library)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
it
|
|
101
|
+
it 'should build parent' do
|
|
102
102
|
new_library = @book.build_library({})
|
|
103
|
-
new_library.
|
|
104
|
-
new_library.
|
|
105
|
-
@book.library.
|
|
103
|
+
expect(new_library).to be_new_record
|
|
104
|
+
expect(new_library).to be_kind_of Library
|
|
105
|
+
expect(@book.library).to eq(new_library)
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
it
|
|
108
|
+
it 'should create parent' do
|
|
109
109
|
new_library = @book.create_library({})
|
|
110
|
-
new_library.
|
|
111
|
-
new_library.
|
|
112
|
-
@book.library.
|
|
110
|
+
expect(new_library).not_to be_new_record
|
|
111
|
+
expect(new_library).to be_kind_of Library
|
|
112
|
+
expect(@book.library).to eq(new_library)
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
it
|
|
116
|
-
@library.new_record
|
|
115
|
+
it 'should let you shift onto the association' do
|
|
116
|
+
expect(@library.new_record?).to be_truthy
|
|
117
117
|
@library.books.size == 0
|
|
118
|
-
@library.books.
|
|
119
|
-
@library.book_ids.
|
|
118
|
+
expect(@library.books).to eq([])
|
|
119
|
+
expect(@library.book_ids).to eq([])
|
|
120
120
|
@library.books << @book
|
|
121
|
-
@library.books.
|
|
122
|
-
@library.book_ids.
|
|
121
|
+
expect(@library.books).to eq([@book])
|
|
122
|
+
expect(@library.book_ids).to eq([@book.pid])
|
|
123
123
|
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
it
|
|
126
|
+
it 'should let you set an array of objects' do
|
|
127
127
|
@library.books = [@book, @book2]
|
|
128
|
-
@library.books.
|
|
128
|
+
expect(@library.books).to eq([@book, @book2])
|
|
129
129
|
@library.save
|
|
130
130
|
|
|
131
131
|
@library.books = [@book]
|
|
132
|
-
@library.books.
|
|
133
|
-
|
|
132
|
+
expect(@library.books).to eq([@book])
|
|
133
|
+
|
|
134
134
|
end
|
|
135
|
-
it
|
|
135
|
+
it 'should let you set an array of object ids' do
|
|
136
136
|
@library.book_ids = [@book.pid, @book2.pid]
|
|
137
|
-
@library.books.
|
|
137
|
+
expect(@library.books).to eq([@book, @book2])
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
it
|
|
140
|
+
it 'setter should wipe out previously saved relations' do
|
|
141
141
|
@library.book_ids = [@book.pid, @book2.pid]
|
|
142
142
|
@library.book_ids = [@book2.pid]
|
|
143
|
-
@library.books.
|
|
144
|
-
|
|
143
|
+
expect(@library.books).to eq([@book2])
|
|
144
|
+
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
it
|
|
147
|
+
it 'saving the parent should save the relationships on the children' do
|
|
148
148
|
@library.save
|
|
149
149
|
@library.books = [@book, @book2]
|
|
150
150
|
@library.save
|
|
151
151
|
@library = Library.find(@library.pid)
|
|
152
|
-
@library.books.
|
|
152
|
+
expect(@library.books).to eq([@book, @book2])
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
|
|
156
|
-
it
|
|
156
|
+
it 'should let you lookup an array of objects with solr' do
|
|
157
157
|
@library.save
|
|
158
158
|
@book.library = @library
|
|
159
159
|
@book2.library = @library
|
|
@@ -161,13 +161,13 @@ describe ActiveFedora::Base do
|
|
|
161
161
|
@book2.save
|
|
162
162
|
|
|
163
163
|
@library = Library.find(@library.pid)
|
|
164
|
-
@library.books.
|
|
165
|
-
|
|
166
|
-
solr_resp = @library.books(:response_format
|
|
167
|
-
solr_resp.size.
|
|
168
|
-
solr_resp[0]['id'].
|
|
169
|
-
solr_resp[1]['id'].
|
|
170
|
-
|
|
164
|
+
expect(@library.books).to eq([@book, @book2])
|
|
165
|
+
|
|
166
|
+
solr_resp = @library.books(:response_format => :solr)
|
|
167
|
+
expect(solr_resp.size).to eq(2)
|
|
168
|
+
expect(solr_resp[0]['id']).to eq(@book.pid)
|
|
169
|
+
expect(solr_resp[1]['id']).to eq(@book2.pid)
|
|
170
|
+
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
|
|
@@ -178,7 +178,7 @@ describe ActiveFedora::Base do
|
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
describe
|
|
181
|
+
describe 'of belongs to' do
|
|
182
182
|
before do
|
|
183
183
|
@library = Library.new()
|
|
184
184
|
@library.save
|
|
@@ -188,12 +188,12 @@ describe ActiveFedora::Base do
|
|
|
188
188
|
it "shouldn't do anything if you set a nil id" do
|
|
189
189
|
@book.library_id = nil
|
|
190
190
|
end
|
|
191
|
-
it
|
|
191
|
+
it 'should be settable from the book side' do
|
|
192
192
|
@book.library_id = @library.pid
|
|
193
|
-
@book.library.
|
|
194
|
-
@book.library.pid.
|
|
195
|
-
@book.attributes= {:library_id =>
|
|
196
|
-
@book.library_id.
|
|
193
|
+
expect(@book.library).to eq(@library)
|
|
194
|
+
expect(@book.library.pid).to eq(@library.pid)
|
|
195
|
+
@book.attributes = {:library_id => ''}
|
|
196
|
+
expect(@book.library_id).to be_nil
|
|
197
197
|
end
|
|
198
198
|
after do
|
|
199
199
|
@library.delete
|
|
@@ -201,43 +201,43 @@ describe ActiveFedora::Base do
|
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
-
describe
|
|
204
|
+
describe 'of has_many_and_belongs_to' do
|
|
205
205
|
before do
|
|
206
206
|
@topic1 = Topic.create
|
|
207
207
|
@topic2 = Topic.create
|
|
208
208
|
@book = Book.create
|
|
209
209
|
@special_book = SpecialInheritedBook.create
|
|
210
210
|
end
|
|
211
|
-
it
|
|
211
|
+
it 'habtm should set and remove relationships bidirectionally' do
|
|
212
212
|
@book.topics << @topic1
|
|
213
|
-
@book.topics.
|
|
214
|
-
@topic1.books.
|
|
215
|
-
@topic1.reload.books.
|
|
213
|
+
expect(@book.topics).to eq([@topic1])
|
|
214
|
+
expect(@topic1.books).to eq([@book])
|
|
215
|
+
expect(@topic1.reload.books).to eq([@book])
|
|
216
216
|
|
|
217
217
|
@book.topics.delete(@topic1)
|
|
218
218
|
#@topic1.books.delete(@book)
|
|
219
|
-
@book.topics.
|
|
220
|
-
@topic1.books.
|
|
219
|
+
expect(@book.topics).to eq([])
|
|
220
|
+
expect(@topic1.books).to eq([])
|
|
221
221
|
end
|
|
222
|
-
it
|
|
222
|
+
it 'Should allow for more than 10 items' do
|
|
223
223
|
|
|
224
224
|
(0..11).each do
|
|
225
225
|
@book.topics << Topic.create
|
|
226
226
|
end
|
|
227
227
|
@book.save
|
|
228
|
-
@book.topics.count.
|
|
228
|
+
expect(@book.topics.count).to eq(12)
|
|
229
229
|
book2 = Book.find(@book.pid)
|
|
230
|
-
book2.topics.count.
|
|
230
|
+
expect(book2.topics.count).to eq(12)
|
|
231
231
|
end
|
|
232
232
|
|
|
233
|
-
it
|
|
233
|
+
it 'Should find inherited objects along with base objects' do
|
|
234
234
|
@book.topics << @topic1
|
|
235
235
|
@special_book.topics << @topic1
|
|
236
|
-
@topic1.books.
|
|
237
|
-
@topic1.reload.books.
|
|
236
|
+
expect(@topic1.books).to eq([@book, @special_book])
|
|
237
|
+
expect(@topic1.reload.books).to eq([@book, @special_book])
|
|
238
238
|
end
|
|
239
239
|
|
|
240
|
-
it
|
|
240
|
+
it 'Should cast found books to the correct cmodel' do
|
|
241
241
|
@topic1.books[0].class == Book
|
|
242
242
|
@topic1.books[1].class == SpecialInheritedBook
|
|
243
243
|
end
|
|
@@ -251,11 +251,11 @@ describe ActiveFedora::Base do
|
|
|
251
251
|
end
|
|
252
252
|
end
|
|
253
253
|
|
|
254
|
-
|
|
255
254
|
|
|
256
255
|
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
|
|
257
|
+
describe 'a saved instance' do
|
|
258
|
+
describe 'of belongs_to' do
|
|
259
259
|
before do
|
|
260
260
|
@library = Library.new()
|
|
261
261
|
@library.save()
|
|
@@ -266,19 +266,19 @@ describe ActiveFedora::Base do
|
|
|
266
266
|
@publisher = Publisher.new
|
|
267
267
|
@publisher.save
|
|
268
268
|
end
|
|
269
|
-
it
|
|
269
|
+
it 'should have many books once it has been saved' do
|
|
270
270
|
@library.books << @book
|
|
271
271
|
|
|
272
|
-
@book.library.pid.
|
|
272
|
+
expect(@book.library.pid).to eq(@library.pid)
|
|
273
273
|
@library.books.reload
|
|
274
|
-
@library.books.
|
|
274
|
+
expect(@library.books).to eq([@book])
|
|
275
275
|
|
|
276
276
|
@library2 = Library.find(@library.pid)
|
|
277
|
-
@library2.books.
|
|
277
|
+
expect(@library2.books).to eq([@book])
|
|
278
278
|
end
|
|
279
279
|
|
|
280
|
-
it
|
|
281
|
-
@library.books << @book << Book.create
|
|
280
|
+
it 'should have a count once it has been saved' do
|
|
281
|
+
@library.books << @book << Book.create
|
|
282
282
|
@library.save
|
|
283
283
|
|
|
284
284
|
# @book.library.pid.should == @library.pid
|
|
@@ -286,46 +286,46 @@ describe ActiveFedora::Base do
|
|
|
286
286
|
# @library.books.should == [@book]
|
|
287
287
|
|
|
288
288
|
@library2 = Library.find(@library.pid)
|
|
289
|
-
@library2.books.size.
|
|
289
|
+
expect(@library2.books.size).to eq(2)
|
|
290
290
|
end
|
|
291
291
|
|
|
292
|
-
it
|
|
292
|
+
it 'should respect the :class_name parameter' do
|
|
293
293
|
@book.author = @person
|
|
294
294
|
@book.save
|
|
295
|
-
Book.find(@book.id).author_id.
|
|
296
|
-
Book.find(@book.id).author.send(:find_target).
|
|
295
|
+
expect(Book.find(@book.id).author_id).to eq(@person.pid)
|
|
296
|
+
expect(Book.find(@book.id).author.send(:find_target)).to be_kind_of Person
|
|
297
297
|
end
|
|
298
298
|
|
|
299
|
-
it
|
|
299
|
+
it 'should respect multiple associations that share the same :property and respect associated class' do
|
|
300
300
|
@book.author = @person
|
|
301
301
|
@book.publisher = @publisher
|
|
302
302
|
@book.save
|
|
303
|
-
|
|
304
|
-
Book.find(@book.id).publisher_id.should == @publisher.pid
|
|
305
|
-
Book.find(@book.id).publisher.send(:find_target).should be_kind_of Publisher
|
|
306
303
|
|
|
307
|
-
Book.find(@book.id).
|
|
308
|
-
Book.find(@book.id).
|
|
304
|
+
expect(Book.find(@book.id).publisher_id).to eq(@publisher.pid)
|
|
305
|
+
expect(Book.find(@book.id).publisher.send(:find_target)).to be_kind_of Publisher
|
|
306
|
+
|
|
307
|
+
expect(Book.find(@book.id).author_id).to eq(@person.pid)
|
|
308
|
+
expect(Book.find(@book.id).author.send(:find_target)).to be_kind_of Person
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
-
describe
|
|
311
|
+
describe 'when changing the belonger' do
|
|
312
312
|
before do
|
|
313
313
|
@book.library = @library
|
|
314
314
|
@book.save
|
|
315
315
|
@library2 = Library.create
|
|
316
316
|
end
|
|
317
|
-
it
|
|
318
|
-
@book.library_id.
|
|
317
|
+
it 'should replace an existing instance' do
|
|
318
|
+
expect(@book.library_id).to eq(@library.id)
|
|
319
319
|
@book.library = @library2
|
|
320
320
|
@book.save
|
|
321
|
-
Book.find(@book.id).library_id.
|
|
321
|
+
expect(Book.find(@book.id).library_id).to eq(@library2.id)
|
|
322
322
|
end
|
|
323
323
|
after do
|
|
324
324
|
@library2.delete
|
|
325
325
|
end
|
|
326
326
|
end
|
|
327
327
|
|
|
328
|
-
describe
|
|
328
|
+
describe 'when dealing with inherited objects' do
|
|
329
329
|
before do
|
|
330
330
|
@library2 = Library.create
|
|
331
331
|
@special_book = SpecialInheritedBook.create
|
|
@@ -336,7 +336,7 @@ describe ActiveFedora::Base do
|
|
|
336
336
|
@special_book.save
|
|
337
337
|
end
|
|
338
338
|
|
|
339
|
-
it
|
|
339
|
+
it 'should cast to the most specific class for the association' do
|
|
340
340
|
@library2.books[0].class == Book
|
|
341
341
|
@library2.books[1].class == SpecialInheritedBook
|
|
342
342
|
end
|
|
@@ -354,41 +354,41 @@ describe ActiveFedora::Base do
|
|
|
354
354
|
@publisher.delete
|
|
355
355
|
end
|
|
356
356
|
end
|
|
357
|
-
describe
|
|
357
|
+
describe 'of has_many_and_belongs_to' do
|
|
358
358
|
before do
|
|
359
359
|
@book = Book.create
|
|
360
360
|
end
|
|
361
361
|
after do
|
|
362
362
|
@book.delete
|
|
363
363
|
end
|
|
364
|
-
describe
|
|
364
|
+
describe 'when invese is specified' do
|
|
365
365
|
before do
|
|
366
366
|
@topic1 = Topic.create
|
|
367
367
|
@topic2 = Topic.create
|
|
368
368
|
end
|
|
369
|
-
it
|
|
369
|
+
it 'should set relationships bidirectionally' do
|
|
370
370
|
@book.topics << @topic1
|
|
371
|
-
@book.topics.
|
|
372
|
-
@book.relationships(:has_topic).
|
|
373
|
-
@topic1.relationships(:has_topic).
|
|
374
|
-
@topic1.relationships(:is_topic_of).
|
|
375
|
-
Topic.find(@topic1.pid).books.
|
|
371
|
+
expect(@book.topics).to eq([@topic1])
|
|
372
|
+
expect(@book.relationships(:has_topic)).to eq([@topic1.internal_uri])
|
|
373
|
+
expect(@topic1.relationships(:has_topic)).to eq([])
|
|
374
|
+
expect(@topic1.relationships(:is_topic_of)).to eq([@book.internal_uri])
|
|
375
|
+
expect(Topic.find(@topic1.pid).books).to eq([@book]) #Can't have saved it because @book isn't saved yet.
|
|
376
376
|
end
|
|
377
|
-
it
|
|
377
|
+
it 'should save new child objects' do
|
|
378
378
|
@book.topics << Topic.new
|
|
379
|
-
@book.topics.first.pid.
|
|
379
|
+
expect(@book.topics.first.pid).not_to be_nil
|
|
380
380
|
end
|
|
381
|
-
it
|
|
381
|
+
it 'should clear out the old associtions' do
|
|
382
382
|
@book.topics = [@topic1]
|
|
383
383
|
@book.topics = [@topic2]
|
|
384
|
-
@book.topic_ids.
|
|
384
|
+
expect(@book.topic_ids).to eq([@topic2.pid])
|
|
385
385
|
end
|
|
386
386
|
after do
|
|
387
387
|
@topic1.delete
|
|
388
388
|
@topic2.delete
|
|
389
389
|
end
|
|
390
390
|
end
|
|
391
|
-
describe
|
|
391
|
+
describe 'when invese is not specified' do
|
|
392
392
|
before do
|
|
393
393
|
@c = Collection.create
|
|
394
394
|
@book.collections << @c
|
|
@@ -397,22 +397,22 @@ describe ActiveFedora::Base do
|
|
|
397
397
|
after do
|
|
398
398
|
@c.delete
|
|
399
399
|
end
|
|
400
|
-
it
|
|
401
|
-
@book.relationships(:is_member_of_collection).
|
|
402
|
-
@book.collections.
|
|
400
|
+
it 'should have a collection' do
|
|
401
|
+
expect(@book.relationships(:is_member_of_collection)).to eq([@c.internal_uri])
|
|
402
|
+
expect(@book.collections).to eq([@c])
|
|
403
403
|
end
|
|
404
|
-
it
|
|
405
|
-
@c.relationships(:is_member_of_collection).
|
|
404
|
+
it 'habtm should not set foreign relationships if :inverse_of is not specified' do
|
|
405
|
+
expect(@c.relationships(:is_member_of_collection)).to eq([])
|
|
406
406
|
end
|
|
407
|
-
it
|
|
407
|
+
it 'should load the collections' do
|
|
408
408
|
reloaded = Book.find(@book.pid)
|
|
409
|
-
reloaded.collections.
|
|
409
|
+
expect(reloaded.collections).to eq([@c])
|
|
410
410
|
end
|
|
411
411
|
end
|
|
412
412
|
end
|
|
413
413
|
end
|
|
414
414
|
|
|
415
|
-
describe
|
|
415
|
+
describe 'setting belongs_to' do
|
|
416
416
|
before do
|
|
417
417
|
@library = Library.new()
|
|
418
418
|
@library.save()
|
|
@@ -422,51 +422,51 @@ describe ActiveFedora::Base do
|
|
|
422
422
|
@publisher = Publisher.new
|
|
423
423
|
@publisher.save
|
|
424
424
|
end
|
|
425
|
-
it
|
|
425
|
+
it 'should set the association' do
|
|
426
426
|
@book.library = @library
|
|
427
|
-
@book.library.pid.
|
|
427
|
+
expect(@book.library.pid).to eq(@library.pid)
|
|
428
428
|
@book.save
|
|
429
429
|
|
|
430
430
|
|
|
431
|
-
Book.find(@book.pid).library.pid.
|
|
432
|
-
|
|
431
|
+
expect(Book.find(@book.pid).library.pid).to eq(@library.pid)
|
|
432
|
+
|
|
433
433
|
end
|
|
434
|
-
it
|
|
434
|
+
it 'should clear the association' do
|
|
435
435
|
@book.library = @library
|
|
436
436
|
@book.library = nil
|
|
437
437
|
@book.save
|
|
438
438
|
|
|
439
|
-
Book.find(@book.pid).library.
|
|
440
|
-
|
|
439
|
+
expect(Book.find(@book.pid).library).to be_nil
|
|
440
|
+
|
|
441
441
|
end
|
|
442
442
|
|
|
443
|
-
it
|
|
443
|
+
it 'should replace the association' do
|
|
444
444
|
@library2 = Library.new
|
|
445
445
|
@library2.save
|
|
446
446
|
@book.library = @library
|
|
447
447
|
@book.save
|
|
448
448
|
@book.library = @library2
|
|
449
449
|
@book.save
|
|
450
|
-
Book.find(@book.pid).library.pid.
|
|
450
|
+
expect(Book.find(@book.pid).library.pid).to eq(@library2.pid)
|
|
451
451
|
|
|
452
452
|
end
|
|
453
453
|
|
|
454
|
-
it
|
|
454
|
+
it 'should only replace the matching class association' do
|
|
455
455
|
@publisher2 = Publisher.new
|
|
456
456
|
@publisher2.save
|
|
457
457
|
|
|
458
458
|
@book.publisher = @publisher
|
|
459
|
-
@book.author = @author
|
|
460
|
-
@book.save
|
|
459
|
+
@book.author = @author
|
|
460
|
+
@book.save
|
|
461
461
|
|
|
462
462
|
@book.publisher = @publisher2
|
|
463
463
|
@book.save
|
|
464
464
|
|
|
465
|
-
Book.find(@book.pid).publisher.pid.
|
|
466
|
-
Book.find(@book.pid).author.pid.
|
|
465
|
+
expect(Book.find(@book.pid).publisher.pid).to eq(@publisher2.pid)
|
|
466
|
+
expect(Book.find(@book.pid).author.pid).to eq(@author.pid)
|
|
467
467
|
end
|
|
468
468
|
|
|
469
|
-
it
|
|
469
|
+
it 'should only clear the matching class association' do
|
|
470
470
|
@book.publisher = @publisher
|
|
471
471
|
@book.author = @author
|
|
472
472
|
@book.save
|
|
@@ -474,16 +474,16 @@ describe ActiveFedora::Base do
|
|
|
474
474
|
@book.author = nil
|
|
475
475
|
@book.save
|
|
476
476
|
|
|
477
|
-
Book.find(@book.pid).author.
|
|
478
|
-
Book.find(@book.pid).publisher.pid.
|
|
477
|
+
expect(Book.find(@book.pid).author).to be_nil
|
|
478
|
+
expect(Book.find(@book.pid).publisher.pid).to eq(@publisher.pid)
|
|
479
479
|
end
|
|
480
480
|
|
|
481
|
-
it
|
|
481
|
+
it 'should be able to be set by id' do
|
|
482
482
|
@book.library_id = @library.pid
|
|
483
|
-
@book.library_id.
|
|
484
|
-
@book.library.pid.
|
|
483
|
+
expect(@book.library_id).to eq(@library.pid)
|
|
484
|
+
expect(@book.library.pid).to eq(@library.pid)
|
|
485
485
|
@book.save
|
|
486
|
-
Book.find(@book.pid).library_id.
|
|
486
|
+
expect(Book.find(@book.pid).library_id).to eq(@library.pid)
|
|
487
487
|
end
|
|
488
488
|
|
|
489
489
|
after do
|
|
@@ -497,10 +497,10 @@ describe ActiveFedora::Base do
|
|
|
497
497
|
end
|
|
498
498
|
end
|
|
499
499
|
|
|
500
|
-
describe
|
|
500
|
+
describe 'belongs_to when class_name is ActiveFedora::Base' do
|
|
501
501
|
before :all do
|
|
502
502
|
class Textbook < ActiveFedora::Base
|
|
503
|
-
belongs_to :container, :property
|
|
503
|
+
belongs_to :container, :property => :is_part_of, :class_name => 'ActiveFedora::Base'
|
|
504
504
|
end
|
|
505
505
|
class Shelf < ActiveFedora::Base; end
|
|
506
506
|
end
|
|
@@ -517,28 +517,28 @@ describe ActiveFedora::Base do
|
|
|
517
517
|
let(:shelf) { Shelf.create}
|
|
518
518
|
subject { Textbook.new }
|
|
519
519
|
|
|
520
|
-
it
|
|
521
|
-
Deprecation.
|
|
520
|
+
it 'Should not raise a deprecation message' do
|
|
521
|
+
expect(Deprecation).not_to receive(:warn) # a deprecation in 6.6.0 that's going away in 7.0.0
|
|
522
522
|
subject.container_id = shelf.id
|
|
523
523
|
end
|
|
524
524
|
end
|
|
525
525
|
|
|
526
|
-
describe
|
|
526
|
+
describe 'single direction habtm' do
|
|
527
527
|
before :all do
|
|
528
528
|
class Course < ActiveFedora::Base
|
|
529
|
-
has_and_belongs_to_many :textbooks, :property
|
|
529
|
+
has_and_belongs_to_many :textbooks, :property => :is_part_of
|
|
530
530
|
end
|
|
531
531
|
class Textbook < ActiveFedora::Base
|
|
532
|
-
has_many :courses, :property
|
|
532
|
+
has_many :courses, :property => :is_part_of
|
|
533
533
|
end
|
|
534
|
-
|
|
534
|
+
|
|
535
535
|
end
|
|
536
536
|
after :all do
|
|
537
537
|
Object.send(:remove_const, :Course)
|
|
538
538
|
Object.send(:remove_const, :Textbook)
|
|
539
539
|
end
|
|
540
540
|
|
|
541
|
-
describe
|
|
541
|
+
describe 'with a parent that has two children' do
|
|
542
542
|
before do
|
|
543
543
|
@course = Course.create
|
|
544
544
|
@t1 = Textbook.create()
|
|
@@ -547,46 +547,46 @@ describe ActiveFedora::Base do
|
|
|
547
547
|
@course.save
|
|
548
548
|
end
|
|
549
549
|
|
|
550
|
-
it
|
|
550
|
+
it 'should load the association stored in the parent' do
|
|
551
551
|
@reloaded_course = Course.find(@course.pid)
|
|
552
|
-
@reloaded_course.textbooks.
|
|
552
|
+
expect(@reloaded_course.textbooks).to eq([@t1, @t2])
|
|
553
553
|
end
|
|
554
554
|
|
|
555
|
-
it
|
|
555
|
+
it 'should allow a parent to be deleted from the has_many association' do
|
|
556
556
|
@reloaded_course = Course.find(@course.pid)
|
|
557
557
|
@t1.courses.delete(@reloaded_course)
|
|
558
558
|
@reloaded_course.save
|
|
559
559
|
|
|
560
560
|
@reloaded_course = Course.find(@course.pid)
|
|
561
|
-
@reloaded_course.textbooks.
|
|
561
|
+
expect(@reloaded_course.textbooks).to eq([@t2])
|
|
562
562
|
end
|
|
563
563
|
|
|
564
|
-
it
|
|
564
|
+
it 'should allow replacing the children' do
|
|
565
565
|
@t3 = Textbook.create()
|
|
566
566
|
@t4 = Textbook.create()
|
|
567
567
|
@course.textbooks = [@t3, @t4]
|
|
568
568
|
@course.save
|
|
569
569
|
|
|
570
|
-
@course.reload.textbooks.
|
|
570
|
+
expect(@course.reload.textbooks).to eq([@t3, @t4])
|
|
571
571
|
end
|
|
572
572
|
|
|
573
|
-
it
|
|
573
|
+
it 'should allow a child to be deleted from the has_and_belongs_to_many association' do
|
|
574
574
|
@reloaded_course = Course.find(@course.pid)
|
|
575
575
|
@reloaded_course.textbooks.delete(@t1)
|
|
576
576
|
@reloaded_course.save
|
|
577
577
|
@t1.save
|
|
578
578
|
|
|
579
579
|
@reloaded_course = Course.find(@course.pid)
|
|
580
|
-
@reloaded_course.textbooks.
|
|
580
|
+
expect(@reloaded_course.textbooks).to eq([@t2])
|
|
581
581
|
end
|
|
582
582
|
end
|
|
583
583
|
end
|
|
584
584
|
|
|
585
|
-
describe
|
|
586
|
-
describe
|
|
585
|
+
describe 'association hooks' do
|
|
586
|
+
describe 'for habtm' do
|
|
587
587
|
before :all do
|
|
588
588
|
class LibraryBook < ActiveFedora::Base
|
|
589
|
-
has_and_belongs_to_many :pages, :property
|
|
589
|
+
has_and_belongs_to_many :pages, :property => :is_part_of, after_remove: :after_hook, before_remove: :before_hook
|
|
590
590
|
|
|
591
591
|
def before_hook(m)
|
|
592
592
|
say_hi(m)
|
|
@@ -601,16 +601,16 @@ describe ActiveFedora::Base do
|
|
|
601
601
|
|
|
602
602
|
end
|
|
603
603
|
class Page < ActiveFedora::Base
|
|
604
|
-
has_many :library_books, :property
|
|
604
|
+
has_many :library_books, :property => :is_part_of
|
|
605
605
|
end
|
|
606
|
-
|
|
606
|
+
|
|
607
607
|
end
|
|
608
608
|
after :all do
|
|
609
609
|
Object.send(:remove_const, :LibraryBook)
|
|
610
610
|
Object.send(:remove_const, :Page)
|
|
611
611
|
end
|
|
612
612
|
|
|
613
|
-
describe
|
|
613
|
+
describe 'removing association' do
|
|
614
614
|
subject {LibraryBook.create}
|
|
615
615
|
before do
|
|
616
616
|
@p1 = Page.create
|
|
@@ -618,36 +618,36 @@ describe ActiveFedora::Base do
|
|
|
618
618
|
subject.pages << @p1 << @p2
|
|
619
619
|
subject.save!
|
|
620
620
|
end
|
|
621
|
-
it
|
|
622
|
-
subject.
|
|
621
|
+
it 'should save between the before and after hooks' do
|
|
622
|
+
expect(subject).to receive(:say_hi).with(@p2).twice
|
|
623
623
|
subject.pages.delete(@p2)
|
|
624
624
|
end
|
|
625
625
|
end
|
|
626
626
|
end
|
|
627
|
-
describe
|
|
627
|
+
describe 'for has_many' do
|
|
628
628
|
before :all do
|
|
629
629
|
class LibraryBook < ActiveFedora::Base
|
|
630
|
-
has_many :pages, :property
|
|
630
|
+
has_many :pages, :property => :is_part_of, after_remove: :say_hi
|
|
631
631
|
|
|
632
632
|
end
|
|
633
633
|
class Page < ActiveFedora::Base
|
|
634
|
-
belongs_to :library_book, :property
|
|
634
|
+
belongs_to :library_book, :property => :is_part_of
|
|
635
635
|
end
|
|
636
|
-
|
|
636
|
+
|
|
637
637
|
end
|
|
638
638
|
after :all do
|
|
639
639
|
Object.send(:remove_const, :LibraryBook)
|
|
640
640
|
Object.send(:remove_const, :Page)
|
|
641
641
|
end
|
|
642
642
|
|
|
643
|
-
describe
|
|
643
|
+
describe 'removing association' do
|
|
644
644
|
subject {LibraryBook.new}
|
|
645
645
|
before do
|
|
646
646
|
@p1 = subject.pages.build
|
|
647
647
|
@p2 = subject.pages.build
|
|
648
648
|
end
|
|
649
|
-
it
|
|
650
|
-
subject.
|
|
649
|
+
it 'should run the hooks' do
|
|
650
|
+
expect(subject).to receive(:say_hi).with(@p2)
|
|
651
651
|
subject.pages.delete(@p2)
|
|
652
652
|
end
|
|
653
653
|
end
|
|
@@ -655,13 +655,13 @@ describe ActiveFedora::Base do
|
|
|
655
655
|
end
|
|
656
656
|
|
|
657
657
|
|
|
658
|
-
describe
|
|
658
|
+
describe 'when a object is deleted' do
|
|
659
659
|
before (:all) do
|
|
660
660
|
class MasterFile < ActiveFedora::Base
|
|
661
|
-
belongs_to :media_object, :property
|
|
661
|
+
belongs_to :media_object, :property => :is_part_of
|
|
662
662
|
end
|
|
663
663
|
class MediaObject < ActiveFedora::Base
|
|
664
|
-
has_many :parts, :class_name=>'MasterFile', :property
|
|
664
|
+
has_many :parts, :class_name => 'MasterFile', :property => :is_part_of
|
|
665
665
|
end
|
|
666
666
|
end
|
|
667
667
|
|
|
@@ -678,14 +678,14 @@ describe ActiveFedora::Base do
|
|
|
678
678
|
Object.send(:remove_const, :MediaObject)
|
|
679
679
|
end
|
|
680
680
|
|
|
681
|
-
it
|
|
681
|
+
it 'should also remove the relationships that point at that object' do
|
|
682
682
|
@media.delete
|
|
683
683
|
@master = MasterFile.find(@master.pid)
|
|
684
|
-
@master.relationships(:is_part_of).
|
|
684
|
+
expect(@master.relationships(:is_part_of)).to eq([])
|
|
685
685
|
end
|
|
686
686
|
end
|
|
687
687
|
|
|
688
|
-
describe
|
|
688
|
+
describe 'has_many' do
|
|
689
689
|
describe "when an object doesn't have a property, and the class_name is predictable" do
|
|
690
690
|
before (:all) do
|
|
691
691
|
class Bauble < ActiveFedora::Base
|
|
@@ -700,8 +700,8 @@ describe ActiveFedora::Base do
|
|
|
700
700
|
Object.send(:remove_const, :MediaObject)
|
|
701
701
|
end
|
|
702
702
|
|
|
703
|
-
it
|
|
704
|
-
MediaObject.new.baubles.send(:find_predicate).
|
|
703
|
+
it 'it should find the predicate' do
|
|
704
|
+
expect(MediaObject.new.baubles.send(:find_predicate)).to eq(:is_part_of)
|
|
705
705
|
end
|
|
706
706
|
end
|
|
707
707
|
|
|
@@ -711,7 +711,7 @@ describe ActiveFedora::Base do
|
|
|
711
711
|
belongs_to :media_object, property: :is_part_of
|
|
712
712
|
end
|
|
713
713
|
class MediaObject < ActiveFedora::Base
|
|
714
|
-
has_many :parts, :class_name=>'MasterFile'
|
|
714
|
+
has_many :parts, :class_name => 'MasterFile'
|
|
715
715
|
end
|
|
716
716
|
end
|
|
717
717
|
after :all do
|
|
@@ -719,12 +719,12 @@ describe ActiveFedora::Base do
|
|
|
719
719
|
Object.send(:remove_const, :MediaObject)
|
|
720
720
|
end
|
|
721
721
|
|
|
722
|
-
it
|
|
723
|
-
MediaObject.new.parts.send(:find_predicate).
|
|
722
|
+
it 'it should find the predicate' do
|
|
723
|
+
expect(MediaObject.new.parts.send(:find_predicate)).to eq(:is_part_of)
|
|
724
724
|
end
|
|
725
725
|
end
|
|
726
726
|
|
|
727
|
-
describe
|
|
727
|
+
describe 'an object has an explicity property' do
|
|
728
728
|
before (:all) do
|
|
729
729
|
class Bauble < ActiveFedora::Base
|
|
730
730
|
belongs_to :media_object, property: :is_part_of
|
|
@@ -738,8 +738,8 @@ describe ActiveFedora::Base do
|
|
|
738
738
|
Object.send(:remove_const, :MediaObject)
|
|
739
739
|
end
|
|
740
740
|
|
|
741
|
-
it
|
|
742
|
-
MediaObject.new.baubles.send(:find_predicate).
|
|
741
|
+
it 'it should find the predicate' do
|
|
742
|
+
expect(MediaObject.new.baubles.send(:find_predicate)).to eq(:has_baubles)
|
|
743
743
|
end
|
|
744
744
|
end
|
|
745
745
|
describe "an object doesn't have a property" do
|
|
@@ -756,14 +756,14 @@ describe ActiveFedora::Base do
|
|
|
756
756
|
Object.send(:remove_const, :MediaObject)
|
|
757
757
|
end
|
|
758
758
|
|
|
759
|
-
it
|
|
760
|
-
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError,
|
|
759
|
+
it 'it should find the predicate' do
|
|
760
|
+
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, 'No :property attribute was set or could be inferred for has_many :shoes on MediaObject'
|
|
761
761
|
end
|
|
762
762
|
end
|
|
763
763
|
end
|
|
764
764
|
|
|
765
|
-
describe
|
|
766
|
-
describe
|
|
765
|
+
describe 'casting when the class name is ActiveFedora::Base' do
|
|
766
|
+
describe 'for habtm' do
|
|
767
767
|
before :all do
|
|
768
768
|
class Novel < ActiveFedora::Base
|
|
769
769
|
has_and_belongs_to_many :contents, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
|
@@ -777,7 +777,7 @@ describe ActiveFedora::Base do
|
|
|
777
777
|
class Image < ActiveFedora::Base
|
|
778
778
|
has_many :books, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
|
779
779
|
end
|
|
780
|
-
|
|
780
|
+
|
|
781
781
|
end
|
|
782
782
|
after :all do
|
|
783
783
|
Object.send(:remove_const, :Novel)
|
|
@@ -786,7 +786,7 @@ describe ActiveFedora::Base do
|
|
|
786
786
|
Object.send(:remove_const, :Image)
|
|
787
787
|
end
|
|
788
788
|
|
|
789
|
-
describe
|
|
789
|
+
describe 'saving between the before and after hooks' do
|
|
790
790
|
let(:text1) { Text.create}
|
|
791
791
|
let(:image1) { Image.create}
|
|
792
792
|
let(:text2) { Text.create}
|
|
@@ -794,33 +794,33 @@ describe ActiveFedora::Base do
|
|
|
794
794
|
let(:book1) { TextBook.create}
|
|
795
795
|
let(:book2) { Novel.create}
|
|
796
796
|
|
|
797
|
-
it
|
|
797
|
+
it 'should work when added via the has_and_belongs_to_many' do
|
|
798
798
|
book1.contents = [text1, image1]
|
|
799
799
|
book1.save!
|
|
800
800
|
book2.contents = [text2, image2]
|
|
801
801
|
book2.save!
|
|
802
802
|
|
|
803
|
-
book1.reload.contents.
|
|
804
|
-
text1.reload.books.
|
|
805
|
-
image1.reload.books.
|
|
803
|
+
expect(book1.reload.contents).to include(text1, image1)
|
|
804
|
+
expect(text1.reload.books).to eq([book1])
|
|
805
|
+
expect(image1.reload.books).to eq([book1])
|
|
806
806
|
|
|
807
|
-
book2.reload.contents.
|
|
808
|
-
text2.reload.books.
|
|
809
|
-
image2.reload.books.
|
|
807
|
+
expect(book2.reload.contents).to include(text2, image2)
|
|
808
|
+
expect(text2.reload.books).to eq([book2])
|
|
809
|
+
expect(image2.reload.books).to eq([book2])
|
|
810
810
|
end
|
|
811
811
|
|
|
812
|
-
it
|
|
812
|
+
it 'should work when added via the has_many' do
|
|
813
813
|
text2.books << book2
|
|
814
814
|
book2.save
|
|
815
|
-
book2.reload.contents.
|
|
816
|
-
text2.reload.books.
|
|
815
|
+
expect(book2.reload.contents).to eq([text2])
|
|
816
|
+
expect(text2.reload.books).to eq([book2])
|
|
817
817
|
end
|
|
818
818
|
end
|
|
819
819
|
end
|
|
820
820
|
end
|
|
821
821
|
|
|
822
|
-
describe
|
|
823
|
-
describe
|
|
822
|
+
describe 'casting inheritance additional test cases' do
|
|
823
|
+
describe 'for habtm' do
|
|
824
824
|
before :all do
|
|
825
825
|
class SimpleObject < ActiveFedora::Base
|
|
826
826
|
belongs_to :simple_collection, property: :is_part_of, class_name: 'SimpleCollection'
|
|
@@ -846,7 +846,7 @@ describe ActiveFedora::Base do
|
|
|
846
846
|
Object.send(:remove_const, :ComplexCollection)
|
|
847
847
|
end
|
|
848
848
|
|
|
849
|
-
describe
|
|
849
|
+
describe 'saving between the before and after hooks' do
|
|
850
850
|
before do
|
|
851
851
|
@simple_collection = SimpleCollection.create
|
|
852
852
|
@complex_collection = ComplexCollection.create
|
|
@@ -869,32 +869,32 @@ describe ActiveFedora::Base do
|
|
|
869
869
|
end
|
|
870
870
|
|
|
871
871
|
|
|
872
|
-
it
|
|
873
|
-
@complex_object.simple_collection.
|
|
874
|
-
@complex_object.complex_collection.
|
|
872
|
+
it 'casted association methods should work and return the most complex class' do
|
|
873
|
+
expect(@complex_object.simple_collection).to be_instance_of SimpleCollection
|
|
874
|
+
expect(@complex_object.complex_collection).to be_instance_of ComplexCollection
|
|
875
875
|
|
|
876
|
-
@simple_object.simple_collection.
|
|
877
|
-
@simple_object.complex_collection.
|
|
878
|
-
@simple_object_second.simple_collection.
|
|
879
|
-
@simple_object_second.complex_collection.
|
|
876
|
+
expect(@simple_object.simple_collection).to be_instance_of SimpleCollection
|
|
877
|
+
expect(@simple_object.complex_collection).to be_instance_of ComplexCollection
|
|
878
|
+
expect(@simple_object_second.simple_collection).to be_instance_of SimpleCollection
|
|
879
|
+
expect(@simple_object_second.complex_collection).to be_nil
|
|
880
880
|
|
|
881
|
-
@complex_collection.objects[0].
|
|
882
|
-
@complex_collection.objects[1].
|
|
881
|
+
expect(@complex_collection.objects[0]).to be_instance_of SimpleObject
|
|
882
|
+
expect(@complex_collection.objects[1]).to be_instance_of ComplexObject
|
|
883
883
|
|
|
884
|
-
@simple_collection.objects[0].
|
|
885
|
-
@simple_collection.objects[1].
|
|
886
|
-
@simple_collection.objects[2].
|
|
884
|
+
expect(@simple_collection.objects[0]).to be_instance_of SimpleObject
|
|
885
|
+
expect(@simple_collection.objects[1]).to be_instance_of SimpleObject
|
|
886
|
+
expect(@simple_collection.objects[2]).to be_instance_of ComplexObject
|
|
887
887
|
|
|
888
888
|
end
|
|
889
889
|
|
|
890
|
-
it
|
|
891
|
-
@complex_collection.complex_objects.length.
|
|
892
|
-
@complex_collection.complex_objects[0].
|
|
893
|
-
@complex_collection.complex_objects[1].
|
|
890
|
+
it 'specified ending relationships should ignore classes not specified' do
|
|
891
|
+
expect(@complex_collection.complex_objects.length).to eq(1)
|
|
892
|
+
expect(@complex_collection.complex_objects[0]).to be_instance_of ComplexObject
|
|
893
|
+
expect(@complex_collection.complex_objects[1]).to be_nil
|
|
894
894
|
|
|
895
|
-
@simple_collection.complex_objects.length.
|
|
896
|
-
@simple_collection.complex_objects[0].
|
|
897
|
-
@simple_collection.complex_objects[1].
|
|
895
|
+
expect(@simple_collection.complex_objects.length).to eq(1)
|
|
896
|
+
expect(@simple_collection.complex_objects[0]).to be_instance_of ComplexObject
|
|
897
|
+
expect(@simple_collection.complex_objects[1]).to be_nil
|
|
898
898
|
|
|
899
899
|
end
|
|
900
900
|
|