active-fedora 6.5.1 → 6.6.0.pre1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fd2e7e3abce44ee6d01097e229e9299c14f8334
4
- data.tar.gz: dec7ba5847ad7417b25a02a82519a3aa9ff0c26b
3
+ metadata.gz: c819c53e6318b54de501b004a3a907dc223ca7f2
4
+ data.tar.gz: 9ee7ef31d8c30472b8aa37eacabb5f697bee0778
5
5
  SHA512:
6
- metadata.gz: 67ed9db96070226172df55c478ddfb0bf698ebd9ec170e5f028b860e9623cd353482a696c2dbf115bbf8a896b5bfffda88abc00c0bc17fce4d3940900612a9e7
7
- data.tar.gz: fadc2758f9fe768ad3a2a7b257790876a1bf1b4c16fed656755f113788d9594e1f81c4333b2e6ef7267e89cb7c532593a3c36135a2be9ac818c2716a0bce6ba3
6
+ metadata.gz: c280347c12e3a7a13ef3b394b2c7df63bc83c49f8f5eee24a4e71565b6da615cb179a437efca408d9b3bef51987215332c5d29704394810f55ba93e2eb9a628a
7
+ data.tar.gz: 19dad27ff49953e76f6f19d7f599afe81d1df2b9badf7c849373474a44bacf903dd06352e438803652466a3c99914b65463f01753dd6952d21882a9531141b14
@@ -22,4 +22,5 @@ Contributors to this project:
22
22
  * Richard Johnson
23
23
  * Thomas Johnson
24
24
  * mpc3c
25
+ * Steven Anderson
25
26
 
@@ -61,12 +61,6 @@ You need to have a copy of hydra-jetty running. To do this, download a working
61
61
  java -jar start.jar
62
62
  </pre>
63
63
 
64
- Then open a new terminal, go to your ActiveFedora source directory, and import fedora's demo objects.
65
-
66
- <pre>
67
- rake active_fedora:fixtures environment=test
68
- </pre>
69
-
70
64
  Now you're ready to run the tests. In the directory where active_fedora is installed, run
71
65
 
72
66
  <pre>
@@ -138,7 +138,7 @@ module ActiveFedora
138
138
  end
139
139
  end
140
140
  rescue ObjectNotFoundError => e
141
- logger.error "Solr and Fedora may be out of sync:\n" + e.message
141
+ ActiveFedora::Base.logger.error "Solr and Fedora may be out of sync:\n" + e.message
142
142
  reset
143
143
  end
144
144
  end
@@ -150,8 +150,13 @@ module ActiveFedora
150
150
  def find_target
151
151
  return [] if @finder_query.empty?
152
152
  solr_result = SolrService.query(@finder_query, :rows=>1000)
153
+
154
+ # Set the default classname to base inheritance on.
155
+ opts = {}
156
+ opts[:class] = @reflection.class_name.constantize.to_class_uri unless @reflection.class_name.nil?
157
+
153
158
  #TODO, don't reify, just store the solr results and lazily reify.
154
- return ActiveFedora::SolrService.reify_solr_results(solr_result)
159
+ return ActiveFedora::SolrService.reify_solr_results(solr_result, opts)
155
160
  end
156
161
 
157
162
  def load_from_solr
@@ -118,7 +118,7 @@ module ActiveFedora
118
118
  ## Replace existing unchanged datastreams with the definitions found in this class if they have a different type.
119
119
  ## Any datastream that is deleted here will cause a reload from fedora, so avoid it whenever possible
120
120
  ds_specs.keys.each do |key|
121
- if !@inner_object.datastreams[key].content_changed? && @inner_object.datastreams[key].class != self.class.ds_specs[key][:type]
121
+ if @inner_object.datastreams[key] != nil && !@inner_object.datastreams[key].content_changed? && @inner_object.datastreams[key].class != self.class.ds_specs[key][:type]
122
122
  @inner_object.datastreams.delete(key)
123
123
  end
124
124
  end
@@ -286,10 +286,33 @@ module ActiveFedora
286
286
  klass.allocate.init_with(inner_object)
287
287
  end
288
288
 
289
- # Examine the :has_model assertions in the RELS-EXT. Adapt this class to the first first known model
289
+ # Examines the :has_model assertions in the RELS-EXT.
290
+ #
291
+ # If the object is of type ActiveFedora::Base, then use the first :has_model
292
+ # in the RELS-EXT for this object. Due to how the RDF writer works, this is
293
+ # currently just the first alphabetical model.
294
+ #
295
+ # If the object was instantiated with any other class, then use that class
296
+ # as the base of the type the user wants rather than casting to the first
297
+ # :has_model found on the object.
298
+ #
299
+ # In either case, if an extended model of that initial base model of the two
300
+ # cases above exists in the :has_model, then instantiate as that extended
301
+ # model type instead.
290
302
  def adapt_to_cmodel
291
- the_model = ActiveFedora::ContentModel.known_models_for( self ).first
292
- self.class != the_model ? self.adapt_to(the_model) : self
303
+ best_model_match = self.class unless self.instance_of? ActiveFedora::Base
304
+
305
+ ActiveFedora::ContentModel.known_models_for( self ).each do |model_value|
306
+ # If this is of type ActiveFedora::Base, then set to the first found :has_model.
307
+ best_model_match ||= model_value
308
+
309
+ # If there is an inheritance structure, use the most specific case.
310
+ if best_model_match > model_value
311
+ best_model_match = model_value
312
+ end
313
+ end
314
+
315
+ self.instance_of?(best_model_match) ? self : self.adapt_to(best_model_match)
293
316
  end
294
317
 
295
318
  # ** EXPERIMENTAL **
@@ -1,6 +1,7 @@
1
1
  module ActiveFedora
2
2
  module Delegating
