active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +68 -74
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +48 -107
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -48,7 +48,7 @@ module ActiveFedora
|
|
48
48
|
def self.reify_solr_result(hit, opts = {})
|
49
49
|
klass = class_from_solr_document(hit)
|
50
50
|
if opts[:load_from_solr]
|
51
|
-
klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
|
51
|
+
klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID], hit)
|
52
52
|
else
|
53
53
|
klass.find(hit[SOLR_DOCUMENT_ID], cast: true)
|
54
54
|
end
|
@@ -26,10 +26,11 @@ module ActiveFedora
|
|
26
26
|
@pid = pid
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def new_record?
|
30
30
|
true
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
|
+
alias :new? :new_record?
|
33
34
|
|
34
35
|
### Change this into a real digital object
|
35
36
|
def save
|
@@ -49,8 +50,9 @@ module ActiveFedora
|
|
49
50
|
self.original_class.assign_pid(self)
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
def delete
|
54
|
+
#nop
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require "active-fedora"
|
2
2
|
require "active_support" # This is just to load ActiveSupport::CoreExtensions::String::Inflections
|
3
|
+
|
4
|
+
ZIP_FILE = 'https://github.com/projecthydra/hydra-jetty/archive/v5.2.0.zip'
|
5
|
+
|
3
6
|
namespace :repo do
|
4
7
|
|
5
8
|
desc "Delete and re-import the object identified by pid"
|
@@ -1,10 +1,10 @@
|
|
1
1
|
APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
|
2
2
|
|
3
3
|
require 'jettywrapper'
|
4
|
+
JETTY_ZIP_BASENAME = 'master'
|
5
|
+
Jettywrapper.url = "https://github.com/projecthydra/hydra-jetty/archive/#{JETTY_ZIP_BASENAME}.zip"
|
4
6
|
|
5
7
|
namespace :active_fedora do
|
6
|
-
require 'active-fedora'
|
7
|
-
|
8
8
|
# Use yard to build docs
|
9
9
|
begin
|
10
10
|
require 'yard'
|
@@ -14,8 +14,8 @@ namespace :active_fedora do
|
|
14
14
|
|
15
15
|
YARD::Rake::YardocTask.new(:doc) do |yt|
|
16
16
|
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
|
17
|
-
[ '-', File.join(project_root, 'README.
|
18
|
-
yt.options = ['--output-dir', doc_destination, '--readme', 'README.
|
17
|
+
[ '-', File.join(project_root, 'README.md')]
|
18
|
+
yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
|
19
19
|
end
|
20
20
|
rescue LoadError
|
21
21
|
desc "Generate YARD Documentation"
|
@@ -24,10 +24,11 @@ namespace :active_fedora do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
require 'rspec/core/rake_task'
|
27
|
+
require 'rspec/core/rake_task'
|
28
28
|
RSpec::Core::RakeTask.new(:rspec) do |spec|
|
29
29
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
30
30
|
spec.pattern += FileList['spec/*_spec.rb']
|
31
|
+
spec.rspec_opts = ['--backtrace'] if ENV['CI']
|
31
32
|
end
|
32
33
|
|
33
34
|
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
data/spec/config_helper.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
def mock_yaml(hash, path)
|
2
|
-
mock_file = double(path.split(
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
mock_file = double(path.split("/")[-1])
|
3
|
+
File.stub(:exist?).with(path).and_return(true)
|
4
|
+
File.stub(:open).with(path).and_return(mock_file)
|
5
|
+
YAMLAdaptor.stub(: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,
|
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']
|
25
|
-
ENV['environment']
|
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
|
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,27 +19,22 @@ 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 => :has_topic, :inverse_of => :is_topic_of
|
39
|
-
has_and_belongs_to_many :collections, :property => :is_member_of_collection
|
40
|
-
end
|
41
|
-
|
42
|
-
class SpecialInheritedBook < Book
|
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
|
43
38
|
end
|
44
39
|
|
45
40
|
class Person < ActiveFedora::Base
|
@@ -47,26 +42,17 @@ describe ActiveFedora::Base do
|
|
47
42
|
|
48
43
|
class Publisher < ActiveFedora::Base
|
49
44
|
end
|
50
|
-
|
51
|
-
class Collection < ActiveFedora::Base
|
52
|
-
end
|
53
|
-
|
54
|
-
class Topic < ActiveFedora::Base
|
55
|
-
has_and_belongs_to_many :books, :property => :is_topic_of
|
56
|
-
end
|
57
45
|
end
|
58
46
|
|
59
47
|
after do
|
60
48
|
Object.send(:remove_const, :Library)
|
61
49
|
Object.send(:remove_const, :Book)
|
62
50
|
Object.send(:remove_const, :Person)
|
63
|
-
Object.send(:remove_const, :
|
64
|
-
Object.send(:remove_const, :Topic)
|
65
|
-
Object.send(:remove_const, :SpecialInheritedBook)
|
51
|
+
Object.send(:remove_const, :Publisher)
|
66
52
|
end
|
67
53
|
|
68
|
-
describe
|
69
|
-
describe
|
54
|
+
describe "an unsaved instance" do
|
55
|
+
describe "of has_many" do
|
70
56
|
before do
|
71
57
|
@library = Library.new()
|
72
58
|
@book = Book.new
|
@@ -75,85 +61,90 @@ describe ActiveFedora::Base do
|
|
75
61
|
@book2.save
|
76
62
|
end
|
77
63
|
|
78
|
-
it
|
64
|
+
it "should build child" do
|
79
65
|
new_book = @library.books.build({})
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
66
|
+
new_book.should be_new_record
|
67
|
+
new_book.should be_kind_of Book
|
68
|
+
new_book.library.should be_kind_of Library
|
69
|
+
@library.books.should == [new_book]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should make a new child" do
|
73
|
+
new_book = @library.books.new
|
74
|
+
new_book.should be_new_record
|
75
|
+
new_book.should be_kind_of Book
|
76
|
+
new_book.library.should be_kind_of Library
|
77
|
+
@library.books.should == [new_book]
|
87
78
|
end
|
88
79
|
|
89
80
|
it "should not create children if the parent isn't saved" do
|
90
|
-
|
81
|
+
lambda {@library.books.create({})}.should raise_error ActiveFedora::RecordNotSaved, "You cannot call create unless the parent is saved"
|
91
82
|
end
|
92
83
|
|
93
|
-
it
|
84
|
+
it "should create children" do
|
94
85
|
@library.save!
|
95
86
|
new_book = @library.books.create({})
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
new_book.should_not be_new_record
|
88
|
+
new_book.should be_kind_of Book
|
89
|
+
new_book.library.should == @library
|
99
90
|
end
|
100
91
|
|
101
|
-
it
|
92
|
+
it "should build parent" do
|
102
93
|
new_library = @book.build_library({})
|
103
|
-
|
104
|
-
|
105
|
-
|
94
|
+
new_library.should be_new_record
|
95
|
+
new_library.should be_kind_of Library
|
96
|
+
@book.library.should == new_library
|
106
97
|
end
|
107
98
|
|
108
|
-
it
|
99
|
+
it "should create parent" do
|
109
100
|
new_library = @book.create_library({})
|
110
|
-
|
111
|
-
|
112
|
-
|
101
|
+
new_library.should_not be_new_record
|
102
|
+
new_library.should be_kind_of Library
|
103
|
+
@book.library.should == new_library
|
113
104
|
end
|
114
105
|
|
115
|
-
it
|
116
|
-
|
106
|
+
it "should let you shift onto the association" do
|
107
|
+
@library.new_record?.should be_true
|
117
108
|
@library.books.size == 0
|
118
|
-
|
119
|
-
|
109
|
+
@library.books.should == []
|
110
|
+
@library.book_ids.should ==[]
|
120
111
|
@library.books << @book
|
121
|
-
|
122
|
-
|
112
|
+
@library.books.should == [@book]
|
113
|
+
@library.book_ids.should ==[@book.pid]
|
123
114
|
|
124
115
|
end
|
125
116
|
|
126
|
-
it
|
117
|
+
it "should let you set an array of objects" do
|
127
118
|
@library.books = [@book, @book2]
|
128
|
-
|
119
|
+
@library.books.should == [@book, @book2]
|
129
120
|
@library.save
|
130
121
|
|
131
122
|
@library.books = [@book]
|
132
|
-
|
133
|
-
|
123
|
+
@library.books.should == [@book]
|
124
|
+
|
134
125
|
end
|
135
|
-
it
|
126
|
+
it "should let you set an array of object ids" do
|
136
127
|
@library.book_ids = [@book.pid, @book2.pid]
|
137
|
-
|
128
|
+
@library.books.should == [@book, @book2]
|
138
129
|
end
|
139
130
|
|
140
|
-
it
|
131
|
+
it "setter should wipe out previously saved relations" do
|
141
132
|
@library.book_ids = [@book.pid, @book2.pid]
|
142
133
|
@library.book_ids = [@book2.pid]
|
143
|
-
|
144
|
-
|
134
|
+
@library.books.should == [@book2]
|
135
|
+
|
145
136
|
end
|
146
137
|
|
147
|
-
it
|
138
|
+
it "saving the parent should save the relationships on the children" do
|
148
139
|
@library.save
|
149
140
|
@library.books = [@book, @book2]
|
150
141
|
@library.save
|
151
142
|
@library = Library.find(@library.pid)
|
152
|
-
|
143
|
+
@library.books.should == [@book, @book2]
|
153
144
|
end
|
154
145
|
|
155
146
|
|
156
|
-
it
|
147
|
+
it "should let you lookup an array of objects with solr" do
|
157
148
|
@library.save
|
158
149
|
@book.library = @library
|
159
150
|
@book2.library = @library
|
@@ -161,13 +152,13 @@ describe ActiveFedora::Base do
|
|
161
152
|
@book2.save
|
162
153
|
|
163
154
|
@library = Library.find(@library.pid)
|
164
|
-
|
165
|
-
|
166
|
-
solr_resp = @library.books(:response_format
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
155
|
+
@library.books.should == [@book, @book2]
|
156
|
+
|
157
|
+
solr_resp = @library.books(:response_format=>:solr)
|
158
|
+
solr_resp.size.should == 2
|
159
|
+
solr_resp[0]['id'].should == @book.pid
|
160
|
+
solr_resp[1]['id'].should == @book2.pid
|
161
|
+
|
171
162
|
end
|
172
163
|
|
173
164
|
|
@@ -178,7 +169,7 @@ describe ActiveFedora::Base do
|
|
178
169
|
end
|
179
170
|
end
|
180
171
|
|
181
|
-
describe
|
172
|
+
describe "of belongs to" do
|
182
173
|
before do
|
183
174
|
@library = Library.new()
|
184
175
|
@library.save
|
@@ -188,74 +179,22 @@ describe ActiveFedora::Base do
|
|
188
179
|
it "shouldn't do anything if you set a nil id" do
|
189
180
|
@book.library_id = nil
|
190
181
|
end
|
191
|
-
it
|
182
|
+
it "should be settable from the book side" do
|
192
183
|
@book.library_id = @library.pid
|
193
|
-
|
194
|
-
|
195
|
-
@book.attributes
|
196
|
-
|
184
|
+
@book.library.should == @library
|
185
|
+
@book.library.pid.should == @library.pid
|
186
|
+
@book.attributes= {:library_id => ""}
|
187
|
+
@book.library_id.should be_nil
|
197
188
|
end
|
198
189
|
after do
|
199
190
|
@library.delete
|
200
191
|
@book.delete
|
201
192
|
end
|
202
193
|
end
|
203
|
-
|
204
|
-
describe 'of has_many_and_belongs_to' do
|
205
|
-
before do
|
206
|
-
@topic1 = Topic.create
|
207
|
-
@topic2 = Topic.create
|
208
|
-
@book = Book.create
|
209
|
-
@special_book = SpecialInheritedBook.create
|
210
|
-
end
|
211
|
-
it 'habtm should set and remove relationships bidirectionally' do
|
212
|
-
@book.topics << @topic1
|
213
|
-
expect(@book.topics).to eq([@topic1])
|
214
|
-
expect(@topic1.books).to eq([@book])
|
215
|
-
expect(@topic1.reload.books).to eq([@book])
|
216
|
-
|
217
|
-
@book.topics.delete(@topic1)
|
218
|
-
#@topic1.books.delete(@book)
|
219
|
-
expect(@book.topics).to eq([])
|
220
|
-
expect(@topic1.books).to eq([])
|
221
|
-
end
|
222
|
-
it 'Should allow for more than 10 items' do
|
223
|
-
|
224
|
-
(0..11).each do
|
225
|
-
@book.topics << Topic.create
|
226
|
-
end
|
227
|
-
@book.save
|
228
|
-
expect(@book.topics.count).to eq(12)
|
229
|
-
book2 = Book.find(@book.pid)
|
230
|
-
expect(book2.topics.count).to eq(12)
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'Should find inherited objects along with base objects' do
|
234
|
-
@book.topics << @topic1
|
235
|
-
@special_book.topics << @topic1
|
236
|
-
expect(@topic1.books).to eq([@book, @special_book])
|
237
|
-
expect(@topic1.reload.books).to eq([@book, @special_book])
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'Should cast found books to the correct cmodel' do
|
241
|
-
@topic1.books[0].class == Book
|
242
|
-
@topic1.books[1].class == SpecialInheritedBook
|
243
|
-
end
|
244
|
-
|
245
|
-
after do
|
246
|
-
@topic1.delete
|
247
|
-
@topic2.delete
|
248
|
-
@book.delete
|
249
|
-
@special_book.delete
|
250
|
-
end
|
251
|
-
end
|
252
194
|
end
|
253
195
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
describe 'a saved instance' do
|
258
|
-
describe 'of belongs_to' do
|
196
|
+
describe "a saved instance" do
|
197
|
+
describe "of belongs_to" do
|
259
198
|
before do
|
260
199
|
@library = Library.new()
|
261
200
|
@library.save()
|
@@ -266,86 +205,61 @@ describe ActiveFedora::Base do
|
|
266
205
|
@publisher = Publisher.new
|
267
206
|
@publisher.save
|
268
207
|
end
|
269
|
-
it
|
208
|
+
it "should have many books once it has been saved" do
|
270
209
|
@library.books << @book
|
271
210
|
|
272
|
-
|
211
|
+
@book.library.pid.should == @library.pid
|
273
212
|
@library.books.reload
|
274
|
-
|
213
|
+
@library.books.should == [@book]
|
275
214
|
|
276
215
|
@library2 = Library.find(@library.pid)
|
277
|
-
|
216
|
+
@library2.books.should == [@book]
|
278
217
|
end
|
279
218
|
|
280
|
-
it
|
281
|
-
@library.books << @book << Book.create
|
219
|
+
it "should have a count once it has been saved" do
|
220
|
+
@library.books << @book << Book.create
|
282
221
|
@library.save
|
283
222
|
|
284
|
-
# @book.library.pid.should == @library.pid
|
285
|
-
# @library.books.reload
|
286
|
-
# @library.books.should == [@book]
|
287
|
-
|
288
223
|
@library2 = Library.find(@library.pid)
|
289
|
-
|
224
|
+
@library2.books.size.should == 2
|
290
225
|
end
|
291
226
|
|
292
|
-
it
|
227
|
+
it "should respect the :class_name parameter" do
|
293
228
|
@book.author = @person
|
294
229
|
@book.save
|
295
|
-
|
296
|
-
|
230
|
+
Book.find(@book.id).author_id.should == @person.pid
|
231
|
+
Book.find(@book.id).author.should be_kind_of Person
|
297
232
|
end
|
298
233
|
|
299
|
-
it
|
234
|
+
it "should respect multiple associations that share the same :property and respect associated class" do
|
300
235
|
@book.author = @person
|
301
236
|
@book.publisher = @publisher
|
302
237
|
@book.save
|
238
|
+
|
239
|
+
Book.find(@book.id).publisher_id.should == @publisher.pid
|
240
|
+
Book.find(@book.id).publisher.should be_kind_of Publisher
|
303
241
|
|
304
|
-
|
305
|
-
|
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
|
242
|
+
Book.find(@book.id).author_id.should == @person.pid
|
243
|
+
Book.find(@book.id).author.should be_kind_of Person
|
309
244
|
end
|
310
245
|
|
311
|
-
describe
|
246
|
+
describe "when changing the belonger" do
|
312
247
|
before do
|
313
248
|
@book.library = @library
|
314
249
|
@book.save
|
315
250
|
@library2 = Library.create
|
316
251
|
end
|
317
|
-
it
|
318
|
-
|
252
|
+
it "should replace an existing instance" do
|
253
|
+
@book.library_id.should == @library.id
|
319
254
|
@book.library = @library2
|
320
255
|
@book.save
|
321
|
-
|
256
|
+
Book.find(@book.id).library_id.should == @library2.id
|
322
257
|
end
|
323
258
|
after do
|
324
259
|
@library2.delete
|
325
260
|
end
|
326
261
|
end
|
327
262
|
|
328
|
-
describe 'when dealing with inherited objects' do
|
329
|
-
before do
|
330
|
-
@library2 = Library.create
|
331
|
-
@special_book = SpecialInheritedBook.create
|
332
|
-
|
333
|
-
@book.library = @library2
|
334
|
-
@book.save
|
335
|
-
@special_book.library = @library2
|
336
|
-
@special_book.save
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'should cast to the most specific class for the association' do
|
340
|
-
@library2.books[0].class == Book
|
341
|
-
@library2.books[1].class == SpecialInheritedBook
|
342
|
-
end
|
343
|
-
|
344
|
-
after do
|
345
|
-
@library2.delete
|
346
|
-
@special_book.delete
|
347
|
-
end
|
348
|
-
end
|
349
263
|
|
350
264
|
after do
|
351
265
|
@library.delete
|
@@ -354,65 +268,9 @@ describe ActiveFedora::Base do
|
|
354
268
|
@publisher.delete
|
355
269
|
end
|
356
270
|
end
|
357
|
-
describe 'of has_many_and_belongs_to' do
|
358
|
-
before do
|
359
|
-
@book = Book.create
|
360
|
-
end
|
361
|
-
after do
|
362
|
-
@book.delete
|
363
|
-
end
|
364
|
-
describe 'when invese is specified' do
|
365
|
-
before do
|
366
|
-
@topic1 = Topic.create
|
367
|
-
@topic2 = Topic.create
|
368
|
-
end
|
369
|
-
it 'should set relationships bidirectionally' do
|
370
|
-
@book.topics << @topic1
|
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
|
-
end
|
377
|
-
it 'should save new child objects' do
|
378
|
-
@book.topics << Topic.new
|
379
|
-
expect(@book.topics.first.pid).not_to be_nil
|
380
|
-
end
|
381
|
-
it 'should clear out the old associtions' do
|
382
|
-
@book.topics = [@topic1]
|
383
|
-
@book.topics = [@topic2]
|
384
|
-
expect(@book.topic_ids).to eq([@topic2.pid])
|
385
|
-
end
|
386
|
-
after do
|
387
|
-
@topic1.delete
|
388
|
-
@topic2.delete
|
389
|
-
end
|
390
|
-
end
|
391
|
-
describe 'when invese is not specified' do
|
392
|
-
before do
|
393
|
-
@c = Collection.create
|
394
|
-
@book.collections << @c
|
395
|
-
@book.save
|
396
|
-
end
|
397
|
-
after do
|
398
|
-
@c.delete
|
399
|
-
end
|
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
|
-
end
|
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
|
-
end
|
407
|
-
it 'should load the collections' do
|
408
|
-
reloaded = Book.find(@book.pid)
|
409
|
-
expect(reloaded.collections).to eq([@c])
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
271
|
end
|
414
272
|
|
415
|
-
describe
|
273
|
+
describe "setting belongs_to" do
|
416
274
|
before do
|
417
275
|
@library = Library.new()
|
418
276
|
@library.save()
|
@@ -422,51 +280,51 @@ describe ActiveFedora::Base do
|
|
422
280
|
@publisher = Publisher.new
|
423
281
|
@publisher.save
|
424
282
|
end
|
425
|
-
it
|
283
|
+
it "should set the association" do
|
426
284
|
@book.library = @library
|
427
|
-
|
285
|
+
@book.library.pid.should == @library.pid
|
428
286
|
@book.save
|
429
287
|
|
430
288
|
|
431
|
-
|
432
|
-
|
289
|
+
Book.find(@book.pid).library.pid.should == @library.pid
|
290
|
+
|
433
291
|
end
|
434
|
-
it
|
292
|
+
it "should clear the association" do
|
435
293
|
@book.library = @library
|
436
294
|
@book.library = nil
|
437
295
|
@book.save
|
438
296
|
|
439
|
-
|
440
|
-
|
297
|
+
Book.find(@book.pid).library.should be_nil
|
298
|
+
|
441
299
|
end
|
442
300
|
|
443
|
-
it
|
301
|
+
it "should replace the association" do
|
444
302
|
@library2 = Library.new
|
445
303
|
@library2.save
|
446
304
|
@book.library = @library
|
447
305
|
@book.save
|
448
306
|
@book.library = @library2
|
449
307
|
@book.save
|
450
|
-
|
308
|
+
Book.find(@book.pid).library.pid.should == @library2.pid
|
451
309
|
|
452
310
|
end
|
453
311
|
|
454
|
-
it
|
312
|
+
it "should only replace the matching class association" do
|
455
313
|
@publisher2 = Publisher.new
|
456
314
|
@publisher2.save
|
457
315
|
|
458
316
|
@book.publisher = @publisher
|
459
|
-
@book.author = @author
|
460
|
-
@book.save
|
317
|
+
@book.author = @author
|
318
|
+
@book.save
|
461
319
|
|
462
320
|
@book.publisher = @publisher2
|
463
321
|
@book.save
|
464
322
|
|
465
|
-
|
466
|
-
|
323
|
+
Book.find(@book.pid).publisher.pid.should == @publisher2.pid
|
324
|
+
Book.find(@book.pid).author.pid.should == @author.pid
|
467
325
|
end
|
468
326
|
|
469
|
-
it
|
327
|
+
it "should only clear the matching class association" do
|
470
328
|
@book.publisher = @publisher
|
471
329
|
@book.author = @author
|
472
330
|
@book.save
|
@@ -474,16 +332,16 @@ describe ActiveFedora::Base do
|
|
474
332
|
@book.author = nil
|
475
333
|
@book.save
|
476
334
|
|
477
|
-
|
478
|
-
|
335
|
+
Book.find(@book.pid).author.should be_nil
|
336
|
+
Book.find(@book.pid).publisher.pid.should == @publisher.pid
|
479
337
|
end
|
480
338
|
|
481
|
-
it
|
339
|
+
it "should be able to be set by id" do
|
482
340
|
@book.library_id = @library.pid
|
483
|
-
|
484
|
-
|
341
|
+
@book.library_id.should == @library.pid
|
342
|
+
@book.library.pid.should == @library.pid
|
485
343
|
@book.save
|
486
|
-
|
344
|
+
Book.find(@book.pid).library_id.should == @library.pid
|
487
345
|
end
|
488
346
|
|
489
347
|
after do
|
@@ -497,48 +355,22 @@ describe ActiveFedora::Base do
|
|
497
355
|
end
|
498
356
|
end
|
499
357
|
|
500
|
-
describe
|
501
|
-
before :all do
|
502
|
-
class Textbook < ActiveFedora::Base
|
503
|
-
belongs_to :container, :property => :is_part_of, :class_name => 'ActiveFedora::Base'
|
504
|
-
end
|
505
|
-
class Shelf < ActiveFedora::Base; end
|
506
|
-
end
|
507
|
-
|
508
|
-
after :all do
|
509
|
-
Object.send(:remove_const, :Textbook)
|
510
|
-
Object.send(:remove_const, :Shelf)
|
511
|
-
end
|
512
|
-
|
513
|
-
after do
|
514
|
-
shelf.destroy
|
515
|
-
end
|
516
|
-
|
517
|
-
let(:shelf) { Shelf.create}
|
518
|
-
subject { Textbook.new }
|
519
|
-
|
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
|
-
subject.container_id = shelf.id
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
describe 'single direction habtm' do
|
358
|
+
describe "single direction habtm" do
|
527
359
|
before :all do
|
528
360
|
class Course < ActiveFedora::Base
|
529
|
-
has_and_belongs_to_many :textbooks, :property
|
361
|
+
has_and_belongs_to_many :textbooks, :property=>:is_part_of
|
530
362
|
end
|
531
363
|
class Textbook < ActiveFedora::Base
|
532
|
-
has_many :courses, :property
|
364
|
+
has_many :courses, :property=>:is_part_of
|
533
365
|
end
|
534
|
-
|
366
|
+
|
535
367
|
end
|
536
368
|
after :all do
|
537
369
|
Object.send(:remove_const, :Course)
|
538
370
|
Object.send(:remove_const, :Textbook)
|
539
371
|
end
|
540
372
|
|
541
|
-
describe
|
373
|
+
describe "with a parent that has two children" do
|
542
374
|
before do
|
543
375
|
@course = Course.create
|
544
376
|
@t1 = Textbook.create()
|
@@ -547,46 +379,46 @@ describe ActiveFedora::Base do
|
|
547
379
|
@course.save
|
548
380
|
end
|
549
381
|
|
550
|
-
it
|
382
|
+
it "should load the association stored in the parent" do
|
551
383
|
@reloaded_course = Course.find(@course.pid)
|
552
|
-
|
384
|
+
@reloaded_course.textbooks.should == [@t1, @t2]
|
553
385
|
end
|
554
386
|
|
555
|
-
it
|
387
|
+
it "should allow a parent to be deleted from the has_many association" do
|
556
388
|
@reloaded_course = Course.find(@course.pid)
|
557
389
|
@t1.courses.delete(@reloaded_course)
|
558
390
|
@reloaded_course.save
|
559
391
|
|
560
392
|
@reloaded_course = Course.find(@course.pid)
|
561
|
-
|
393
|
+
@reloaded_course.textbooks.should == [@t2]
|
562
394
|
end
|
563
395
|
|
564
|
-
it
|
396
|
+
it "should allow replacing the children" do
|
565
397
|
@t3 = Textbook.create()
|
566
398
|
@t4 = Textbook.create()
|
567
399
|
@course.textbooks = [@t3, @t4]
|
568
400
|
@course.save
|
569
401
|
|
570
|
-
|
402
|
+
@course.reload.textbooks.should == [@t3, @t4]
|
571
403
|
end
|
572
404
|
|
573
|
-
it
|
405
|
+
it "should allow a child to be deleted from the has_and_belongs_to_many association" do
|
574
406
|
@reloaded_course = Course.find(@course.pid)
|
575
407
|
@reloaded_course.textbooks.delete(@t1)
|
576
408
|
@reloaded_course.save
|
577
409
|
@t1.save
|
578
410
|
|
579
411
|
@reloaded_course = Course.find(@course.pid)
|
580
|
-
|
412
|
+
@reloaded_course.textbooks.should == [@t2]
|
581
413
|
end
|
582
414
|
end
|
583
415
|
end
|
584
416
|
|
585
|
-
describe
|
586
|
-
describe
|
417
|
+
describe "association hooks" do
|
418
|
+
describe "for habtm" do
|
587
419
|
before :all do
|
588
420
|
class LibraryBook < ActiveFedora::Base
|
589
|
-
has_and_belongs_to_many :pages, :property
|
421
|
+
has_and_belongs_to_many :pages, :property=>:is_part_of, after_remove: :after_hook, before_remove: :before_hook
|
590
422
|
|
591
423
|
def before_hook(m)
|
592
424
|
say_hi(m)
|
@@ -601,16 +433,16 @@ describe ActiveFedora::Base do
|
|
601
433
|
|
602
434
|
end
|
603
435
|
class Page < ActiveFedora::Base
|
604
|
-
has_many :library_books, :property
|
436
|
+
has_many :library_books, :property=>:is_part_of
|
605
437
|
end
|
606
|
-
|
438
|
+
|
607
439
|
end
|
608
440
|
after :all do
|
609
441
|
Object.send(:remove_const, :LibraryBook)
|
610
442
|
Object.send(:remove_const, :Page)
|
611
443
|
end
|
612
444
|
|
613
|
-
describe
|
445
|
+
describe "removing association" do
|
614
446
|
subject {LibraryBook.create}
|
615
447
|
before do
|
616
448
|
@p1 = Page.create
|
@@ -618,74 +450,43 @@ describe ActiveFedora::Base do
|
|
618
450
|
subject.pages << @p1 << @p2
|
619
451
|
subject.save!
|
620
452
|
end
|
621
|
-
it
|
622
|
-
|
453
|
+
it "should save between the before and after hooks" do
|
454
|
+
subject.should_receive(:say_hi).with(@p2).twice
|
623
455
|
subject.pages.delete(@p2)
|
624
456
|
end
|
625
457
|
end
|
626
458
|
end
|
627
|
-
describe
|
459
|
+
describe "for has_many" do
|
628
460
|
before :all do
|
629
461
|
class LibraryBook < ActiveFedora::Base
|
630
|
-
has_many :pages, :property
|
462
|
+
has_many :pages, :property=>:is_part_of, after_remove: :say_hi
|
631
463
|
|
632
464
|
end
|
633
465
|
class Page < ActiveFedora::Base
|
634
|
-
belongs_to :library_book, :property
|
466
|
+
belongs_to :library_book, :property=>:is_part_of
|
635
467
|
end
|
636
|
-
|
468
|
+
|
637
469
|
end
|
638
470
|
after :all do
|
639
471
|
Object.send(:remove_const, :LibraryBook)
|
640
472
|
Object.send(:remove_const, :Page)
|
641
473
|
end
|
642
474
|
|
643
|
-
describe
|
475
|
+
describe "removing association" do
|
644
476
|
subject {LibraryBook.new}
|
645
477
|
before do
|
646
478
|
@p1 = subject.pages.build
|
647
479
|
@p2 = subject.pages.build
|
648
480
|
end
|
649
|
-
it
|
650
|
-
|
481
|
+
it "should run the hooks" do
|
482
|
+
subject.should_receive(:say_hi).with(@p2)
|
651
483
|
subject.pages.delete(@p2)
|
652
484
|
end
|
653
485
|
end
|
654
486
|
end
|
655
487
|
end
|
656
488
|
|
657
|
-
|
658
|
-
describe 'when a object is deleted' do
|
659
|
-
before (:all) do
|
660
|
-
class MasterFile < ActiveFedora::Base
|
661
|
-
belongs_to :media_object, :property => :is_part_of
|
662
|
-
end
|
663
|
-
class MediaObject < ActiveFedora::Base
|
664
|
-
has_many :parts, :class_name => 'MasterFile', :property => :is_part_of
|
665
|
-
end
|
666
|
-
end
|
667
|
-
|
668
|
-
before :each do
|
669
|
-
@master = MasterFile.create
|
670
|
-
@media = MediaObject.create
|
671
|
-
@master.media_object = @media
|
672
|
-
@master.save
|
673
|
-
@master.reload
|
674
|
-
end
|
675
|
-
|
676
|
-
after :all do
|
677
|
-
Object.send(:remove_const, :MasterFile)
|
678
|
-
Object.send(:remove_const, :MediaObject)
|
679
|
-
end
|
680
|
-
|
681
|
-
it 'should also remove the relationships that point at that object' do
|
682
|
-
@media.delete
|
683
|
-
@master = MasterFile.find(@master.pid)
|
684
|
-
expect(@master.relationships(:is_part_of)).to eq([])
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
|
-
describe 'has_many' do
|
489
|
+
describe "has_many" do
|
689
490
|
describe "when an object doesn't have a property, and the class_name is predictable" do
|
690
491
|
before (:all) do
|
691
492
|
class Bauble < ActiveFedora::Base
|
@@ -700,8 +501,8 @@ describe ActiveFedora::Base do
|
|
700
501
|
Object.send(:remove_const, :MediaObject)
|
701
502
|
end
|
702
503
|
|
703
|
-
it
|
704
|
-
|
504
|
+
it "it should find the predicate" do
|
505
|
+
MediaObject.new.association(:baubles).send(:find_predicate).should == :is_part_of
|
705
506
|
end
|
706
507
|
end
|
707
508
|
|
@@ -711,7 +512,7 @@ describe ActiveFedora::Base do
|
|
711
512
|
belongs_to :media_object, property: :is_part_of
|
712
513
|
end
|
713
514
|
class MediaObject < ActiveFedora::Base
|
714
|
-
has_many :parts, :class_name
|
515
|
+
has_many :parts, :class_name=>'MasterFile'
|
715
516
|
end
|
716
517
|
end
|
717
518
|
after :all do
|
@@ -719,12 +520,12 @@ describe ActiveFedora::Base do
|
|
719
520
|
Object.send(:remove_const, :MediaObject)
|
720
521
|
end
|
721
522
|
|
722
|
-
it
|
723
|
-
|
523
|
+
it "it should find the predicate" do
|
524
|
+
MediaObject.new.association(:parts).send(:find_predicate).should == :is_part_of
|
724
525
|
end
|
725
526
|
end
|
726
527
|
|
727
|
-
describe
|
528
|
+
describe "an object has an explicity property" do
|
728
529
|
before (:all) do
|
729
530
|
class Bauble < ActiveFedora::Base
|
730
531
|
belongs_to :media_object, property: :is_part_of
|
@@ -738,8 +539,8 @@ describe ActiveFedora::Base do
|
|
738
539
|
Object.send(:remove_const, :MediaObject)
|
739
540
|
end
|
740
541
|
|
741
|
-
it
|
742
|
-
|
542
|
+
it "it should find the predicate" do
|
543
|
+
MediaObject.new.association(:baubles).send(:find_predicate).should == :has_baubles
|
743
544
|
end
|
744
545
|
end
|
745
546
|
describe "an object doesn't have a property" do
|
@@ -756,14 +557,14 @@ describe ActiveFedora::Base do
|
|
756
557
|
Object.send(:remove_const, :MediaObject)
|
757
558
|
end
|
758
559
|
|
759
|
-
it
|
760
|
-
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError,
|
560
|
+
it "it should find the predicate" do
|
561
|
+
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
562
|
end
|
762
563
|
end
|
763
564
|
end
|
764
565
|
|
765
|
-
describe
|
766
|
-
describe
|
566
|
+
describe "casting when the class name is ActiveFedora::Base" do
|
567
|
+
describe "for habtm" do
|
767
568
|
before :all do
|
768
569
|
class Novel < ActiveFedora::Base
|
769
570
|
has_and_belongs_to_many :contents, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
@@ -777,7 +578,7 @@ describe ActiveFedora::Base do
|
|
777
578
|
class Image < ActiveFedora::Base
|
778
579
|
has_many :books, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
779
580
|
end
|
780
|
-
|
581
|
+
|
781
582
|
end
|
782
583
|
after :all do
|
783
584
|
Object.send(:remove_const, :Novel)
|
@@ -786,7 +587,7 @@ describe ActiveFedora::Base do
|
|
786
587
|
Object.send(:remove_const, :Image)
|
787
588
|
end
|
788
589
|
|
789
|
-
describe
|
590
|
+
describe "saving between the before and after hooks" do
|
790
591
|
let(:text1) { Text.create}
|
791
592
|
let(:image1) { Image.create}
|
792
593
|
let(:text2) { Text.create}
|
@@ -794,114 +595,26 @@ describe ActiveFedora::Base do
|
|
794
595
|
let(:book1) { TextBook.create}
|
795
596
|
let(:book2) { Novel.create}
|
796
597
|
|
797
|
-
it
|
598
|
+
it "should work when added via the has_and_belongs_to_many" do
|
798
599
|
book1.contents = [text1, image1]
|
799
600
|
book1.save!
|
800
601
|
book2.contents = [text2, image2]
|
801
602
|
book2.save!
|
802
603
|
|
803
|
-
|
804
|
-
|
805
|
-
|
604
|
+
book1.reload.contents.should include(text1, image1)
|
605
|
+
text1.reload.books.should == [book1]
|
606
|
+
image1.reload.books.should == [book1]
|
806
607
|
|
807
|
-
|
808
|
-
|
809
|
-
|
608
|
+
book2.reload.contents.should include(text2, image2)
|
609
|
+
text2.reload.books.should == [book2]
|
610
|
+
image2.reload.books.should == [book2]
|
810
611
|
end
|
811
612
|
|
812
|
-
it
|
613
|
+
it "should work when added via the has_many" do
|
813
614
|
text2.books << book2
|
814
615
|
book2.save
|
815
|
-
|
816
|
-
|
817
|
-
end
|
818
|
-
end
|
819
|
-
end
|
820
|
-
end
|
821
|
-
|
822
|
-
describe 'casting inheritance additional test cases' do
|
823
|
-
describe 'for habtm' do
|
824
|
-
before :all do
|
825
|
-
class SimpleObject < ActiveFedora::Base
|
826
|
-
belongs_to :simple_collection, property: :is_part_of, class_name: 'SimpleCollection'
|
827
|
-
belongs_to :complex_collection, property: :is_part_of, class_name: 'ComplexCollection'
|
828
|
-
end
|
829
|
-
|
830
|
-
class ComplexObject < SimpleObject
|
831
|
-
end
|
832
|
-
|
833
|
-
class SimpleCollection < ActiveFedora::Base
|
834
|
-
has_many :objects, property: :is_part_of, class_name: 'SimpleObject'
|
835
|
-
has_many :complex_objects, property: :is_part_of, class_name: 'ComplexObject'
|
836
|
-
end
|
837
|
-
|
838
|
-
class ComplexCollection < SimpleCollection
|
839
|
-
end
|
840
|
-
|
841
|
-
end
|
842
|
-
after :all do
|
843
|
-
Object.send(:remove_const, :SimpleObject)
|
844
|
-
Object.send(:remove_const, :ComplexObject)
|
845
|
-
Object.send(:remove_const, :SimpleCollection)
|
846
|
-
Object.send(:remove_const, :ComplexCollection)
|
847
|
-
end
|
848
|
-
|
849
|
-
describe 'saving between the before and after hooks' do
|
850
|
-
before do
|
851
|
-
@simple_collection = SimpleCollection.create
|
852
|
-
@complex_collection = ComplexCollection.create
|
853
|
-
|
854
|
-
@simple_object = SimpleObject.create
|
855
|
-
@simple_object_second = SimpleObject.create
|
856
|
-
@complex_object = ComplexObject.create
|
857
|
-
|
858
|
-
#Need to add the simpler cmodel here as currently inheritance support is read-only.
|
859
|
-
#See ActiveFedora pull request 207 on how to do this programmatically.
|
860
|
-
@complex_object.add_relationship(:has_model, @complex_object.class.superclass.to_class_uri)
|
861
|
-
|
862
|
-
@simple_collection.objects = [@simple_object, @simple_object_second, @complex_object]
|
863
|
-
@simple_collection.save!
|
864
|
-
@complex_collection.objects = [@simple_object, @complex_object]
|
865
|
-
@complex_collection.save!
|
866
|
-
@complex_object.save!
|
867
|
-
@simple_object.save!
|
868
|
-
@simple_object_second.save!
|
869
|
-
end
|
870
|
-
|
871
|
-
|
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
|
-
|
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
|
-
|
881
|
-
expect(@complex_collection.objects[0]).to be_instance_of SimpleObject
|
882
|
-
expect(@complex_collection.objects[1]).to be_instance_of ComplexObject
|
883
|
-
|
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
|
-
|
888
|
-
end
|
889
|
-
|
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
|
-
|
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
|
-
|
899
|
-
end
|
900
|
-
|
901
|
-
after do
|
902
|
-
@simple_object.delete
|
903
|
-
@simple_object_second.delete
|
904
|
-
@complex_object.delete
|
616
|
+
book2.reload.contents.should == [text2]
|
617
|
+
text2.reload.books.should == [book2]
|
905
618
|
end
|
906
619
|
end
|
907
620
|
end
|