active-fedora 2.3.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -1
- data/Gemfile.lock +16 -10
- data/History.txt +4 -5
- data/README.textile +1 -1
- data/active-fedora.gemspec +2 -2
- data/lib/active_fedora.rb +36 -19
- data/lib/active_fedora/associations.rb +157 -0
- data/lib/active_fedora/associations/association_collection.rb +180 -0
- data/lib/active_fedora/associations/association_proxy.rb +177 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +36 -0
- data/lib/active_fedora/associations/has_many_association.rb +52 -0
- data/lib/active_fedora/attribute_methods.rb +8 -0
- data/lib/active_fedora/base.rb +76 -80
- data/lib/active_fedora/datastream.rb +0 -1
- data/lib/active_fedora/delegating.rb +53 -0
- data/lib/active_fedora/model.rb +4 -2
- data/lib/active_fedora/nested_attributes.rb +153 -0
- data/lib/active_fedora/nokogiri_datastream.rb +17 -18
- data/lib/active_fedora/reflection.rb +140 -0
- data/lib/active_fedora/relationships_helper.rb +10 -5
- data/lib/active_fedora/semantic_node.rb +146 -57
- data/lib/active_fedora/solr_service.rb +0 -7
- data/lib/active_fedora/version.rb +1 -1
- data/lib/fedora/connection.rb +75 -111
- data/lib/fedora/repository.rb +14 -28
- data/lib/ruby-fedora.rb +1 -1
- data/spec/integration/associations_spec.rb +139 -0
- data/spec/integration/nested_attribute_spec.rb +40 -0
- data/spec/integration/repository_spec.rb +9 -14
- data/spec/integration/semantic_node_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -3
- data/spec/unit/active_fedora_spec.rb +2 -1
- data/spec/unit/association_proxy_spec.rb +13 -0
- data/spec/unit/base_active_model_spec.rb +61 -0
- data/spec/unit/base_delegate_spec.rb +59 -0
- data/spec/unit/base_spec.rb +45 -58
- data/spec/unit/connection_spec.rb +21 -21
- data/spec/unit/datastream_spec.rb +0 -11
- data/spec/unit/has_many_collection_spec.rb +27 -0
- data/spec/unit/model_spec.rb +1 -1
- data/spec/unit/nokogiri_datastream_spec.rb +3 -29
- data/spec/unit/repository_spec.rb +2 -2
- data/spec/unit/semantic_node_spec.rb +2 -0
- data/spec/unit/solr_service_spec.rb +0 -7
- metadata +36 -15
- data/lib/active_fedora/active_fedora_configuration_exception.rb +0 -2
- data/lib/util/class_level_inheritable_attributes.rb +0 -23
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NestedAttribute behavior" do
|
4
|
+
before do
|
5
|
+
class Bar < ActiveFedora::Base
|
6
|
+
belongs_to :car, :property=>:has_member
|
7
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
8
|
+
m.field "uno", :string
|
9
|
+
m.field "dos", :string
|
10
|
+
end
|
11
|
+
delegate :uno, :to=>'someData', :unique=>true
|
12
|
+
delegate :dos, :to=>'someData', :unique=>true
|
13
|
+
end
|
14
|
+
class Car < ActiveFedora::Base
|
15
|
+
has_many :bars, :property=>:has_member
|
16
|
+
accepts_nested_attributes_for :bars#, :allow_destroy=>true
|
17
|
+
end
|
18
|
+
|
19
|
+
@car = Car.new
|
20
|
+
@car.save
|
21
|
+
@bar1 = Bar.new(:car=>@car)
|
22
|
+
@bar1.save
|
23
|
+
|
24
|
+
@bar2 = Bar.new(:car=>@car)
|
25
|
+
@bar2.save
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should update the child objects" do
|
30
|
+
@car.attributes = {:bars_attributes=>[{:id=>@bar1.pid, :uno=>"bar1 uno"}, {:uno=>"newbar uno"}, {:id=>@bar2.pid, :_destroy=>'1', :uno=>'bar2 uno'}]}
|
31
|
+
Bar.find(@bar1.pid).uno.should == 'bar1 uno'
|
32
|
+
# pending the fix of nested_attributes_options
|
33
|
+
#Bar.find(@bar2.pid).should be_nil
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end
|
@@ -140,8 +140,6 @@ end
|
|
140
140
|
describe Fedora::Repository, "find_objects" do
|
141
141
|
before(:all) do
|
142
142
|
Fedora::Repository.register(ActiveFedora.fedora_config[:url])
|
143
|
-
@mock_response = mock("Response")
|
144
|
-
@mock_response.stubs(:body).returns(sample_response_xml)
|
145
143
|
end
|
146
144
|
|
147
145
|
def fields_to_s(fields)
|
@@ -158,33 +156,31 @@ describe Fedora::Repository, "find_objects" do
|
|
158
156
|
|
159
157
|
it "should include all fields by default" do
|
160
158
|
when_find_objects('label~Image*') { |conn|
|
161
|
-
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
159
|
+
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
162
160
|
}
|
163
161
|
end
|
164
162
|
|
165
163
|
it "should include all fields when :include => :all " do
|
166
164
|
when_find_objects('label~Image*', :include => :all) { |conn|
|
167
|
-
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
165
|
+
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
168
166
|
}
|
169
167
|
end
|
170
168
|
|
171
169
|
it "should fetch results with limit" do
|
172
170
|
when_find_objects('label~Image*', :limit => 10) { |conn|
|
173
|
-
conn.expects(:get).with('/fedora/objects?maxResults=10&query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
171
|
+
conn.expects(:get).with('/fedora/objects?maxResults=10&query=label%7EImage%2A&resultFormat=xml' + fields_to_s(Fedora::ALL_FIELDS))
|
174
172
|
}
|
175
173
|
end
|
176
174
|
|
177
175
|
it "should fetch results with some fields but not :pid" do
|
178
176
|
when_find_objects('label~Image*', :select => [:label, :mDate]) { |conn|
|
179
|
-
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
|
180
|
-
|
177
|
+
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
|
181
178
|
}
|
182
179
|
end
|
183
180
|
|
184
181
|
it "should fetch results with some fields with :pid" do
|
185
182
|
when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
|
186
|
-
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
|
187
|
-
|
183
|
+
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate]))
|
188
184
|
}
|
189
185
|
end
|
190
186
|
|
@@ -207,7 +203,7 @@ describe Fedora::Repository, "find_objects" do
|
|
207
203
|
it "should convert xml response with 0 objectFields into array of FedoraObject" do
|
208
204
|
objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
|
209
205
|
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
|
210
|
-
returns(
|
206
|
+
returns(Fedora::XmlFormat.decode(sample_response_xml))
|
211
207
|
}
|
212
208
|
|
213
209
|
objects.session_token.should == 'aToken'
|
@@ -217,7 +213,7 @@ describe Fedora::Repository, "find_objects" do
|
|
217
213
|
it "should return FedoraObjects with new_object set to false" do
|
218
214
|
objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
|
219
215
|
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
|
220
|
-
returns(
|
216
|
+
returns(Fedora::XmlFormat.decode(sample_response_xml))
|
221
217
|
}
|
222
218
|
objects.each do |obj|
|
223
219
|
obj.should_not be_new_object
|
@@ -228,7 +224,7 @@ describe Fedora::Repository, "find_objects" do
|
|
228
224
|
it "should convert xml response with single objectFields into array of FedoraObject" do
|
229
225
|
objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
|
230
226
|
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
|
231
|
-
returns(
|
227
|
+
returns(Fedora::XmlFormat.decode(sample_response_xml(1)))
|
232
228
|
}
|
233
229
|
|
234
230
|
objects.session_token.should == 'aToken'
|
@@ -238,10 +234,9 @@ describe Fedora::Repository, "find_objects" do
|
|
238
234
|
end
|
239
235
|
|
240
236
|
it "should convert xml response 2 objectFields into array of FedoraObject" do
|
241
|
-
@mock_response.stubs(:body).returns(sample_response_xml(2))
|
242
237
|
objects = when_find_objects('label~Image*', :select => [:pid, :label, :mDate]) { |conn|
|
243
238
|
conn.expects(:get).with('/fedora/objects?query=label%7EImage%2A&resultFormat=xml' + fields_to_s([:pid, :label, :mDate])).
|
244
|
-
returns(
|
239
|
+
returns(Fedora::XmlFormat.decode(sample_response_xml(2)))
|
245
240
|
}
|
246
241
|
|
247
242
|
objects.session_token.should == 'aToken'
|
@@ -6,6 +6,7 @@ describe ActiveFedora::SemanticNode do
|
|
6
6
|
|
7
7
|
before(:all) do
|
8
8
|
class SpecNode
|
9
|
+
include ActiveFedora::RelationshipsHelper
|
9
10
|
include ActiveFedora::SemanticNode
|
10
11
|
has_relationship "collection_members", :has_collection_member
|
11
12
|
end
|
@@ -430,6 +431,7 @@ describe ActiveFedora::SemanticNode do
|
|
430
431
|
#putting this test here instead of relationships_helper because testing that relationships_by_name hash gets refreshed if the relationships hash is changed
|
431
432
|
describe "relationships_by_name" do
|
432
433
|
class MockSemNamedRelationships
|
434
|
+
include ActiveFedora::RelationshipsHelper
|
433
435
|
include ActiveFedora::SemanticNode
|
434
436
|
has_relationship "testing", :has_part
|
435
437
|
has_relationship "testing2", :has_member
|
data/spec/spec_helper.rb
CHANGED
@@ -14,10 +14,8 @@ end
|
|
14
14
|
ENV["RAILS_ENV"] ||= 'test'
|
15
15
|
RAILS_ENV = ENV["RAILS_ENV"]
|
16
16
|
|
17
|
-
logger.level = Logger::WARN if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method
|
18
|
-
|
19
17
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
20
|
-
Dir[File.join(File.dirname(__FILE__)+'/../lib/')+'**/*.rb'].each{|x| require x unless x.match(/railtie.rb$/)}
|
18
|
+
#Dir[File.join(File.dirname(__FILE__)+'/../lib/')+'**/*.rb'].each{|x| require x unless x.match(/railtie.rb$/)}
|
21
19
|
$VERBOSE=nil
|
22
20
|
|
23
21
|
# This loads the Fedora and Solr config info from /config/fedora.yml
|
@@ -26,6 +26,7 @@ describe ActiveFedora do
|
|
26
26
|
it "should use config_options[:environment] if set" do
|
27
27
|
ActiveFedora.expects(:config_options).at_least_once.returns(:environment=>"ballyhoo")
|
28
28
|
ActiveFedora.environment.should eql("ballyhoo")
|
29
|
+
ENV['environment']='test'
|
29
30
|
end
|
30
31
|
|
31
32
|
it "should use Rails.env if no config_options and Rails.env is set" do
|
@@ -243,7 +244,7 @@ describe ActiveFedora do
|
|
243
244
|
#ActiveFedora.config_path.should eql("#{@fake_rails_root}/config/fake_fedora.yml")
|
244
245
|
end
|
245
246
|
it "raises an error if you pass in a non-existant config file" do
|
246
|
-
lambda{ ActiveFedora.init("really_fake_fedora.yml") }.should raise_exception(ActiveFedoraConfigurationException)
|
247
|
+
lambda{ ActiveFedora.init("really_fake_fedora.yml") }.should raise_exception(ActiveFedora::ActiveFedoraConfigurationException)
|
247
248
|
end
|
248
249
|
|
249
250
|
describe "within Rails" do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Associations::AssociationProxy do
|
4
|
+
it "should delegate to_param" do
|
5
|
+
@owner = stub(:new_record? => false)
|
6
|
+
@assoc = ActiveFedora::Associations::AssociationProxy.new(@owner, @reflection)
|
7
|
+
@assoc.expects(:find_target).returns(stub(:to_param => '1234'))
|
8
|
+
@assoc.send(:load_target)
|
9
|
+
@assoc.to_param.should == '1234'
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
|
5
|
+
describe "active model methods" do
|
6
|
+
class BarStream < ActiveFedora::NokogiriDatastream
|
7
|
+
set_terminology do |t|
|
8
|
+
t.root(:path=>"first", :xmlns=>"urn:foobar")
|
9
|
+
t.duck()
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.xml_template
|
13
|
+
Nokogiri::XML::Document.parse '<first xmlns="urn:foobar">
|
14
|
+
<duck></duck>
|
15
|
+
</first>'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BarHistory < ActiveFedora::Base
|
20
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
21
|
+
m.field "fubar", :string
|
22
|
+
m.field "swank", :text
|
23
|
+
end
|
24
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
|
25
|
+
m.field "fubar", :text
|
26
|
+
end
|
27
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
28
|
+
m.field "fubar", :text
|
29
|
+
end
|
30
|
+
|
31
|
+
has_metadata :type=>BarStream, :name=>"xmlish"
|
32
|
+
delegate :fubar, :to=>'withText', :unique=>true
|
33
|
+
delegate :duck, :to=>'xmlish', :unique=>true
|
34
|
+
end
|
35
|
+
before :each do
|
36
|
+
@n = BarHistory.new(:pid=>"monkey:99")
|
37
|
+
end
|
38
|
+
describe "attributes=" do
|
39
|
+
it "should set attributes" do
|
40
|
+
@n.attributes = {:fubar=>"baz", :duck=>"Quack"}
|
41
|
+
@n.fubar.should == "baz"
|
42
|
+
@n.withText.get_values(:fubar).first.should == 'baz'
|
43
|
+
@n.duck.should == "Quack"
|
44
|
+
@n.xmlish.term_values(:duck).first.should == 'Quack'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
describe "update_attributes" do
|
48
|
+
it "should set attributes and save " do
|
49
|
+
@n.update_attributes(:fubar=>"baz", :duck=>"Quack")
|
50
|
+
@q = BarHistory.find('monkey:99')
|
51
|
+
@q.fubar.should == "baz"
|
52
|
+
@q.duck.should == "Quack"
|
53
|
+
end
|
54
|
+
after do
|
55
|
+
@n.delete
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
|
5
|
+
describe "first level delegation" do
|
6
|
+
class BarStream2 < ActiveFedora::NokogiriDatastream
|
7
|
+
set_terminology do |t|
|
8
|
+
t.root(:path=>"first", :xmlns=>"urn:foobar")
|
9
|
+
t.duck()
|
10
|
+
t.cow()
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.xml_template
|
14
|
+
Nokogiri::XML::Document.parse '<first xmlns="urn:foobar">
|
15
|
+
<duck></duck>
|
16
|
+
<cow></cow>
|
17
|
+
</first>'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class BarHistory2 < ActiveFedora::Base
|
22
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
23
|
+
m.field "fubar", :string
|
24
|
+
m.field "bandana", :string
|
25
|
+
m.field "swank", :text
|
26
|
+
end
|
27
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
|
28
|
+
m.field "fubar", :text
|
29
|
+
end
|
30
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
31
|
+
m.field "fubar", :text
|
32
|
+
end
|
33
|
+
|
34
|
+
has_metadata :type=>BarStream2, :name=>"xmlish"
|
35
|
+
delegate :fubar, :to=>'withText', :unique=>true
|
36
|
+
delegate :duck, :to=>'xmlish', :unique=>true
|
37
|
+
delegate :cow, :to=>'xmlish'
|
38
|
+
end
|
39
|
+
before :each do
|
40
|
+
@n = BarHistory2.new(:pid=>"monkey:99")
|
41
|
+
end
|
42
|
+
it "should save a delegated property uniquely" do
|
43
|
+
@n.fubar="Quack"
|
44
|
+
@n.fubar.should == "Quack"
|
45
|
+
@n.withText.get_values(:fubar).first.should == 'Quack'
|
46
|
+
@n.duck="Quack"
|
47
|
+
@n.duck.should == "Quack"
|
48
|
+
@n.xmlish.term_values(:duck).first.should == 'Quack'
|
49
|
+
end
|
50
|
+
it "should return an array if not marked as unique" do
|
51
|
+
### Metadata datastream does not appear to support multiple value setting
|
52
|
+
@n.cow=["one", "two"]
|
53
|
+
@n.cow.should == ["one", "two"]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
data/spec/unit/base_spec.rb
CHANGED
@@ -5,7 +5,6 @@ require 'active_fedora/base'
|
|
5
5
|
require 'active_fedora/metadata_datastream'
|
6
6
|
require 'time'
|
7
7
|
require 'date'
|
8
|
-
|
9
8
|
class FooHistory < ActiveFedora::Base
|
10
9
|
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
11
10
|
m.field "fubar", :string
|
@@ -49,6 +48,13 @@ describe ActiveFedora::Base do
|
|
49
48
|
result.inner_object.should be_kind_of(Fedora::FedoraObject)
|
50
49
|
end
|
51
50
|
|
51
|
+
it "should allow initialization with nil" do
|
52
|
+
# for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
|
53
|
+
Fedora::Repository.instance.expects(:save).never
|
54
|
+
result = ActiveFedora::Base.new(nil)
|
55
|
+
result.inner_object.should be_kind_of(Fedora::FedoraObject)
|
56
|
+
end
|
57
|
+
|
52
58
|
end
|
53
59
|
|
54
60
|
describe ".internal_uri" do
|
@@ -57,10 +63,35 @@ describe ActiveFedora::Base do
|
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
60
|
-
|
66
|
+
### Methods for ActiveModel::Conversions
|
67
|
+
it "should have to_param once it's saved" do
|
68
|
+
@test_object.to_param.should be_nil
|
69
|
+
@test_object.expects(:create).returns(true)
|
70
|
+
@test_object.save
|
61
71
|
@test_object.to_param.should == @test_object.pid
|
62
72
|
end
|
63
73
|
|
74
|
+
it "should have to_key once it's saved" do
|
75
|
+
@test_object.to_key.should be_nil
|
76
|
+
@test_object.expects(:create).returns(true)
|
77
|
+
@test_object.save
|
78
|
+
@test_object.to_key.should == [@test_object.pid]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have to_model" do
|
82
|
+
@test_object.to_model.should be @test_object
|
83
|
+
end
|
84
|
+
### end ActiveModel::Conversions
|
85
|
+
|
86
|
+
### Methods for ActiveModel::Naming
|
87
|
+
it "Should know the model_name" do
|
88
|
+
FooHistory.model_name.should == 'FooHistory'
|
89
|
+
FooHistory.model_name.human.should == 'Foo history'
|
90
|
+
end
|
91
|
+
### End ActiveModel::Naming
|
92
|
+
|
93
|
+
|
94
|
+
|
64
95
|
it "should respond_to has_metadata" do
|
65
96
|
ActiveFedora::Base.respond_to?(:has_metadata).should be_true
|
66
97
|
end
|
@@ -87,6 +118,8 @@ describe ActiveFedora::Base do
|
|
87
118
|
|
88
119
|
end
|
89
120
|
|
121
|
+
|
122
|
+
|
90
123
|
describe ".fields" do
|
91
124
|
it "should provide fields" do
|
92
125
|
@test_object.should respond_to(:fields)
|
@@ -234,10 +267,13 @@ describe ActiveFedora::Base do
|
|
234
267
|
describe '.save' do
|
235
268
|
|
236
269
|
|
237
|
-
it "should return true if object and datastreams all save successfully" do
|
270
|
+
it "should return true and set persisted if object and datastreams all save successfully" do
|
271
|
+
@test_object.persisted?.should be false
|
238
272
|
@test_object.expects(:create).returns(true)
|
239
273
|
@test_object.save.should == true
|
274
|
+
@test_object.persisted?.should be true
|
240
275
|
end
|
276
|
+
|
241
277
|
|
242
278
|
it "should raise an exception if object fails to save" do
|
243
279
|
server_response = mock("Server Error")
|
@@ -436,6 +472,7 @@ describe ActiveFedora::Base do
|
|
436
472
|
end
|
437
473
|
|
438
474
|
end
|
475
|
+
|
439
476
|
|
440
477
|
describe ".update_index" do
|
441
478
|
it "should provide .update_index" do
|
@@ -509,65 +546,15 @@ describe ActiveFedora::Base do
|
|
509
546
|
|
510
547
|
describe "update_attributes" do
|
511
548
|
|
512
|
-
it "should
|
549
|
+
it "should set the attributes and save" do
|
513
550
|
m = FooHistory.new
|
514
|
-
att= {"fubar"=>
|
551
|
+
att= {"fubar"=> '1234', "baz" =>'stuff'}
|
515
552
|
|
516
|
-
m.
|
553
|
+
m.expects(:fubar=).with('1234')
|
554
|
+
m.expects(:baz=).with('stuff')
|
555
|
+
m.expects(:save)
|
517
556
|
m.update_attributes(att)
|
518
557
|
end
|
519
|
-
|
520
|
-
it "should be able to update attr on text fields" do
|
521
|
-
m = FooHistory.new
|
522
|
-
m.should_not be_nil
|
523
|
-
m.datastreams['someData'].swank_values.should == []
|
524
|
-
m.update_attributes(:swank=>'baz')
|
525
|
-
m.should_not be_nil
|
526
|
-
m.datastreams['someData'].swank_values.should == ['baz']
|
527
|
-
end
|
528
|
-
|
529
|
-
it "should have update_attributes" do
|
530
|
-
n = FooHistory.new
|
531
|
-
n.update_attributes(:fubar=>'baz')
|
532
|
-
n.datastreams["someData"].fubar_values.should == ['baz']
|
533
|
-
n.update_attributes('fubar'=>'bak')
|
534
|
-
n.datastreams["someData"].fubar_values.should == ['bak']
|
535
|
-
#really? should it hit all matching datastreams?
|
536
|
-
n.datastreams["withText"].fubar_values.should == ['bak']
|
537
|
-
end
|
538
|
-
|
539
|
-
it "should allow deleting of values" do
|
540
|
-
n = FooHistory.new
|
541
|
-
n.datastreams["someData"].fubar_values.should == []
|
542
|
-
n.update_attributes(:fubar=>'baz')
|
543
|
-
n.datastreams["someData"].fubar_values.should == ['baz']
|
544
|
-
n.update_attributes(:fubar=>:delete)
|
545
|
-
n.datastreams["someData"].fubar_values.should == []
|
546
|
-
n.update_attributes(:fubar=>'baz')
|
547
|
-
n.datastreams["someData"].fubar_values.should == ['baz']
|
548
|
-
n.update_attributes(:fubar=>"")
|
549
|
-
n.datastreams["someData"].fubar_values.should == []
|
550
|
-
end
|
551
|
-
|
552
|
-
it "should take a :datastreams argument" do
|
553
|
-
m = FooHistory.new
|
554
|
-
m.should_not be_nil
|
555
|
-
m.datastreams['someData'].fubar_values.should == []
|
556
|
-
m.datastreams['withText'].fubar_values.should == []
|
557
|
-
m.datastreams['withText2'].fubar_values.should == []
|
558
|
-
|
559
|
-
m.update_attributes({:fubar=>'baz'}, :datastreams=>"someData")
|
560
|
-
m.should_not be_nil
|
561
|
-
m.datastreams['someData'].fubar_values.should == ['baz']
|
562
|
-
m.datastreams["withText"].fubar_values.should == []
|
563
|
-
m.datastreams['withText2'].fubar_values.should == []
|
564
|
-
|
565
|
-
m.update_attributes({:fubar=>'baz'}, :datastreams=>["someData", "withText2"])
|
566
|
-
m.should_not be_nil
|
567
|
-
m.datastreams['someData'].fubar_values.should == ['baz']
|
568
|
-
m.datastreams["withText"].fubar_values.should == []
|
569
|
-
m.datastreams['withText2'].fubar_values.should == ['baz']
|
570
|
-
end
|
571
558
|
end
|
572
559
|
|
573
560
|
describe "update_indexed_attributes" do
|