3
3
  extend ActiveSupport::Concern
4
+ extend Deprecation
4
5
 
5
6
  included do
6
7
  after_save :clear_changed_attributes
@@ -53,16 +54,16 @@ module ActiveFedora
53
54
  end
54
55
  # Provides a delegate class method to expose methods in metadata streams
55
56
  # as member of the base object. Pass the target datastream via the
56
- # <tt>:to</tt> argument. If you want to return a unique result, (e.g. string
57
- # instead of an array) set the <tt>:unique</tt> argument to true.
57
+ # <tt>:to</tt> argument. If you want to return a multivalue result, (e.g. array
58
+ # instead of a string) set the <tt>:multiple</tt> argument to true.
58
59
  #
59
60
  # The optional <tt>:at</tt> argument provides a terminology that the delegate will point to.
60
61
  #
61
62
  # class Foo < ActiveFedora::Base
62
63
  # has_metadata :name => "descMetadata", :type => MyDatastream
63
64
  #
64
- # delegate :field1, :to=>"descMetadata", :unique=>true
65
- # delegate :field2, :to=>"descMetadata", :at=>[:term1, :term2]
65
+ # delegate :field1, :to=>"descMetadata", multiple: false
66
+ # delegate :field2, :to=>"descMetadata", :at=>[:term1, :term2], multiple: true
66
67
  # end
67
68
  #
68
69
  # foo = Foo.new
@@ -118,7 +119,14 @@ module ActiveFedora
118
119
  # @param [Symbol] field the field to query
119
120
  # @return [Boolean]
120
121
  def unique?(field)
121
- delegates[field][:unique]
122
+ !multiple?(field)
123
+ end
124
+
125
+ # Reveal if the delegated field is multivalued or not
126
+ # @param [Symbol] field the field to query
127
+ # @return [Boolean]
128
+ def multiple?(field)
129
+ delegates[field][:multiple]
122
130
  end
123
131
 
124
132
  private
@@ -138,11 +146,33 @@ module ActiveFedora
138
146
  end
139
147
  end
140
148
 
141
- self.delegates[field][:unique] = args[:unique]
149
+ if !args[:multiple].nil?
150
+ self.delegates[field][:multiple] = args[:multiple]
151
+ elsif !args[:unique].nil?
152
+ i = 0
153
+ begin
154
+ match = /in `(delegate.*)'/.match(caller[i])
155
+ i+=1
156
+ end while match.nil?
157
+
158
+ prev_method = match.captures.first
159
+ Deprecation.warn Delegating, "The :unique option for `#{prev_method}' is deprecated. Use :multiple instead. :unique will be removed in ActiveFedora 7", caller(i+1)
160
+ self.delegates[field][:multiple] = !args[:unique]
161
+ else
162
+ i = 0
163
+ begin
164
+ match = /in `(delegate.*)'/.match(caller[i])
165
+ i+=1
166
+ end while match.nil?
167
+
168
+ prev_method = match.captures.first
169
+ Deprecation.warn Delegating, "You have not explicitly set the :multiple option on `#{prev_method}'. The default value will switch from true to false in ActiveFedora 7, so if you want to future-proof this application set `multiple: true'", caller(i+ 1)
170
+ self.delegates[field][:multiple] = true # this should be false for ActiveFedora 7
171
+ end
142
172
 
143
173
  define_method field do |*opts|
144
174
  val = array_reader(field, *opts)
145
- self.class.unique?(field) ? val.first : val
175
+ self.class.multiple?(field) ? val : val.first
146
176
  end
147
177
  end
148
178
 
