active-fedora 9.0.6 → 9.0.8
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 +5 -5
- data/History.txt +57 -0
- data/lib/active_fedora.rb +5 -0
- data/lib/active_fedora/associations/collection_association.rb +1 -18
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
- data/lib/active_fedora/core.rb +15 -17
- data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
- data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
- data/lib/active_fedora/errors.rb +4 -0
- data/lib/active_fedora/fedora_attributes.rb +15 -5
- data/lib/active_fedora/file.rb +2 -0
- data/lib/active_fedora/inheritable_accessors.rb +26 -0
- data/lib/active_fedora/reflection.rb +3 -1
- data/lib/active_fedora/relation/finder_methods.rb +27 -3
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versions_graph.rb +7 -8
- data/spec/integration/associations_spec.rb +34 -22
- data/spec/integration/belongs_to_association_spec.rb +118 -47
- data/spec/integration/collection_association_spec.rb +46 -0
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +178 -139
- data/spec/integration/versionable_spec.rb +38 -1
- data/spec/samples/samples.rb +0 -1
- data/spec/unit/base_spec.rb +51 -0
- data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
- data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
- data/spec/unit/core_spec.rb +50 -0
- data/spec/unit/has_many_association_spec.rb +27 -2
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
- data/spec/unit/reflection_spec.rb +44 -0
- metadata +9 -13
- data/spec/samples/marpa-dc_datastream.rb +0 -102
- data/spec/samples/models/audio_record.rb +0 -29
- data/spec/samples/models/image.rb +0 -5
- data/spec/samples/models/oral_history.rb +0 -36
- data/spec/samples/models/seminar.rb +0 -29
- data/spec/samples/models/seminar_audio_file.rb +0 -32
- data/spec/samples/oral_history_sample_model.rb +0 -30
- data/spec/samples/special_thing.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebf611de1fa3721bc0d53f15e6210ced8509072da4f1406f818e2f14c5f11be2
|
4
|
+
data.tar.gz: 1f6729e4bce4f1b03ba5ba2864c4dbe84ae454932221de98fe4357b8e80e69e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ba1bc7bcb326f435f1ed88cad1e1a7b68c04b122472379430bf320a634e67e3da72c13c424dda5ba1f9d2673aec820a74d9b7adffb60bd9c23498f89ed7b52
|
7
|
+
data.tar.gz: 2e06a0593ec85862f1995277e7a530f05bff3f31e30ed80a4719c04beb8807c28060ec275fa2d833c118b83ad22fb812c5a07d848823bbfc9d90bb8693683fd9
|
data/History.txt
CHANGED
@@ -1,3 +1,60 @@
|
|
1
|
+
v9.0.8
|
2
|
+
|
3
|
+
2015-04-15: Revert "Move the indexing logic to the model. Fixes #736"
|
4
|
+
[Justin Coyne] (cabb9057)
|
5
|
+
|
6
|
+
2015-04-15: Fix deleting from a HABTM when the inverse_of is a
|
7
|
+
has_many. Fixes #763 [Justin Coyne] (b1e67fb1)
|
8
|
+
|
9
|
+
2015-04-15: Remove a spec that is a duplicate of
|
10
|
+
integration/collection_association_spec.rb:92 [Justin Coyne]
|
11
|
+
(bdafd50d)
|
12
|
+
|
13
|
+
2015-04-15: Leverage the code in AssociationRelation to find the
|
14
|
+
inverse. Fixes #760 [Justin Coyne] (c764ea70)
|
15
|
+
|
16
|
+
2015-04-15: Make #translate_id_to_uri/uri_to_id reliable. [Trey
|
17
|
+
Terrell] (80a4e3fd)
|
18
|
+
|
19
|
+
2015-04-15: Find best model match in case of inheritance [Stuart
|
20
|
+
Kenny] (481a9cd4)
|
21
|
+
|
22
|
+
2015-04-15: Requires 'deprecation' for ActiveFedora::File [Andrew
|
23
|
+
Myers] (14be5cf6)
|
24
|
+
|
25
|
+
2015-04-07: The indexing hints should be inheritable [Justin Coyne]
|
26
|
+
(c8d41b91)
|
27
|
+
|
28
|
+
v9.0.7
|
29
|
+
2015-04-06: Only set/save the inverse on a HABTM if the inverse is also HABTM
|
30
|
+
previously we were getting: [Justin Coyne]
|
31
|
+
|
32
|
+
2015-04-06: Derive a foreign_key ending with `_ids` if the inverse is a
|
33
|
+
collection [Justin Coyne]
|
34
|
+
|
35
|
+
2015-04-06: Find inverse relations when class_names have modules [Justin Coyne]
|
36
|
+
|
37
|
+
2015-04-06: Raise an error when the inverse relationship can not be found.
|
38
|
+
Previously a "SystemStackError: Stack too deep" was encountered in this
|
39
|
+
situation [Justin Coyne]
|
40
|
+
|
41
|
+
2015-04-02: Add a mechanism to set rdf_label on the ActiveTriple resource
|
42
|
+
[Justin Coyne]
|
43
|
+
|
44
|
+
2015-04-03: Refactor has_and_belongs_to_many_associations_spec [Justin Coyne]
|
45
|
+
|
46
|
+
2015-04-03: Remove unused sample classes [Justin Coyne]
|
47
|
+
|
48
|
+
2015-04-02: Sort versions as dates not as strings [Justin Coyne]
|
49
|
+
|
50
|
+
2015-04-01: Prevents an object from being loaded to the incorrect class. For
|
51
|
+
example, when loading a batch object it should be loaded into a Batch (and not a
|
52
|
+
File for example.) [Justin Coyne]
|
53
|
+
|
54
|
+
2015-03-27: Move the indexing logic to the model. Fixes #736 You should now add
|
55
|
+
indexing hints to has_attributes by passing a block similar to how you do it
|
56
|
+
with rdf properties. e.g.: [Justin Coyne]
|
57
|
+
|
1
58
|
v9.0.6
|
2
59
|
2015-03-26: Setting type should not wipe out properties. Fixes #737 [Justin Coyne]
|
3
60
|
|
data/lib/active_fedora.rb
CHANGED
@@ -51,6 +51,10 @@ module ActiveFedora #:nodoc:
|
|
51
51
|
autoload :ChangeSet
|
52
52
|
autoload :Config
|
53
53
|
autoload :Core
|
54
|
+
autoload_under 'core' do
|
55
|
+
autoload :FedoraIdTranslator
|
56
|
+
autoload :FedoraUriTranslator
|
57
|
+
end
|
54
58
|
autoload :Datastream
|
55
59
|
autoload :Datastreams
|
56
60
|
autoload :DelegatedAttribute
|
@@ -63,6 +67,7 @@ module ActiveFedora #:nodoc:
|
|
63
67
|
autoload :FixityService
|
64
68
|
autoload :Indexing
|
65
69
|
autoload :IndexingService
|
70
|
+
autoload :InheritableAccessors
|
66
71
|
autoload :LdpCache
|
67
72
|
autoload :LdpResource
|
68
73
|
autoload :LdpResourceService
|
@@ -343,29 +343,12 @@ module ActiveFedora
|
|
343
343
|
def find_reflection
|
344
344
|
return reflection if @reflection.options[:predicate]
|
345
345
|
if @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base' && @reflection.macro != :has_and_belongs_to_many
|
346
|
-
|
347
|
-
begin
|
348
|
-
find_reflection_for_relation(@reflection.class_name.constantize)
|
349
|
-
rescue NameError
|
350
|
-
raise "No :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}"
|
351
|
-
end
|
346
|
+
@reflection.inverse_of || raise("No :inverse_of or :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}")
|
352
347
|
else
|
353
348
|
raise "Couldn't find reflection"
|
354
349
|
end
|
355
350
|
end
|
356
351
|
|
357
|
-
def find_reflection_for_relation(klass, inverse_relation=@owner.class.to_s.underscore.to_sym)
|
358
|
-
raise "Unable to lookup the :predicate attribute for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class} because #{klass} specifies \"class_name: 'ActiveFedora::Base'\". Either specify a specific class_name in #{klass} or set :predicate in the #{@reflection.macro} declaration on #{@owner.class}" if inverse_relation == :'active_fedora/base'
|
359
|
-
if klass.reflections.key?(inverse_relation)
|
360
|
-
# Try it singular
|
361
|
-
return klass.reflections[inverse_relation]
|
362
|
-
elsif klass.reflections.key?(inverse_relation.to_s.pluralize.to_sym)
|
363
|
-
# Try it plural
|
364
|
-
return klass.reflections[inverse_relation.to_s.pluralize.to_sym]
|
365
|
-
end
|
366
|
-
find_reflection_for_relation(klass, @owner.class.superclass.to_s.underscore.to_sym)
|
367
|
-
end
|
368
|
-
|
369
352
|
def create_record(attributes, raise = false)
|
370
353
|
attributes.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
|
371
354
|
ensure_owner_is_not_new
|
@@ -18,13 +18,16 @@ module ActiveFedora
|
|
18
18
|
owner[reflection.foreign_key] ||= []
|
19
19
|
owner[reflection.foreign_key] += [record.id]
|
20
20
|
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
# Only if they've explicitly stated the inverse in the options
|
22
|
+
if reflection.options[:inverse_of]
|
23
|
+
inverse = reflection.inverse_of
|
24
|
+
if owner.new_record?
|
25
|
+
ActiveFedora::Base.logger.warn("has_and_belongs_to_many #{reflection.inspect} is cowardly refusing to insert the inverse relationship into #{record}, because #{owner} is not persisted yet.") if ActiveFedora::Base.logger
|
26
|
+
elsif inverse.has_and_belongs_to_many?
|
27
|
+
record[inverse.foreign_key] ||= []
|
28
|
+
record[inverse.foreign_key] += [owner.id]
|
29
|
+
record.save
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
return true
|
@@ -76,9 +79,8 @@ module ActiveFedora
|
|
76
79
|
records.each do |r|
|
77
80
|
owner[reflection.foreign_key] -= [r.id]
|
78
81
|
|
79
|
-
if
|
80
|
-
inverse
|
81
|
-
r[inverse.foreign_key] -= [owner.id]
|
82
|
+
if inverse = @reflection.inverse_of
|
83
|
+
r[inverse.foreign_key] -= [owner.id] if inverse.has_and_belongs_to_many?
|
82
84
|
r.association(inverse.name).reset
|
83
85
|
r.save
|
84
86
|
end
|
data/lib/active_fedora/core.rb
CHANGED
@@ -14,14 +14,25 @@ module ActiveFedora
|
|
14
14
|
# :singleton-method
|
15
15
|
#
|
16
16
|
# Accepts a proc that takes an id and transforms it to a URI
|
17
|
-
|
17
|
+
mattr_reader :translate_id_to_uri do
|
18
|
+
FedoraIdTranslator
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.translate_id_to_uri=(translator)
|
22
|
+
@@translate_id_to_uri = translator || FedoraIdTranslator
|
23
|
+
end
|
18
24
|
|
19
25
|
##
|
20
26
|
# :singleton-method
|
21
27
|
#
|
22
28
|
# Accepts a proc that takes a uri and transforms it to an id
|
23
|
-
|
29
|
+
mattr_reader :translate_uri_to_id do
|
30
|
+
FedoraUriTranslator
|
31
|
+
end
|
24
32
|
|
33
|
+
def self.translate_uri_to_id=(translator)
|
34
|
+
@@translate_uri_to_id = translator || FedoraUriTranslator
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
def ldp_source
|
@@ -134,27 +145,14 @@ module ActiveFedora
|
|
134
145
|
# Transforms an id into a uri
|
135
146
|
# if translate_id_to_uri is set it uses that proc, otherwise just the default
|
136
147
|
def id_to_uri(id)
|
137
|
-
|
138
|
-
translate_id_to_uri.call(id)
|
139
|
-
else
|
140
|
-
id = "/#{id}" unless id.start_with? SLASH
|
141
|
-
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
142
|
-
id = ActiveFedora.fedora.base_path + id
|
143
|
-
end
|
144
|
-
ActiveFedora.fedora.host + id
|
145
|
-
end
|
148
|
+
translate_id_to_uri.call(id)
|
146
149
|
end
|
147
150
|
|
148
151
|
##
|
149
152
|
# Transforms a uri into an id
|
150
153
|
# if translate_uri_to_id is set it uses that proc, otherwise just the default
|
151
154
|
def uri_to_id(uri)
|
152
|
-
|
153
|
-
translate_uri_to_id.call(uri)
|
154
|
-
else
|
155
|
-
id = uri.to_s.sub(ActiveFedora.fedora.host + ActiveFedora.fedora.base_path, '')
|
156
|
-
id.start_with?('/') ? id[1..-1] : id
|
157
|
-
end
|
155
|
+
translate_uri_to_id.call(uri)
|
158
156
|
end
|
159
157
|
|
160
158
|
##
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActiveFedora::Core
|
2
|
+
class FedoraIdTranslator
|
3
|
+
SLASH = '/'.freeze
|
4
|
+
def self.call(id)
|
5
|
+
id = "/#{id}" unless id.start_with? SLASH
|
6
|
+
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
7
|
+
id = ActiveFedora.fedora.base_path + id
|
8
|
+
end
|
9
|
+
ActiveFedora.fedora.host + id
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/active_fedora/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module FedoraAttributes
|
3
3
|
extend ActiveSupport::Concern
|
4
|
+
include InheritableAccessors
|
4
5
|
|
5
6
|
included do
|
6
7
|
include ActiveTriples::Properties
|
@@ -18,6 +19,8 @@ module ActiveFedora
|
|
18
19
|
def modified_date
|
19
20
|
super.first
|
20
21
|
end
|
22
|
+
|
23
|
+
define_inheritable_accessor(:type, :rdf_label)
|
21
24
|
end
|
22
25
|
|
23
26
|
# Override ActiveTriples method for setting properties
|
@@ -62,6 +65,12 @@ module ActiveFedora
|
|
62
65
|
@resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, @ldp_source.graph)
|
63
66
|
end
|
64
67
|
|
68
|
+
# You can set the URI to use for the rdf_label on ClassMethods.rdf_label, then on
|
69
|
+
# the instance, calling rdf_label returns the value of that configured property
|
70
|
+
def rdf_label
|
71
|
+
resource.rdf_label
|
72
|
+
end
|
73
|
+
|
65
74
|
module ClassMethods
|
66
75
|
# We make a unique class, because properties belong to a class.
|
67
76
|
# This keeps properties from different objects separate.
|
@@ -70,7 +79,7 @@ module ActiveFedora
|
|
70
79
|
def resource_class
|
71
80
|
@generated_resource_class ||= begin
|
72
81
|
klass = self.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
|
73
|
-
klass.configure
|
82
|
+
klass.configure active_triple_options
|
74
83
|
klass.properties.merge(self.properties).each do |property, config|
|
75
84
|
klass.property(config.term,
|
76
85
|
predicate: config.predicate,
|
@@ -80,10 +89,11 @@ module ActiveFedora
|
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
92
|
+
private
|
93
|
+
# @return a Hash of options suitable for passing to ActiveTriples::Base.configure
|
94
|
+
def active_triple_options
|
95
|
+
{ type: type, rdf_label: rdf_label }
|
96
|
+
end
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
data/lib/active_fedora/file.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Similar to ActiveSupport.class_attribute but with a setter that doesn't use the #{name}= syntax
|
2
|
+
# This preserves backward compatibility with the API in ActiveTriples
|
3
|
+
|
4
|
+
module ActiveFedora
|
5
|
+
module InheritableAccessors
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
module ClassMethods
|
8
|
+
def define_inheritable_accessor(*names)
|
9
|
+
names.each do |name|
|
10
|
+
define_accessor(name, nil)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def define_accessor(name, val)
|
16
|
+
singleton_class.class_eval do
|
17
|
+
remove_possible_method(name)
|
18
|
+
define_method(name) do |uri = nil|
|
19
|
+
define_accessor(name, uri) if uri
|
20
|
+
val
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -152,6 +152,8 @@ module ActiveFedora
|
|
152
152
|
"#{name.to_s.singularize}_ids"
|
153
153
|
elsif options[:as]
|
154
154
|
"#{options[:as]}_id"
|
155
|
+
elsif inverse_of && inverse_of.collection?
|
156
|
+
"#{options[:inverse_of].to_s.singularize}_ids"
|
155
157
|
else
|
156
158
|
# This works well if this is a has_many that is the inverse of a belongs_to, but it isn't correct for a has_many that is the invers of a has_and_belongs_to_many
|
157
159
|
active_fedora.name.foreign_key
|
@@ -292,7 +294,7 @@ module ActiveFedora
|
|
292
294
|
# returns either false or the inverse association name that it finds.
|
293
295
|
def automatic_inverse_of
|
294
296
|
if can_find_inverse_of_automatically?(self)
|
295
|
-
inverse_name = ActiveSupport::Inflector.underscore(active_fedora.name).to_sym
|
297
|
+
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_fedora.name.demodulize).to_sym
|
296
298
|
|
297
299
|
begin
|
298
300
|
reflection = klass.reflect_on_association(inverse_name)
|
@@ -38,7 +38,6 @@ module ActiveFedora
|
|
38
38
|
return to_a.find { |*block_args| yield(*block_args) } if block_given?
|
39
39
|
options = args.extract_options!
|
40
40
|
options = options.dup
|
41
|
-
|
42
41
|
cast = if @klass == ActiveFedora::Base && !options.has_key?(:cast)
|
43
42
|
true
|
44
43
|
else
|
@@ -198,12 +197,37 @@ module ActiveFedora
|
|
198
197
|
ActiveFedora::Base
|
199
198
|
else
|
200
199
|
# The true class may be a subclass of @klass, so always use from_class_uri
|
201
|
-
Model.from_class_uri(has_model_value(resource)) || ActiveFedora::Base
|
200
|
+
resource_class = Model.from_class_uri(has_model_value(resource)) || ActiveFedora::Base
|
201
|
+
unless equivalent_class?(resource_class)
|
202
|
+
raise ActiveFedora::ActiveFedoraError.new("Model mismatch. Expected #{@klass}. Got: #{resource_class}")
|
203
|
+
end
|
204
|
+
resource_class
|
202
205
|
end
|
203
206
|
end
|
204
207
|
|
205
208
|
def has_model_value(resource)
|
206
|
-
|
209
|
+
best_model_match = nil
|
210
|
+
|
211
|
+
resource.graph.query([nil, ActiveFedora::RDF::Fcrepo::Model.hasModel, nil]).each do |rg|
|
212
|
+
|
213
|
+
model_value = Model.from_class_uri(rg.object.to_s)
|
214
|
+
|
215
|
+
if model_value
|
216
|
+
|
217
|
+
best_model_match ||= model_value
|
218
|
+
|
219
|
+
# If there is an inheritance structure, use the most specific case.
|
220
|
+
if best_model_match > model_value
|
221
|
+
best_model_match = model_value
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
best_model_match.to_s
|
227
|
+
end
|
228
|
+
|
229
|
+
def equivalent_class?(other_class)
|
230
|
+
other_class <= @klass
|
207
231
|
end
|
208
232
|
|
209
233
|
def find_with_ids(ids, cast)
|
@@ -2,11 +2,13 @@ module ActiveFedora
|
|
2
2
|
class VersionsGraph < ::RDF::Graph
|
3
3
|
|
4
4
|
def all opts={}
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
fedora_versions.reject { |v| v.label.match("auto") }
|
5
|
+
versions = fedora_versions
|
6
|
+
unless opts[:include_auto_save]
|
7
|
+
versions.reject! { |version| version.label.match("auto") }
|
9
8
|
end
|
9
|
+
versions.sort_by { |version| DateTime.parse(version.created) }
|
10
|
+
rescue ArgumentError, NoMethodError
|
11
|
+
raise ActiveFedora::VersionLacksCreateDate
|
10
12
|
end
|
11
13
|
|
12
14
|
def first
|
@@ -50,10 +52,7 @@ module ActiveFedora
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def fedora_versions
|
53
|
-
|
54
|
-
list.sort_by(&:created)
|
55
|
+
resources.map { |statement| version_from_resource(statement) }
|
55
56
|
end
|
56
|
-
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
@@ -28,7 +28,7 @@ describe ActiveFedora::Base do
|
|
28
28
|
describe "explicit foreign key" do
|
29
29
|
before do
|
30
30
|
class FooThing < ActiveFedora::Base
|
31
|
-
has_many :bars, :class_name=>'BarThing', :predicate=>ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, :
|
31
|
+
has_many :bars, :class_name=>'BarThing', :predicate=>ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, as: :foothing
|
32
32
|
end
|
33
33
|
|
34
34
|
class BarThing < ActiveFedora::Base
|
@@ -286,6 +286,39 @@ describe ActiveFedora::Base do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
+
describe "when fetching an existing object" do
|
290
|
+
before do
|
291
|
+
class Dog < ActiveFedora::Base; end
|
292
|
+
class BigDog < Dog; end
|
293
|
+
class Cat < ActiveFedora::Base; end
|
294
|
+
@dog = Dog.create
|
295
|
+
@big_dog = BigDog.create
|
296
|
+
end
|
297
|
+
it "should detect class mismatch" do
|
298
|
+
expect {
|
299
|
+
Cat.find @dog.id
|
300
|
+
}.to raise_error(ActiveFedora::ActiveFedoraError)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should not accept parent class into a subclass" do
|
304
|
+
expect {
|
305
|
+
BigDog.find @dog.id
|
306
|
+
}.to raise_error(ActiveFedora::ActiveFedoraError)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should accept a subclass into a parent class" do
|
310
|
+
# We could prevent this altogether since loading a subclass into
|
311
|
+
# a parent class (a BigDog into a Dog) would result in lost of
|
312
|
+
# data if the object is saved back and the subclass has more
|
313
|
+
# properties than the parent class. However, it does seem reasonable
|
314
|
+
# that people might want to use them interchangeably (after all
|
315
|
+
# a BigDog is a Dog) and therefore we allow for it.
|
316
|
+
expect {
|
317
|
+
Dog.find @big_dog.id
|
318
|
+
}.not_to raise_error
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
289
322
|
describe "setting belongs_to" do
|
290
323
|
before do
|
291
324
|
@library = Library.new()
|
@@ -558,27 +591,6 @@ describe ActiveFedora::Base do
|
|
558
591
|
expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject.reflect_on_association(:baubles)
|
559
592
|
end
|
560
593
|
end
|
561
|
-
|
562
|
-
describe "an object doesn't have a property" do
|
563
|
-
before :all do
|
564
|
-
class Bauble < ActiveFedora::Base
|
565
|
-
belongs_to :media_object, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
566
|
-
end
|
567
|
-
|
568
|
-
class MediaObject < ActiveFedora::Base
|
569
|
-
has_many :shoes
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
after :all do
|
574
|
-
Object.send(:remove_const, :Bauble)
|
575
|
-
Object.send(:remove_const, :MediaObject)
|
576
|
-
end
|
577
|
-
|
578
|
-
it "it should find the predicate" do
|
579
|
-
expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, "No :predicate attribute was set or could be inferred for has_many :shoes on MediaObject"
|
580
|
-
end
|
581
|
-
end
|
582
594
|
end
|
583
595
|
|
584
596
|
describe "casting when the class name is ActiveFedora::Base" do
|