rubydora 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rubydora/datastream.rb +4 -2
- data/lib/rubydora/digital_object.rb +23 -4
- data/lib/rubydora/profile_parser.rb +21 -0
- data/lib/rubydora/repository.rb +3 -2
- data/lib/rubydora/rest_api_client.rb +3 -3
- data/spec/lib/datastream_spec.rb +60 -45
- data/spec/lib/digital_object_spec.rb +153 -68
- data/spec/lib/integration_test_spec.rb +25 -2
- data/spec/lib/profile_parser_spec.rb +20 -0
- data/spec/lib/repository_spec.rb +7 -0
- metadata +41 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 613a09dfb2ffdd26f9e0823e55cff69c6b961c00
|
4
|
+
data.tar.gz: 66603795ff46db8c1d2422ae81794eb6577fa9e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29615bcda338d44a3e40972d5e1adb54946ffc14e3473b5c5e3763eff87aac40c792dfc4e6450b3beadcaf896bd2960ff160c065458d2b21dcac118c7a080d8f
|
7
|
+
data.tar.gz: ea6981f21d6c4cac06f40b2f563f257cdd4bc8ec26591346935593914f27f73b17ee4ab5a9e8fc58ea367f3302045ae2e14bbcf60aed9b0f6291094a3e5959d5
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.7.
|
1
|
+
1.7.3
|
data/lib/rubydora/datastream.rb
CHANGED
@@ -290,8 +290,9 @@ module Rubydora
|
|
290
290
|
def create
|
291
291
|
check_if_read_only
|
292
292
|
run_callbacks :create do
|
293
|
-
repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid, :content => content })
|
293
|
+
p = repository.add_datastream( to_api_params.merge({ :pid => pid, :dsid => dsid, :content => content })) || {}
|
294
294
|
reset_profile_attributes
|
295
|
+
self.profile= p unless p.empty?
|
295
296
|
self.class.new(digital_object, dsid, @options)
|
296
297
|
end
|
297
298
|
end
|
@@ -303,8 +304,9 @@ module Rubydora
|
|
303
304
|
run_callbacks :save do
|
304
305
|
raise RubydoraError.new("Unable to save #{self.inspect} without content") unless has_content?
|
305
306
|
return create if new?
|
306
|
-
repository.modify_datastream
|
307
|
+
p = repository.modify_datastream(to_api_params.merge({ :pid => pid, :dsid => dsid })) || {}
|
307
308
|
reset_profile_attributes
|
309
|
+
self.profile= p unless p.empty?
|
308
310
|
self.class.new(digital_object, dsid, @options)
|
309
311
|
end
|
310
312
|
end
|
@@ -185,23 +185,31 @@ module Rubydora
|
|
185
185
|
# persist the object to Fedora, either as a new object
|
186
186
|
# by modifing the existing object
|
187
187
|
#
|
188
|
-
# also will save all `:
|
188
|
+
# also will save all `:changed?` datastreams that already exist
|
189
189
|
# new datastreams must be directly saved
|
190
190
|
#
|
191
191
|
# @return [Rubydora::DigitalObject] a new copy of this object
|
192
192
|
def save
|
193
193
|
check_if_read_only
|
194
|
+
mod_time = nil
|
194
195
|
run_callbacks :save do
|
195
196
|
if self.new?
|
196
197
|
self.pid = repository.ingest to_api_params.merge(:pid => pid)
|
197
198
|
@profile = nil #will cause a reload with updated data
|
198
199
|
else
|
199
200
|
p = to_api_params
|
200
|
-
|
201
|
+
unless p.empty?
|
202
|
+
mod_time = repository.modify_object p.merge(:pid => pid)
|
203
|
+
changed_attributes.clear
|
204
|
+
end
|
201
205
|
end
|
202
206
|
end
|
203
|
-
|
204
|
-
|
207
|
+
mod_time = save_datastreams(mod_time)
|
208
|
+
# mod_time will be nil on new objects with no ds changes
|
209
|
+
unless mod_time.nil?
|
210
|
+
self.lastModifiedDate = mod_time
|
211
|
+
changed_attributes.delete 'lastModifiedDate'
|
212
|
+
end
|
205
213
|
self
|
206
214
|
end
|
207
215
|
|
@@ -268,5 +276,16 @@ module Rubydora
|
|
268
276
|
super
|
269
277
|
end
|
270
278
|
|
279
|
+
# save changed datastreams
|
280
|
+
# @param [String] memo_time : the time before changes, or nil
|
281
|
+
# @return [String] the time of the last datastream change, or nil if no changes
|
282
|
+
def save_datastreams(memo_time=nil)
|
283
|
+
mod_time = memo_time
|
284
|
+
self.datastreams.select { |dsid, ds| ds.changed? }.each do |dsid, ds|
|
285
|
+
ds.save
|
286
|
+
mod_time = ProfileParser.canonicalize_date(ds.dsCreateDate)
|
287
|
+
end
|
288
|
+
mod_time
|
289
|
+
end
|
271
290
|
end
|
272
291
|
end
|
@@ -46,6 +46,7 @@ module Rubydora
|
|
46
46
|
next if key == "objModels"
|
47
47
|
h[key] = values.reject { |x| x.empty? }.first
|
48
48
|
end
|
49
|
+
h['objLastModDate'] = canonicalize_date_string(h['objLastModDate']) if h['objLastModDate']
|
49
50
|
h.with_indifferent_access
|
50
51
|
end
|
51
52
|
|
@@ -65,5 +66,25 @@ module Rubydora
|
|
65
66
|
end
|
66
67
|
h.with_indifferent_access
|
67
68
|
end
|
69
|
+
|
70
|
+
# Some versions of Fedora 3 return lexical representations of a w3c date
|
71
|
+
# in the object profile, which will not compare correctly to the canonical
|
72
|
+
# representations returned from update operations
|
73
|
+
def self.canonicalize_date_string(input)
|
74
|
+
if input =~ /0Z/
|
75
|
+
lmd = input.sub(/\.[0]+Z$/,'Z')
|
76
|
+
lmd = lmd.sub(/\.([^0]+)[0]+Z$/,'.\1Z')
|
77
|
+
lmd
|
78
|
+
else
|
79
|
+
input
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def self.canonicalize_date(input)
|
83
|
+
if input.is_a? Time
|
84
|
+
canonicalize_date_string(input.utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"))
|
85
|
+
else
|
86
|
+
canonicalize_date_string(input.to_s)
|
87
|
+
end
|
88
|
+
end
|
68
89
|
end
|
69
90
|
end
|
data/lib/rubydora/repository.rb
CHANGED
@@ -17,7 +17,7 @@ module Rubydora
|
|
17
17
|
end
|
18
18
|
|
19
19
|
delegate :client, :transaction, :mint, :ingest, :find_objects, :purge_object,
|
20
|
-
:modify_object, :datastreams, :add_datastream, :modify_datastream,
|
20
|
+
:modify_object, :datastream_url, :datastreams, :add_datastream, :modify_datastream,
|
21
21
|
:set_datastream_options, :datastream_dissemination, :purge_datastream,
|
22
22
|
:add_relationship, :purge_relationship, :repository_profile,
|
23
23
|
:object_profile, :datastream_profile, :versions_for_datastream,
|
@@ -31,8 +31,9 @@ module Rubydora
|
|
31
31
|
# @option options [String] :user
|
32
32
|
# @option options [String] :password
|
33
33
|
# @option options [Boolean] :validateChecksum
|
34
|
-
def initialize options = {}
|
34
|
+
def initialize options = {}, api = nil
|
35
35
|
@config = options.symbolize_keys
|
36
|
+
@api = api if api
|
36
37
|
check_repository_version!
|
37
38
|
end
|
38
39
|
|
@@ -162,7 +162,7 @@ module Rubydora
|
|
162
162
|
query_options = options.dup
|
163
163
|
pid = query_options.delete(:pid)
|
164
164
|
run_hook :before_modify_object, :pid => pid, :options => options
|
165
|
-
client[object_url(pid, query_options)].put
|
165
|
+
ProfileParser.canonicalize_date_string(client[object_url(pid, query_options)].put(nil))
|
166
166
|
rescue Exception => exception
|
167
167
|
rescue_with_handler(exception) || raise
|
168
168
|
end
|
@@ -340,7 +340,7 @@ module Rubydora
|
|
340
340
|
run_hook :before_add_datastream, :pid => pid, :dsid => dsid, :file => file, :options => options
|
341
341
|
str = file.respond_to?(:read) ? file.read : file
|
342
342
|
file.rewind if file.respond_to?(:rewind)
|
343
|
-
client[datastream_url(pid, dsid, query_options)].post(str, :content_type => content_type.to_s, :multipart => true)
|
343
|
+
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].post(str, :content_type => content_type.to_s, :multipart => true))
|
344
344
|
rescue Exception => exception
|
345
345
|
rescue_with_handler(exception) || raise
|
346
346
|
end
|
@@ -365,7 +365,7 @@ module Rubydora
|
|
365
365
|
run_hook :before_modify_datastream, :pid => pid, :dsid => dsid, :file => file, :content_type => content_type, :options => options
|
366
366
|
str = file.respond_to?(:read) ? file.read : file
|
367
367
|
file.rewind if file.respond_to?(:rewind)
|
368
|
-
client[datastream_url(pid, dsid, query_options)].put(str, rest_client_options)
|
368
|
+
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].put(str, rest_client_options))
|
369
369
|
|
370
370
|
rescue Exception => exception
|
371
371
|
rescue_with_handler(exception) || raise
|
data/spec/lib/datastream_spec.rb
CHANGED
@@ -3,7 +3,9 @@ require 'stringio'
|
|
3
3
|
|
4
4
|
describe Rubydora::Datastream do
|
5
5
|
before do
|
6
|
-
@
|
6
|
+
@mock_api = Rubydora::Fc3Service.new({})
|
7
|
+
@mock_api.stub(:repository_profile, {"repositoryVersion" => "3.4"})
|
8
|
+
@mock_repository = Rubydora::Repository.new({}, @mock_api)
|
7
9
|
@mock_object = double(Rubydora::DigitalObject)
|
8
10
|
@mock_object.stub(:repository => @mock_repository, :pid => 'pid', :new_record? => false)
|
9
11
|
end
|
@@ -25,7 +27,7 @@ describe Rubydora::Datastream do
|
|
25
27
|
before do
|
26
28
|
stub_response = double
|
27
29
|
stub_response.stub(:read_body).and_yield("one1").and_yield('two2').and_yield('thre').and_yield('four')
|
28
|
-
@
|
30
|
+
@mock_api.should_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_yield(stub_response)
|
29
31
|
prof = <<-XML
|
30
32
|
<datastreamProfile>
|
31
33
|
<dsSize>16</dsSize>
|
@@ -69,7 +71,7 @@ describe Rubydora::Datastream do
|
|
69
71
|
|
70
72
|
describe "create" do
|
71
73
|
before(:each) do
|
72
|
-
@
|
74
|
+
@mock_api.stub(:datastream) { raise(RestClient::ResourceNotFound) }
|
73
75
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
74
76
|
end
|
75
77
|
|
@@ -147,12 +149,12 @@ describe Rubydora::Datastream do
|
|
147
149
|
|
148
150
|
it "should call the appropriate api on save" do
|
149
151
|
@datastream.stub(:content => 'content')
|
150
|
-
@
|
152
|
+
@mock_api.should_receive(:add_datastream).with(hash_including(:content => 'content', :pid => 'pid', :dsid => 'dsid', :controlGroup => 'M', :dsState => 'A'))
|
151
153
|
@datastream.save
|
152
154
|
end
|
153
155
|
|
154
156
|
it "should be able to override defaults" do
|
155
|
-
@
|
157
|
+
@mock_api.should_receive(:add_datastream).with(hash_including(:controlGroup => 'E'))
|
156
158
|
@datastream.controlGroup = 'E'
|
157
159
|
@datastream.dsLocation = "uri:asdf"
|
158
160
|
@datastream.save
|
@@ -164,7 +166,7 @@ describe Rubydora::Datastream do
|
|
164
166
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
165
167
|
end
|
166
168
|
it "should be true by default" do
|
167
|
-
@
|
169
|
+
@mock_api.should_receive(:datastream).and_return <<-XML
|
168
170
|
<datastreamProfile>
|
169
171
|
</datastreamProfile>
|
170
172
|
XML
|
@@ -172,7 +174,7 @@ describe Rubydora::Datastream do
|
|
172
174
|
end
|
173
175
|
|
174
176
|
it "should be true when it's returned as true" do
|
175
|
-
@
|
177
|
+
@mock_api.should_receive(:datastream).and_return <<-XML
|
176
178
|
<datastreamProfile>
|
177
179
|
<dsVersionable>true</dsVersionable>
|
178
180
|
</datastreamProfile>
|
@@ -181,7 +183,7 @@ describe Rubydora::Datastream do
|
|
181
183
|
end
|
182
184
|
|
183
185
|
it "should be false when it's returned as false" do
|
184
|
-
@
|
186
|
+
@mock_api.should_receive(:datastream).and_return <<-XML
|
185
187
|
<datastreamProfile>
|
186
188
|
<dsVersionable>false</dsVersionable>
|
187
189
|
</datastreamProfile>
|
@@ -195,7 +197,7 @@ describe Rubydora::Datastream do
|
|
195
197
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
196
198
|
end
|
197
199
|
it "should be nil when it hasn't been set" do
|
198
|
-
@
|
200
|
+
@mock_api.should_receive(:datastream).with(hash_including(:validateChecksum => true)).and_return <<-XML
|
199
201
|
<datastreamProfile>
|
200
202
|
</datastreamProfile>
|
201
203
|
XML
|
@@ -203,7 +205,7 @@ describe Rubydora::Datastream do
|
|
203
205
|
end
|
204
206
|
|
205
207
|
it "should be true when it's returned as true" do
|
206
|
-
@
|
208
|
+
@mock_api.should_receive(:datastream).with(hash_including(:validateChecksum => true)).and_return <<-XML
|
207
209
|
<datastreamProfile>
|
208
210
|
<dsChecksumValid>true</dsChecksumValid>
|
209
211
|
</datastreamProfile>
|
@@ -212,7 +214,7 @@ describe Rubydora::Datastream do
|
|
212
214
|
end
|
213
215
|
|
214
216
|
it "should be false when it's returned as false" do
|
215
|
-
@
|
217
|
+
@mock_api.should_receive(:datastream).with(hash_including(:validateChecksum => true)).and_return <<-XML
|
216
218
|
<datastreamProfile>
|
217
219
|
<dsChecksumValid>false</dsChecksumValid>
|
218
220
|
</datastreamProfile>
|
@@ -224,7 +226,7 @@ describe Rubydora::Datastream do
|
|
224
226
|
describe "retrieve" do
|
225
227
|
before(:each) do
|
226
228
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
227
|
-
@
|
229
|
+
@mock_api.stub(:datastream).and_return <<-XML
|
228
230
|
<datastreamProfile>
|
229
231
|
<dsLocation>some:uri</dsLocation>
|
230
232
|
<dsLabel>label</dsLabel>
|
@@ -246,12 +248,12 @@ describe Rubydora::Datastream do
|
|
246
248
|
end
|
247
249
|
|
248
250
|
it "should mediate access to datastream contents" do
|
249
|
-
@
|
251
|
+
@mock_api.should_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('asdf')
|
250
252
|
@datastream.content.should == "asdf"
|
251
253
|
end
|
252
254
|
|
253
255
|
it "should not load contents if they say not to" do
|
254
|
-
@
|
256
|
+
@mock_api.should_not_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid'))
|
255
257
|
@datastream.local_or_remote_content(false).should be_nil
|
256
258
|
end
|
257
259
|
|
@@ -273,7 +275,7 @@ describe Rubydora::Datastream do
|
|
273
275
|
describe "for a managed datastream" do
|
274
276
|
before(:each) do
|
275
277
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
276
|
-
@
|
278
|
+
@mock_api.stub(:datastream).and_return <<-XML
|
277
279
|
<datastreamProfile>
|
278
280
|
<dsLocation>some:uri</dsLocation>
|
279
281
|
<dsLabel>label</dsLabel>
|
@@ -282,35 +284,35 @@ describe Rubydora::Datastream do
|
|
282
284
|
end
|
283
285
|
|
284
286
|
it "should not be changed after a read-only access" do
|
285
|
-
@
|
287
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('asdf')
|
286
288
|
@datastream.content
|
287
289
|
@datastream.content_changed?.should == false
|
288
290
|
end
|
289
291
|
it "should not load content just to check and see if it was changed." do
|
290
|
-
@
|
292
|
+
@mock_api.should_not_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid'))
|
291
293
|
@datastream.content_changed?.should == false
|
292
294
|
end
|
293
295
|
it "should be changed when the new content is different than the old content" do
|
294
|
-
@
|
296
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('asdf')
|
295
297
|
@datastream.content = "test"
|
296
298
|
@datastream.content_changed?.should == true
|
297
299
|
end
|
298
300
|
|
299
301
|
it "should not be changed when the new content is the same as the existing content (when eager-loading is enabled)" do
|
300
|
-
@
|
302
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
|
301
303
|
@datastream.eager_load_datastream_content = true
|
302
304
|
@datastream.content = "test"
|
303
305
|
@datastream.content_changed?.should == false
|
304
306
|
end
|
305
307
|
|
306
308
|
it "should be changed when the new content is the same as the existing content (without eager loading, the default)" do
|
307
|
-
@
|
309
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
|
308
310
|
@datastream.content = "test"
|
309
311
|
@datastream.content_changed?.should == true
|
310
312
|
end
|
311
313
|
|
312
314
|
it "should not be changed when the new content is the same as the existing content (and we have accessed #content previously)" do
|
313
|
-
@
|
315
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
|
314
316
|
@datastream.content
|
315
317
|
@datastream.content = "test"
|
316
318
|
@datastream.content_changed?.should == false
|
@@ -319,7 +321,7 @@ describe Rubydora::Datastream do
|
|
319
321
|
|
320
322
|
describe "for an inline datastream" do
|
321
323
|
before(:each) do
|
322
|
-
@
|
324
|
+
@mock_api.stub(:datastream).and_return <<-XML
|
323
325
|
<datastreamProfile>
|
324
326
|
<dsLocation>some:uri</dsLocation>
|
325
327
|
<dsLabel>label</dsLabel>
|
@@ -328,14 +330,14 @@ describe Rubydora::Datastream do
|
|
328
330
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid', :controlGroup => 'X'
|
329
331
|
end
|
330
332
|
it "should not be changed when the new content is the same as the existing content (when eager-loading is enabled)" do
|
331
|
-
@
|
333
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('<xml>test</xml>')
|
332
334
|
@datastream.eager_load_datastream_content = true
|
333
335
|
@datastream.content = "<xml>test</xml>"
|
334
336
|
@datastream.content_changed?.should == false
|
335
337
|
end
|
336
338
|
|
337
339
|
it "should be changed when the new content is the same as the existing content (without eager loading, the default)" do
|
338
|
-
@
|
340
|
+
@mock_api.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('<xml>test</xml>')
|
339
341
|
@datastream.content = "<xml>test</xml>"
|
340
342
|
@datastream.content_changed?.should == true
|
341
343
|
end
|
@@ -383,7 +385,7 @@ describe Rubydora::Datastream do
|
|
383
385
|
describe "update" do
|
384
386
|
before(:each) do
|
385
387
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
386
|
-
@
|
388
|
+
@mock_api.should_receive(:datastream).once.and_return <<-XML
|
387
389
|
<datastreamProfile>
|
388
390
|
<dsLocation>some:uri</dsLocation>
|
389
391
|
<dsLabel>label</dsLabel>
|
@@ -406,7 +408,7 @@ describe Rubydora::Datastream do
|
|
406
408
|
end
|
407
409
|
|
408
410
|
it "should call the appropriate api with any dirty attributes" do
|
409
|
-
@
|
411
|
+
@mock_api.should_receive(:modify_datastream).with(hash_including(:dsLabel => "New Label"))
|
410
412
|
@datastream.dsLabel = "New Label"
|
411
413
|
@datastream.save
|
412
414
|
end
|
@@ -414,9 +416,10 @@ describe Rubydora::Datastream do
|
|
414
416
|
|
415
417
|
describe "update when content is changed" do
|
416
418
|
it "should update the datastream when the content is changed" do
|
417
|
-
@
|
419
|
+
@mock_api.should_receive(:modify_datastream).with(hash_including(:content => 'test')).and_return({'dsLocation' => 'some:uri', 'dsLabel' => 'label', 'dsSize' => 4})
|
418
420
|
@datastream.content = "test"
|
419
421
|
@datastream.save
|
422
|
+
@datastream.dsSize.should == 4
|
420
423
|
end
|
421
424
|
|
422
425
|
it "should be marked as changed when the content is updated" do
|
@@ -432,7 +435,7 @@ describe Rubydora::Datastream do
|
|
432
435
|
before(:each) do
|
433
436
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
434
437
|
@datastream.stub :content_changed? => false
|
435
|
-
@
|
438
|
+
@mock_api.stub(:datastream).and_return <<-XML
|
436
439
|
<datastreamProfile>
|
437
440
|
<dsLocation>some:uri</dsLocation>
|
438
441
|
<dsLabel>label</dsLabel>
|
@@ -446,13 +449,13 @@ describe Rubydora::Datastream do
|
|
446
449
|
end
|
447
450
|
|
448
451
|
it "before saving an object" do
|
449
|
-
@
|
452
|
+
@mock_api.should_receive(:modify_datastream)
|
450
453
|
@datastream.should_receive(:check_if_read_only)
|
451
454
|
@datastream.save
|
452
455
|
end
|
453
456
|
|
454
457
|
it "before deleting an object" do
|
455
|
-
@
|
458
|
+
@mock_api.should_receive(:purge_datastream)
|
456
459
|
@mock_object.should_receive(:datastreams).and_return([])
|
457
460
|
@datastream.should_receive(:check_if_read_only)
|
458
461
|
@datastream.delete
|
@@ -464,7 +467,7 @@ describe Rubydora::Datastream do
|
|
464
467
|
before(:each) do
|
465
468
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
466
469
|
@datastream.stub(:new? => false)
|
467
|
-
@
|
470
|
+
@mock_api.stub(:datastream_versions).and_return <<-XML
|
468
471
|
<datastreamHistory>
|
469
472
|
<datastreamProfile>
|
470
473
|
<dsVersionID>dsid.1</dsVersionID>
|
@@ -487,13 +490,13 @@ describe Rubydora::Datastream do
|
|
487
490
|
end
|
488
491
|
|
489
492
|
it "should lookup content of datastream using the asOfDateTime parameter" do
|
490
|
-
@
|
493
|
+
@mock_api.should_receive(:datastream_dissemination).with(hash_including(:asOfDateTime => '2008-08-05T01:30:05.012Z'))
|
491
494
|
Rubydora::Datastream.any_instance.stub(:new? => false)
|
492
495
|
@datastream.versions.last.content
|
493
496
|
end
|
494
497
|
|
495
498
|
it "should be the current version" do
|
496
|
-
@
|
499
|
+
@mock_api.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return <<-XML
|
497
500
|
<datastreamProfile>
|
498
501
|
<dsVersionID>dsid.1</dsVersionID>
|
499
502
|
<dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
|
@@ -503,7 +506,7 @@ describe Rubydora::Datastream do
|
|
503
506
|
end
|
504
507
|
|
505
508
|
it "should be the current version if it's the first version" do
|
506
|
-
@
|
509
|
+
@mock_api.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime =>'2010-01-02T00:00:00.012Z')).and_return <<-XML
|
507
510
|
<datastreamProfile>
|
508
511
|
<dsVersionID>dsid.1</dsVersionID>
|
509
512
|
<dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
|
@@ -513,7 +516,7 @@ describe Rubydora::Datastream do
|
|
513
516
|
end
|
514
517
|
|
515
518
|
it "should not be the current version if it's the second version" do
|
516
|
-
@
|
519
|
+
@mock_api.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime => '2008-08-05T01:30:05.012Z')).and_return <<-XML
|
517
520
|
<datastreamProfile>
|
518
521
|
<dsVersionID>dsid.0</dsVersionID>
|
519
522
|
<dsCreateDate>2008-08-05T01:30:05.012Z</dsCreateDate>
|
@@ -525,7 +528,7 @@ describe Rubydora::Datastream do
|
|
525
528
|
describe "when no versions are found" do
|
526
529
|
before(:each) do
|
527
530
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
528
|
-
@
|
531
|
+
@mock_api.stub(:datastream_versions).and_return nil
|
529
532
|
end
|
530
533
|
|
531
534
|
it "should have an emptylist of previous versions" do
|
@@ -543,7 +546,7 @@ describe Rubydora::Datastream do
|
|
543
546
|
|
544
547
|
describe "datastream attributes" do
|
545
548
|
before do
|
546
|
-
@
|
549
|
+
@mock_api.stub(:datastream => <<-XML
|
547
550
|
<datastreamProfile>
|
548
551
|
<anyProfileValue />
|
549
552
|
</datastreamProfile>
|
@@ -587,10 +590,11 @@ describe Rubydora::Datastream do
|
|
587
590
|
end
|
588
591
|
|
589
592
|
it "should appear in the save request" do
|
590
|
-
@
|
593
|
+
@mock_api.should_receive(:modify_datastream).with(hash_including(method.to_sym => 'new_value'))
|
591
594
|
subject.send("#{method}=", 'new_value')
|
592
595
|
subject.save
|
593
|
-
|
596
|
+
expect(subject).to_not be_changed, "#{subject.changes.inspect}"
|
597
|
+
end
|
594
598
|
end
|
595
599
|
end
|
596
600
|
|
@@ -633,7 +637,7 @@ describe Rubydora::Datastream do
|
|
633
637
|
end
|
634
638
|
|
635
639
|
it "should appear in the save request" do
|
636
|
-
@
|
640
|
+
@mock_api.should_receive(:modify_datastream).with(hash_including(method.to_sym => 'http://example.com'))
|
637
641
|
subject.stub(:content_changed? => false)
|
638
642
|
subject.dsLocation = 'http://example.com'
|
639
643
|
subject.save
|
@@ -741,7 +745,7 @@ describe Rubydora::Datastream do
|
|
741
745
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
742
746
|
end
|
743
747
|
it "should accept a validateChecksum argument" do
|
744
|
-
@
|
748
|
+
@mock_api.should_receive(:datastream).with(hash_including(:validateChecksum => true)).and_return <<-XML
|
745
749
|
<datastreamProfile>
|
746
750
|
<dsChecksumValid>true</dsChecksumValid>
|
747
751
|
</datastreamProfile>
|
@@ -749,13 +753,13 @@ describe Rubydora::Datastream do
|
|
749
753
|
@datastream.profile(:validateChecksum=>true).should == {'dsChecksumValid' =>true}
|
750
754
|
end
|
751
755
|
it "should reraise Unauthorized errors" do
|
752
|
-
@
|
756
|
+
@mock_api.should_receive(:datastream).and_raise(RestClient::Unauthorized)
|
753
757
|
lambda{@datastream.profile}.should raise_error(RestClient::Unauthorized)
|
754
758
|
end
|
755
759
|
|
756
760
|
describe "once it has a profile" do
|
757
761
|
it "should use the profile from cache" do
|
758
|
-
@
|
762
|
+
@mock_api.should_receive(:datastream).once.and_return <<-XML
|
759
763
|
<datastreamProfile>
|
760
764
|
<dsChecksumValid>true</dsChecksumValid>
|
761
765
|
</datastreamProfile>
|
@@ -765,12 +769,12 @@ describe Rubydora::Datastream do
|
|
765
769
|
@datastream.profile().should == {'dsChecksumValid' =>true}
|
766
770
|
end
|
767
771
|
it "should re-fetch and replace the profile when validateChecksum is passed in, and there is no dsChecksumValid in the existing profile" do
|
768
|
-
@
|
772
|
+
@mock_api.should_receive(:datastream).once.and_return <<-XML
|
769
773
|
<datastreamProfile>
|
770
774
|
<dsLabel>The description of the content</dsLabel>
|
771
775
|
</datastreamProfile>
|
772
776
|
XML
|
773
|
-
@
|
777
|
+
@mock_api.should_receive(:datastream).with(hash_including(:validateChecksum => true)).once.and_return <<-XML
|
774
778
|
<datastreamProfile>
|
775
779
|
<dsLabel>The description of the content</dsLabel>
|
776
780
|
<dsChecksumValid>true</dsChecksumValid>
|
@@ -822,5 +826,16 @@ describe Rubydora::Datastream do
|
|
822
826
|
end
|
823
827
|
end
|
824
828
|
end
|
829
|
+
|
830
|
+
describe "url" do
|
831
|
+
before(:each) do
|
832
|
+
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
833
|
+
end
|
834
|
+
|
835
|
+
it "should call appropriate repository methods" do
|
836
|
+
@mock_api.should_receive(:datastream_url).once.and_return("http://example.org/foo")
|
837
|
+
@datastream.url.should == "http://example.org/foo/content"
|
838
|
+
end
|
839
|
+
end
|
825
840
|
end
|
826
841
|
|