@@ -98,6 +98,10 @@ module ActiveFedora
98
98
  '"' + value.gsub(/(:)/, '\\:').gsub(/(\/)/, '\\/').gsub(/"/, '\\"') + '"'
99
99
  end
100
100
 
101
+
102
+ extend Deprecation
103
+ self.deprecation_horizon = 'active-fedora 7.0.0'
104
+
101
105
  # Retrieve the Fedora object with the given pid, explore the returned object, determine its model
102
106
  # using #{ActiveFedora::ContentModel.known_models_for} and cast to that class.
103
107
  # Raises a ObjectNotFoundError if the object is not found.
@@ -106,7 +110,11 @@ module ActiveFedora
106
110
  #
107
111
  # @example because the object hydra:dataset1 asserts it is a Dataset (hasModel info:fedora/afmodel:Dataset), return a Dataset object (not a Book).
108
112
  # Book.find_one("hydra:dataset1")
109
- def find_one(pid, cast=false)
113
+ def find_one(pid, cast=nil)
114
+ if cast.nil?
115
+ cast = false
116
+ Deprecation.warn(Querying, "find_one's cast parameter will default to true", caller)
117
+ end
110
118
  inner = DigitalObject.find(self, pid)
111
119
  af_base = self.allocate.init_with(inner)
112
120
  cast ? af_base.adapt_to_cmodel : af_base
@@ -1,6 +1,6 @@
1
1
  module ActiveFedora
2
2
  class Relation
3
-
3
+ extend Deprecation
4
4
  delegate :map, :each, :collect, :all?, :include?, :to => :to_a
5
5
 
6
6
  attr_reader :loaded
@@ -90,7 +90,10 @@ module ActiveFedora
90
90
  relation.order_values += args.flatten
91
91
  relation
92
92
  end
93
-
93
+
94
+ extend Deprecation
95
+ self.deprecation_horizon = 'active-fedora 7.0.0'
96
+
94
97
  # Returns an Array of objects of the Class that +find+ is being
95
98
  # called on
96
99
  #
@@ -102,6 +105,9 @@ module ActiveFedora
102
105
  options = args.extract_options!
103
106
 
104
107
  # TODO is there any reason not to cast?
108
+ if !options.has_key?(:cast)
109
+ Deprecation.warn(Relation, "find's cast option will default to true", caller)
110
+ end
105
111
  cast = options.delete(:cast)
106
112
  if options[:sort]
107
113
  # Deprecate sort sometime?
@@ -116,6 +122,7 @@ module ActiveFedora
116
122
  else
117
123
  case args.first
118
124
  when :first, :last, :all
125
+ Deprecation.warn Relation, "ActiveFedora::Base.find(#{args.first.inspect}) is deprecated. Use ActiveFedora::Base.#{args.first} instead. This option will be removed in ActiveFedora 7", caller
119
126
  send(args.first)
120
127
  else
121
128
  find_with_ids(args, cast)
@@ -51,11 +51,28 @@ module ActiveFedora
51
51
  classname.send(method, hit[SOLR_DOCUMENT_ID])
52
52
  end
53
53
 
54
- def self.class_from_solr_document(hit)
55
- model_value = nil
56
- hit[solr_name("has_model", :symbol)].each {|value| model_value ||= Model.from_class_uri(value)}
57
- logger.warn "Could not find a model for #{hit["id"]}, defaulting to ActiveFedora::Base" unless model_value
58
- model_value || ActiveFedora::Base
54
+ def self.class_from_solr_document(hit, opts = {})
55
+ #Set the default starting point to the class specified, if available.
56
+ best_model_match = Model.from_class_uri(opts[:class]) unless opts[:class].nil?
57
+
58
+ hit[solr_name("has_model", :symbol)].each do |value|
59
+
60
+ model_value = Model.from_class_uri(value)
61
+
62
+ if model_value
63
+
64
+ # Set as the first model in case opts[:class] was nil
65
+ best_model_match ||= model_value
66
+
67
+ # If there is an inheritance structure, use the most specific case.
68
+ if best_model_match > model_value
69
+ best_model_match = model_value
70
+ end
71
+ end
72
+ end
73
+
74
+ logger.warn "Could not find a model for #{hit["id"]}, defaulting to ActiveFedora::Base" unless best_model_match
75
+ best_model_match || ActiveFedora::Base
59
76
  end
60
77
 
61
78
  # Construct a solr query for a list of pids
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "6.5.1"
2
+ VERSION = "6.6.0.pre1"
3
3
  end
@@ -15,6 +15,9 @@ describe ActiveFedora::Base do
15
15
  has_and_belongs_to_many :collections, :property=>:is_member_of_collection
16
16
  end
17
17
 
18
+ class SpecialInheritedBook < Book
19
+ end
20
+
18
21
  class Person < ActiveFedora::Base
19
22
  end
20
23
 
@@ -35,6 +38,7 @@ describe ActiveFedora::Base do
35
38
  Object.send(:remove_const, :Person)
36
39
  Object.send(:remove_const, :Collection)
37
40
  Object.send(:remove_const, :Topic)
41
+ Object.send(:remove_const, :SpecialInheritedBook)
38
42
  end
39
43
 
40
44
  describe "an unsaved instance" do
@@ -178,6 +182,7 @@ describe ActiveFedora::Base do
178
182
  @topic1 = Topic.create
179
183
  @topic2 = Topic.create
180
184
  @book = Book.create
185
+ @special_book = SpecialInheritedBook.create
181
186
  end
182
187
  it "habtm should set and remove relationships bidirectionally" do
183
188
  @book.topics << @topic1
@@ -201,9 +206,23 @@ describe ActiveFedora::Base do
201
206
  book2.topics.count.should == 12
202
207
  end
203
208
 
209
+ it "Should find inherited objects along with base objects" do
210
+ @book.topics << @topic1
211
+ @special_book.topics << @topic1
212
+ @topic1.books.should == [@book, @special_book]
213
+ @topic1.reload.books.should == [@book, @special_book]
214
+ end
215
+
216
+ it "Should cast found books to the correct cmodel" do
217
+ @topic1.books[0].class == Book
218
+ @topic1.books[1].class == SpecialInheritedBook
219
+ end
220
+
204
221
  after do
205
222
  @topic1.delete
206
223
  @topic2.delete
224
+ @book.delete
225
+ @special_book.delete
207
226
  end
208
227
  end
209
228
  end
@@ -282,6 +301,28 @@ describe ActiveFedora::Base do
282
301
  end
283
302
  end
284
303
 
304
+ describe "when dealing with inherited objects" do
305
+ before do
306
+ @library2 = Library.create
307
+ @special_book = SpecialInheritedBook.create
308
+
309
+ @book.library = @library2
310
+ @book.save
311
+ @special_book.library = @library2
312
+ @special_book.save
313
+ end
314
+
315
+ it "should cast to the most specific class for the association" do
316
+ @library2.books[0].class == Book
317
+ @library2.books[1].class == SpecialInheritedBook
318
+ end
319
+
320
+ after do
321
+ @library2.delete
322
+ @special_book.delete
323
+ end
324
+ end
325
+
285
326
  after do
286
327
  @library.delete
287
328
  @book.delete
@@ -727,4 +768,96 @@ describe ActiveFedora::Base do
727
768
  end
728
769
  end
729
770
  end
771
+
772
+ describe "casting inheritance additional test cases" do
773
+ describe "for habtm" do
774
+ before :all do
775
+ class SimpleObject < ActiveFedora::Base
776
+ belongs_to :simple_collection, property: :is_part_of, class_name: 'SimpleCollection'
777
+ belongs_to :complex_collection, property: :is_part_of, class_name: 'ComplexCollection'
778
+ end
779
+
780
+ class ComplexObject < SimpleObject
781
+ end
782
+
783
+ class SimpleCollection < ActiveFedora::Base
784
+ has_many :objects, property: :is_part_of, class_name: 'SimpleObject'
785
+ has_many :complex_objects, property: :is_part_of, class_name: 'ComplexObject'
786
+ end
787
+
788
+ class ComplexCollection < SimpleCollection
789
+ end
790
+
791
+ end
792
+ after :all do
793
+ Object.send(:remove_const, :SimpleObject)
794
+ Object.send(:remove_const, :ComplexObject)
795
+ Object.send(:remove_const, :SimpleCollection)
796
+ Object.send(:remove_const, :ComplexCollection)
797
+ end
798
+
799
+ describe "saving between the before and after hooks" do
800
+ before do
801
+ @simple_collection = SimpleCollection.create
802
+ @complex_collection = ComplexCollection.create
803
+
804
+ #Need to add the simpler cmodel here as currently inheritance support is read-only.
805
+ #See ActiveFedora pull request 207 on how to do this programmatically.
806
+ @complex_collection.add_relationship(:has_model, @complex_object.class.superclass.to_class_uri)
807
+
808
+ @simple_object = SimpleObject.create
809
+ @simple_object_second = SimpleObject.create
810
+ @complex_object = ComplexObject.create
811
+
812
+ #Need to add the simpler cmodel here as currently inheritance support is read-only.
813
+ #See ActiveFedora pull request 207 on how to do this programmatically.
814
+ @complex_object.add_relationship(:has_model, @complex_object.class.superclass.to_class_uri)
815
+
816
+ @simple_collection.objects = [@simple_object, @simple_object_second, @complex_object]
817
+ @simple_collection.save!
818
+ @complex_collection.objects = [@simple_object, @complex_object]
819
+ @complex_collection.save!
820
+ @complex_object.save!
821
+ @simple_object.save!
822
+ @simple_object_second.save!
823
+ end
824
+
825
+
826
+ it "casted association methods should work and return the most complex class" do
827
+ @complex_object.simple_collection.should be_instance_of SimpleCollection
828
+ @complex_object.complex_collection.should be_instance_of ComplexCollection
829
+
830
+ @simple_object.simple_collection.should be_instance_of SimpleCollection
831
+ @simple_object.complex_collection.should be_instance_of ComplexCollection
832
+ @simple_object_second.simple_collection.should be_instance_of SimpleCollection
833
+ @simple_object_second.complex_collection.should be_nil
834
+
835
+ @complex_collection.objects[0].should be_instance_of SimpleObject
836
+ @complex_collection.objects[1].should be_instance_of ComplexObject
837
+
838
+ @simple_collection.objects[0].should be_instance_of SimpleObject
839
+ @simple_collection.objects[1].should be_instance_of SimpleObject
840
+ @simple_collection.objects[2].should be_instance_of ComplexObject
841
+
842
+ end
843
+
844
+ it "specified ending relationships should ignore classes not specified" do
845
+ @complex_collection.complex_objects.length.should == 1
846
+ @complex_collection.complex_objects[0].should be_instance_of ComplexObject
847
+ @complex_collection.complex_objects[1].should be_nil
848
+
849
+ @simple_collection.complex_objects.length.should == 1
850
+ @simple_collection.complex_objects[0].should be_instance_of ComplexObject
851
+ @simple_collection.complex_objects[1].should be_nil
852
+
853
+ end
854
+
855
+ after do
856
+ @simple_object.delete
857
+ @simple_object_second.delete
858
+ @complex_object.delete
859
+ end
860
+ end
861
+ end
862
+ end
730
863
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'timeout'
3
+
4
+ describe "fedora_solr_sync_issues" do
5
+ before :all do
6
+ class ParentThing < ActiveFedora::Base
7
+ has_many :things, :class_name=>'ChildThing', :property=>:is_part_of
8
+ end
9
+
10
+ class ChildThing < ActiveFedora::Base
11
+ belongs_to :parent, :class_name=>'ParentThing', :property=>:is_part_of
12
+ end
13
+ end
14
+
15
+ after :all do
16
+ Object.send(:remove_const, :ChildThing)
17
+ Object.send(:remove_const, :ParentThing)
18
+ end
19
+
20
+ let(:parent) { ParentThing.create }
21
+ subject { ChildThing.create :parent => parent }
22
+
23
+ it "should not go into an infinite loop" do
24
+ subject.inner_object.delete
25
+ parent.reload
26
+ parent.things.should == []
27
+ end
28
+ end
@@ -44,6 +44,9 @@ describe ActiveFedora::Model do
44
44
  end
45
45
  describe "#find with a valid pid without cast" do
46
46
  subject { ActiveFedora::Base.find(@test_instance.pid) }
47
+ before(:each) do
48
+ Deprecation.should_receive(:warn).at_least(1).times
49
+ end
47
50
  it { should be_instance_of ActiveFedora::Base}
48
51
  end
49
52
  end
@@ -8,8 +8,8 @@ describe "NestedAttribute behavior" do
8
8
  m.field "uno", :string
9
9
  m.field "dos", :string
10
10
  end
11
- delegate :uno, :to=>'someData', :unique=>true
12
- delegate :dos, :to=>'someData', :unique=>true
11
+ delegate :uno, to: 'someData', multiple: false
12
+ delegate :dos, to: 'someData', multiple: false
13
13
  end
14
14
 
15
15
  # base Car class, used in test for association updates and :allow_destroy flag
@@ -18,8 +18,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
18
18
  end
19
19
  class RdfTest < ActiveFedora::Base
20
20
  has_metadata :name=>'rdf', :type=>MyDatastream
21
- delegate_to 'rdf', [:based_near, :related_url, :part, :date_uploaded]
22
- delegate :title, :to=>'rdf', :unique=>true
21
+ delegate_to 'rdf', [:based_near, :related_url, :part, :date_uploaded], multiple: true
22
+ delegate :title, to: 'rdf', multiple: false
23
23
  end
24
24
  @subject = RdfTest.new
25
25
  end
@@ -198,7 +198,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
198
198
  end
199
199
  class Foobar < ActiveFedora::Base
200
200
  has_metadata :name=>'rdf', :type=>TitleDatastream
201
- delegate :title, :to=>'rdf'
201
+ delegate :title, :to=>'rdf', multiple: true
202
202
  end
203
203
  @subject = Foobar.new
204
204
  @subject.title = ["title1", "title2", "title3"]
@@ -6,8 +6,8 @@ describe "persisting objects" do
6
6
  has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"foo" do |m|
7
7
  m.field "name", :string
8
8
  end
9
- delegate :name, :to=>'foo', :unique=>true
10
- validates :name, :presence=>true
9
+ delegate :name, to: 'foo', multiple: false
10
+ validates :name, presence: true
11
11
  end
12
12
  end
13
13
  after :all do
@@ -11,7 +11,7 @@ describe ActiveFedora::Model do
11
11
  m.field "baz", :string
12
12
  end
13
13
 
14
- delegate_to :properties, [:foo, :bar, :baz]
14
+ delegate_to :properties, [:foo, :bar, :baz], multiple: true
15
15
 
16
16
  def to_solr(doc = {})
17
17
  doc = super
@@ -11,7 +11,7 @@ describe ActiveFedora::Model do
11
11
  m.field "baz", :string
12
12
  end
13
13
 
14
- delegate_to :properties, [:foo, :bar, :baz]
14
+ delegate_to :properties, [:foo, :bar, :baz], multiple: true
15
15
 
16
16
  def to_solr(doc = {})
17
17
  doc = super
@@ -28,8 +28,8 @@ describe ActiveFedora::Base do
28
28
  end
29
29
 
30
30
  has_metadata :type=>BarStream, :name=>"xmlish"
31
- delegate :fubar, :to=>'withText', :unique=>true
32
- delegate :duck, :to=>'xmlish', :unique=>true
31
+ delegate :fubar, to: 'withText', multiple: false
32
+ delegate :duck, to: 'xmlish', multiple: false
33
33
  end
34
34
  before :each do
35
35
  @n = BarHistory.new()
@@ -12,6 +12,8 @@ describe ActiveFedora::Base do
12
12
  end
13
13
  t.donkey()
14
14
  t.cow()
15
+ t.pig()
16
+ t.horse()
15
17
  end
16
18
 
17
19
  def self.xml_template
@@ -49,8 +51,10 @@ describe ActiveFedora::Base do
49
51
  has_metadata :type=>BarStream2, :name=>"xmlish"
50
52
  delegate :fubar, :to=>'withText', :unique=>true
51
53
  delegate :donkey, :to=>'xmlish', :unique=>true
52
- delegate :cow, :to=>'xmlish'
53
- delegate :duck, :to=>'xmlish', :at=>[:waterfowl, :ducks]
54
+ delegate :cow, :to=>'xmlish' # for testing the default value of multiple
55
+ delegate :pig, :to=>'xmlish', multiple: false
56
+ delegate :horse, :to=>'xmlish', multiple: true
57
+ delegate :duck, :to=>'xmlish', :at=>[:waterfowl, :ducks], multiple: true
54
58
  end
55
59
  end
56
60
 
@@ -72,6 +76,9 @@ describe ActiveFedora::Base do
72
76
  subject.donkey="Bray"
73
77
  subject.donkey.should == "Bray"
74
78
  subject.xmlish.term_values(:donkey).first.should == 'Bray'
79
+
80
+ subject.pig="Oink"
81
+ subject.pig.should == "Oink"
75
82
  end
76
83
 
77
84
  it "should allow passing parameters to the delegate accessor" do
@@ -84,6 +91,9 @@ describe ActiveFedora::Base do
84
91
  ### Metadata datastream does not appear to support multiple value setting
85
92
  subject.cow=["one", "two"]
86
93
  subject.cow.should == ["one", "two"]
94
+
95
+ subject.horse=["neigh", "whinny"]
96
+ subject.horse.should == ["neigh", "whinny"]
87
97
  end
88
98
 
89
99
  it "should be able to delegate deeply into the terminology" do
@@ -123,7 +133,7 @@ describe ActiveFedora::Base do
123
133
  before :all do
124
134
  class BarHistory2 < ActiveFedora::Base
125
135
  has_metadata 'xmlish', :type=>BarStream2
126
- delegate_to 'xmlish', [:donkey, :cow]
136
+ delegate_to 'xmlish', [:donkey, :cow], multiple: true
127
137
  end
128
138
  class BarHistory3 < BarHistory2
129
139
  end
@@ -158,7 +168,7 @@ describe ActiveFedora::Base do
158
168
  end
159
169
  class BarHistory4 < ActiveFedora::Base
160
170
  has_metadata 'rdfish', :type=>BarRdfDatastream
161
- delegate_to 'rdfish', [:title, :description]
171
+ delegate_to 'rdfish', [:title, :description], multiple: true
162
172
  end
163
173
  end
164
174
 
@@ -37,7 +37,7 @@ describe ActiveFedora::Base do
37
37
 
38
38
  class Barnyard < ActiveFedora::Base
39
39
  has_metadata :type=>BarnyardDocument, :name=>"xmlish"
40
- delegate_to :xmlish, [:cow, :chicken, :pig, :duck]
40
+ delegate_to :xmlish, [:cow, :chicken, :pig, :duck], multiple: true
41
41
  delegate_to :xmlish, [:donkey, :horse], :unique=>true
42
42
  #delegate :donkey, :to=>'xmlish', :unique=>true
43
43
  end
@@ -28,7 +28,7 @@ describe ActiveFedora::Base do
28
28
  end
29
29
  describe "assign_pid" do
30
30
  it "should use fedora to generate pids" do
31
- # TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
31
+ # TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
32
32
  # possibly wrap it all into a fedora_connection method - MZ 06-05-2012
33
33
  stubfedora = double("Fedora")
34
34
  stubfedora.should_receive(:connection).and_return(double("Connection", :mint =>"sample:newpid"))
@@ -125,21 +125,26 @@ describe ActiveFedora::Base do
125
125
  has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel", :autocreate => true do |m|
126
126
  m.field "fubar", :text
127
127
  end
128
- delegate :fubar, :to=>'withText'
129
- delegate :swank, :to=>'someData'
128
+ delegate :fubar, :to=>'withText', multiple: true
129
+ delegate :swank, :to=>'someData', multiple: true
130
130
  end
131
131
  class FooAdaptation < ActiveFedora::Base
132
132
  has_metadata :type=>ActiveFedora::OmDatastream, :name=>'someData'
133
133
  end
134
+
135
+ class FooInherited < FooHistory
136
+
137
+ end
134
138
  end
135
139
 
136
140
  after :all do
137
141
  Object.send(:remove_const, :FooHistory)
138
142
  Object.send(:remove_const, :FooAdaptation)
143
+ Object.send(:remove_const, :FooInherited)
139
144
  end
140
-
145
+
141
146
  def increment_pid
142
- @@last_pid += 1
147
+ @@last_pid += 1
143
148
  end
144
149
 
145
150
  before(:each) do
@@ -161,11 +166,11 @@ describe ActiveFedora::Base do
161
166
 
162
167
 
163
168
  describe '#new' do
164
- it "should create an inner object" do
169
+ it "should create an inner object" do
165
170
  # for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
166
171
  Rubydora::DigitalObject.any_instance.should_receive(:save).never
167
- result = ActiveFedora::Base.new(nil)
168
- result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
172
+ result = ActiveFedora::Base.new(nil)
173
+ result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
169
174
  end
170
175
 
171
176
  it "should not save or get an pid on init" do
@@ -203,7 +208,7 @@ describe ActiveFedora::Base do
203
208
  @test_object.to_param.should == @test_object.pid
204
209
  end
205
210
 
206
- it "should have to_key once it's saved" do
211
+ it "should have to_key once it's saved" do
207
212
  @test_object.to_key.should be_nil
208
213
  @test_object.inner_object.stub(:new? => false)
209
214
  @test_object.to_key.should == [@test_object.pid]
@@ -219,8 +224,8 @@ describe ActiveFedora::Base do
219
224
  FooHistory.model_name.should == 'FooHistory'
220
225
  FooHistory.model_name.human.should == 'Foo history'
221
226
  end
222
- ### End ActiveModel::Naming
223
-
227
+ ### End ActiveModel::Naming
228
+
224
229
 
225
230
  describe ".datastreams" do
226
231
  before do
@@ -272,7 +277,7 @@ describe ActiveFedora::Base do
272
277
  describe '#add_relationship' do
273
278
  it 'should call #add_relationship on the rels_ext datastream' do
274
279
  @test_object.add_relationship("predicate", "info:fedora/object")
275
- pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
280
+ pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
276
281
  @test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
277
282
  end
278
283
 
@@ -283,7 +288,7 @@ describe ActiveFedora::Base do
283
288
  @test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
284
289
  @test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
285
290
  end
286
-
291
+
287
292
  it 'should add a relationship to an object only if it does not exist already' do
288
293
  next_pid = increment_pid.to_s
289
294
  ActiveFedora::Base.stub(:assign_pid).and_return(next_pid)
@@ -302,11 +307,11 @@ describe ActiveFedora::Base do
302
307
  @test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
303
308
  end
304
309
  end
305
-
310
+
306
311
  it 'should provide #remove_relationship' do
307
312
  @test_object.should respond_to(:remove_relationship)
308
313
  end
309
-
314
+
310
315
  describe '#remove_relationship' do
311
316
  it 'should remove a relationship from the relationships hash' do
312
317
  @test_object3 = ActiveFedora::Base.new()
@@ -333,7 +338,7 @@ describe ActiveFedora::Base do
333
338
  describe '#relationships' do
334
339
  it 'should return a graph' do
335
340
  @test_object.relationships.kind_of?(RDF::Graph).should be_true
336
- @test_object.relationships.size.should == 0
341
+ @test_object.relationships.size.should == 0
337
342
  end
338
343
  end
339
344
 
@@ -343,7 +348,7 @@ describe ActiveFedora::Base do
343
348
  stub_add_ds(@this_pid, ['RELS-EXT'])
344
349
  @test_object.assert_content_model
345
350
  @test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
346
-
351
+
347
352
  end
348
353
  end
349
354
 
@@ -352,14 +357,14 @@ describe ActiveFedora::Base do
352
357
  @test_object.stub(:new_record? => true)
353
358
  @test_object.should_receive(:create)
354
359
  @test_object.should_receive(:update_index)
355
- @test_object.save
360
+ @test_object.save
356
361
  end
357
362
 
358
363
  it "should update an existing record" do
359
364
  @test_object.stub(:new_record? => false)
360
365
  @test_object.should_receive(:update_record)
361
366
  @test_object.should_receive(:update_index)
362
- @test_object.save
367
+ @test_object.save
363
368
  end
364
369
  end
365
370
 
@@ -370,7 +375,7 @@ describe ActiveFedora::Base do
370
375
  FooHistory.should_receive(:new).and_return(obj)
371
376
  @hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
372
377
  end
373
-
378
+
374
379
  end
375
380
 
376
381
  describe ".adapt_to" do
@@ -408,18 +413,33 @@ describe ActiveFedora::Base do
408
413
  end
409
414
  end
410
415
 
411
- describe ".adapt_to_cmodel" do
412
- subject { FooHistory.new }
413
- it "should cast when a cmodel is found" do
414
- ActiveFedora::ContentModel.should_receive(:known_models_for).with( subject).and_return([FooAdaptation])
415
- subject.adapt_to_cmodel.should be_kind_of FooAdaptation
416
+ describe ".adapt_to_cmodel with implemented (non-ActiveFedora::Base) cmodel" do
417
+ subject { FooHistory.new }
418
+
419
+ it "should not cast to a random first cmodel if it has a specific cmodel already" do
420
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation])
421
+ subject.adapt_to_cmodel.should be_kind_of FooHistory
422
+ end
423
+ it "should cast to an inherited model over a random one" do
424
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooInherited])
425
+ subject.adapt_to_cmodel.should be_kind_of FooInherited
416
426
  end
417
427
  it "should not cast when a cmodel is same as the class" do
418
- ActiveFedora::ContentModel.should_receive(:known_models_for).with( subject).and_return([FooHistory])
428
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooHistory])
419
429
  subject.adapt_to_cmodel.should === subject
420
430
  end
421
431
  end
422
432
 
433
+ describe ".adapt_to_cmodel with ActiveFedora::Base" do
434
+ subject { ActiveFedora::Base.new }
435
+
436
+ it "should cast to the first cmodel if ActiveFedora::Base (or no specified cmodel)" do
437
+ ActiveFedora::ContentModel.should_receive(:known_models_for).with(subject).and_return([FooAdaptation, FooHistory])
438
+ subject.adapt_to_cmodel.should be_kind_of FooAdaptation
439
+ end
440
+ end
441
+
442
+
423
443
  describe ".to_solr" do
424
444
  it "should provide .to_solr" do
425
445
  @test_object.should respond_to(:to_solr)
@@ -444,7 +464,7 @@ describe ActiveFedora::Base do
444
464
  solr_doc["id"].should be_nil
445
465
  solr_doc[ActiveFedora::SolrService.solr_name("has_part", :symbol)].should be_nil
446
466
  end
447
-
467
+
448
468
  it "should add self.class as the :active_fedora_model" do
449
469
  stub_get(@this_pid)
450
470
  stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
@@ -460,7 +480,7 @@ describe ActiveFedora::Base do
460
480
  ngds.should_receive(:solrize_profile)
461
481
  mock1.should_receive(:solrize_profile)
462
482
  mock2.should_receive(:solrize_profile)
463
-
483
+
464
484
  @test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
465
485
  @test_object.should_receive(:solrize_relationships)
466
486
  @test_object.to_solr
@@ -468,7 +488,7 @@ describe ActiveFedora::Base do
468
488
  it "should call .to_solr on all RDFDatastreams, passing the resulting document to solr" do
469
489
  mock = double("ds1", :to_solr => {})
470
490
  mock.should_receive(:solrize_profile)
471
-
491
+
472
492
  @test_object.should_receive(:datastreams).twice.and_return({:ds1 => mock})
473
493
  @test_object.should_receive(:solrize_relationships)
474
494
  @test_object.to_solr
@@ -481,16 +501,16 @@ describe ActiveFedora::Base do
481
501
  @test_object.should_receive(:solrize_relationships)
482
502
  @test_object.to_solr
483
503
  end
484
-
504
+
485
505
  end
486
506
 
487
507
  describe ".label" do
488
- it "should return the label of the inner object" do
508
+ it "should return the label of the inner object" do
489
509
  @test_object.inner_object.should_receive(:label).and_return("foo label")
490
510
  @test_object.label.should == "foo label"
491
511
  end
492
512
  end
493
-
513
+
494
514
  describe ".label=" do
495
515
  it "should set the label of the inner object" do
496
516
  @test_object.label.should_not == "foo label"
@@ -498,8 +518,8 @@ describe ActiveFedora::Base do
498
518
  @test_object.label.should == "foo label"
499
519
  end
500
520
  end
501
-
502
-
521
+
522
+
503
523
  describe "get_values_from_datastream" do
504
524
  it "should look up the named datastream and call get_values with the given pointer/field_name" do
505
525
  mock_ds = double("Datastream", :get_values=>["value1", "value2"])
@@ -507,13 +527,13 @@ describe ActiveFedora::Base do
507
527
  @test_object.get_values_from_datastream("ds1", "--my xpath--").should == ["value1", "value2"]
508
528
  end
509
529
  end
510
-
530
+
511
531
  describe "update_datastream_attributes" do
512
532
  it "should look up any datastreams specified as keys in the given hash and call update_attributes on the datastream" do
513
533
  mock_desc_metadata = double("descMetadata")
514
534
  mock_properties = double("properties")
515
535
  mock_ds_hash = {'descMetadata'=>mock_desc_metadata, 'properties'=>mock_properties}
516
-
536
+
517
537
  ds_values_hash = {
518
538
  "descMetadata"=>{ [{:person=>0}, :role]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} },
519
539
  "properties"=>{ "notes"=>"foo" }
@@ -535,12 +555,12 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
535
555
  m.to_xml.should == untouched_xml
536
556
  end
537
557
  end
538
-
558
+
539
559
  describe "update_attributes" do
540
560
  it "should set the attributes and save" do
541
561
  m = FooHistory.new
542
562
  att= {"fubar"=> '1234', "baz" =>'stuff'}
543
-
563
+
544
564
  m.should_receive(:fubar=).with('1234')
545
565
  m.should_receive(:baz=).with('stuff')
546
566
  m.should_receive(:save)
@@ -552,14 +572,14 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
552
572
  it "should set the attributes and save" do
553
573
  m = FooHistory.new
554
574
  att= {"fubar"=> '1234', "baz" =>'stuff'}
555
-
575
+
556
576
  m.should_receive(:fubar=).with('1234')
557
577
  m.should_receive(:baz=).with('stuff')
558
578
  m.should_receive(:save)
559
579
  m.update(att)
560
580
  end
561
581
  end
562
-
582
+
563
583
  describe "update_indexed_attributes" do
564
584
  before do
565
585
  Deprecation.should_receive(:warn).at_least(1).times
@@ -567,13 +587,13 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
567
587
  it "should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams" do
568
588
  m = FooHistory.new
569
589
  att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
570
-
590
+
571
591
  m.datastreams['someData'].should_receive(:update_indexed_attributes)
572
592
  m.datastreams["withText"].should_receive(:update_indexed_attributes)
573
593
  m.datastreams['withText2'].should_receive(:update_indexed_attributes)
574
594
  m.update_indexed_attributes(att)
575
595
  end
576
- it "should take a :datastreams argument" do
596
+ it "should take a :datastreams argument" do
577
597
  att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
578
598
  stub_get(@this_pid)
579
599
  stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
@@ -583,7 +603,7 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
583
603
  m.datastreams['someData'].fubar.should == []
584
604
  m.datastreams["withText"].fubar.should == ['mork', 'york', 'mangle']
585
605
  m.datastreams['withText2'].fubar.should == []
586
-
606
+
587
607
  att= {"fubar"=>{"-1"=>"tork", "0"=>"work", "1"=>"bork"}}
588
608
  m.update_indexed_attributes(att, :datastreams=>["someData", "withText2"])
589
609
  m.should_not be_nil
@@ -7,8 +7,8 @@ describe ActiveFedora::Base do
7
7
  m.field "fubar", :string
8
8
  m.field "swank", :text
9
9
  end
10
- delegate :fubar, :to=>'someData'
11
- delegate :swank, :to=>'someData'
10
+ delegate :fubar, :to=>'someData', multiple: true
11
+ delegate :swank, :to=>'someData', multiple: true
12
12
 
13
13
  after_initialize :a_init
14
14
  before_save :b_save
@@ -200,12 +200,12 @@ describe ActiveFedora::NtriplesRDFDatastream do
200
200
  before(:each) do
201
201
  class Foo < ActiveFedora::Base
202
202
  has_metadata :name => "descMetadata", :type => MyDatastream
203
- delegate :created, :to => :descMetadata
204
- delegate :title, :to => :descMetadata
205
- delegate :publisher, :to => :descMetadata
206
- delegate :based_near, :to => :descMetadata
207
- delegate :related_url, :to => :descMetadata
208
- delegate :rights, :to => :descMetadata
203
+ delegate :created, :to => :descMetadata, multiple: true
204
+ delegate :title, :to => :descMetadata, multiple: true
205
+ delegate :publisher, :to => :descMetadata, multiple: true
206
+ delegate :based_near, :to => :descMetadata, multiple: true
207
+ delegate :related_url, :to => :descMetadata, multiple: true
208
+ delegate :rights, :to => :descMetadata, multiple: true
209
209
  end
210
210
  @obj = MyDatastream.new(@inner_object, 'solr_rdf')
211
211
  repository = double()
@@ -15,6 +15,15 @@ describe ActiveFedora::Base do
15
15
  Object.send(:remove_const, :SpecModel)
16
16
  end
17
17
 
18
+ describe '#find_one' do
19
+ it 'should notify of deprecation if no cast parameter is passed' do
20
+ Deprecation.should_receive(:warn).at_least(1).times
21
+ expect {
22
+ ActiveFedora::Base.find_one('_PID_')
23
+ }.to raise_error(ActiveFedora::ObjectNotFoundError)
24
+ end
25
+ end
26
+
18
27
  describe '#find' do
19
28
  describe "without :cast" do
20
29
  describe ":all" do
@@ -7,8 +7,8 @@ describe ActiveFedora::Base do
7
7
  m.field "fubar", :string
8
8
  m.field "swank", :text
9
9
  end
10
- delegate :fubar, :to=>'someData'
11
- delegate :swank, :to=>'someData', unique: true
10
+ delegate :fubar, :to=>'someData', multiple: true
11
+ delegate :swank, :to=>'someData', multiple: false
12
12
 
13
13
  validates_presence_of :fubar
14
14
  validates_length_of :swank, :minimum=>5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.5.1
4
+ version: 6.6.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-10 00:00:00.000000000 Z
13
+ date: 2013-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -422,6 +422,7 @@ files:
422
422
  - spec/integration/datastreams_spec.rb
423
423
  - spec/integration/delegating_spec.rb
424
424
  - spec/integration/delete_all_spec.rb
425
+ - spec/integration/fedora_solr_sync_spec.rb
425
426
  - spec/integration/full_featured_model_spec.rb
426
427
  - spec/integration/has_many_associations_spec.rb
427
428
  - spec/integration/model_spec.rb
@@ -549,12 +550,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
549
550
  version: 1.9.3
550
551
  required_rubygems_version: !ruby/object:Gem::Requirement
551
552
  requirements:
552
- - - '>='
553
+ - - '>'
553
554
  - !ruby/object:Gem::Version
554
- version: '0'
555
+ version: 1.3.1
555
556
  requirements: []
556
557
  rubyforge_project:
557
- rubygems_version: 2.0.3
558
+ rubygems_version: 2.0.5
558
559
  signing_key:
559
560
  specification_version: 4
560
561
  summary: A convenience libary for manipulating documents in the Fedora Repository.
@@ -586,6 +587,7 @@ test_files:
586
587
  - spec/integration/datastreams_spec.rb
587
588
  - spec/integration/delegating_spec.rb
588
589
  - spec/integration/delete_all_spec.rb
590
+ - spec/integration/fedora_solr_sync_spec.rb
589
591
  - spec/integration/full_featured_model_spec.rb
590
592
  - spec/integration/has_many_associations_spec.rb
591
593
  - spec/integration/model_spec.rb