rubydora 1.6.3 → 1.6.4

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: 3446c99b699e41f3fb8e24b636313a510c7b77cc
4
- data.tar.gz: a0b85f13192eeb58e95423ce84eb5956285f1879
3
+ metadata.gz: 763537753ba63badc5604ff8c0e8973d2c9c66e2
4
+ data.tar.gz: 6ba0d875a73f459ef3d77d426eaebbc0992b50a1
5
5
  SHA512:
6
- metadata.gz: 7b280b7c624ba9037034ee314a2a03e6e91bc36c8690a89dd3a74b43e58a7239afe52a05657f7ee41aa54f8cf9decc1426e9e8335f285baffa0a83046fce8937
7
- data.tar.gz: 4b96fe24d6ec7878662bad578a9a4171d27af9e8bf245fe03a1f5b1b6dfe1b25d7156d8a9f695fe2575ed562671e7bb22c84a22eae6c63cc4b4c02b6a4cbe2de
6
+ metadata.gz: 1d4a724ddddd121e7276a6b001a633dca5d1b233c72bf7c724740f38f455cf1a44c268e3dc604638b0700c54981ce816a314fa8e827a1279d6bae928188c7a05
7
+ data.tar.gz: 5abd3a54fb74151c19dd37df480b694447a6a85c7e70e89c3d720023e128afe391c4c8d81c0209db80465023477ccf35f09d4f93e6da86f6ea7e699a9c25580a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.3
1
+ 1.6.4
@@ -318,6 +318,12 @@ module Rubydora
318
318
  end
319
319
  end
320
320
 
321
+ def current_version?
322
+ return true if new?
323
+ vers = versions
324
+ return vers.empty? || dsVersionID == vers.first.dsVersionID
325
+ end
326
+
321
327
  # Add datastream to Fedora
322
328
  # @return [Rubydora::Datastream]
323
329
  def create
@@ -12,6 +12,10 @@ module Rubydora
12
12
  "#{base}" + (("?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }" if options and not options.empty?) || '')
13
13
  end
14
14
 
15
+ def describe_repository_url options = nil
16
+ url_for("describe", options)
17
+ end
18
+
15
19
  # Generate a base object REST API endpoint URI
16
20
  # @param [String] pid
17
21
  # @param [Hash] options to convert to URL parameters
@@ -20,6 +24,10 @@ module Rubydora
20
24
  url_for("objects" + (("/#{CGI::escape(pid.to_s.gsub('info:fedora/', ''))}" if pid) || ''), options)
21
25
  end
22
26
 
27
+ def new_object_url options = nil
28
+ object_url "new", options
29
+ end
30
+
23
31
  # @param [Hash] options to convert to URL parameters
24
32
  # @return [String] URI
25
33
  def next_pid_url options = nil
@@ -48,9 +56,20 @@ module Rubydora
48
56
  # @param [String] dsid
49
57
  # @param [Hash] options to convert to URL parameters
50
58
  # @return [String] URI
51
- def datastream_url pid, dsid = nil, options = nil
59
+ def datastream_url pid, dsid, options = nil
60
+ raise "" unless pid and dsid
61
+ url_for(object_url(pid) + "/datastreams/#{CGI::escape(dsid)}", options)
62
+ end
63
+
64
+
65
+ # Generate a base datastream REST API endpoint URI
66
+ # @param [String] pid
67
+ # @param [String] dsid
68
+ # @param [Hash] options to convert to URL parameters
69
+ # @return [String] URI
70
+ def datastreams_url pid, options = nil
52
71
  raise "" unless pid
53
- url_for(object_url(pid) + "/datastreams" + (("/#{CGI::escape(dsid)}" if dsid) || ''), options)
72
+ url_for(object_url(pid) + "/datastreams", options)
54
73
  end
55
74
 
56
75
  # @param [String] pid
@@ -24,6 +24,10 @@ module Rubydora
24
24
  DigitalObject.find(pid, self)
25
25
  end
26
26
 
27
+ def find_or_initialize pid
28
+ DigitalObject.find_or_initialize(pid, self)
29
+ end
30
+
27
31
  # High-level access to the Fedora find_objects API
28
32
  #
29
33
  # @params [String] query
@@ -65,7 +69,7 @@ module Rubydora
65
69
  # @return [Hash]
66
70
  def profile
67
71
  @profile ||= begin
68
- profile_xml = client['describe?xml=true'].get
72
+ profile_xml = self.describe.strip
69
73
  profile_xml.gsub! '<fedoraRepository', '<fedoraRepository xmlns="http://www.fedora.info/definitions/1/0/access/"' unless profile_xml =~ /xmlns=/
70
74
  doc = Nokogiri::XML(profile_xml)
71
75
  xmlns = { 'access' => "http://www.fedora.info/definitions/1/0/access/" }
@@ -9,7 +9,9 @@ module Rubydora
9
9
 
10
10
  include Rubydora::FedoraUrlHelpers
11
11
  extend ActiveSupport::Concern
12
- include ActiveSupport::Benchmarkable
12
+ include ActiveSupport::Benchmarkable
13
+ extend Deprecation
14
+
13
15
 
14
16
 
15
17
  VALID_CLIENT_OPTIONS = [:user, :password, :timeout, :open_timeout, :ssl_client_cert, :ssl_client_key]
@@ -59,6 +61,14 @@ module Rubydora
59
61
  end
60
62
  end
61
63
 
64
+ def describe options = {}
65
+ query_options = options.dup
66
+ query_options[:xml] ||= 'true'
67
+ client[describe_repository_url(query_options)].get
68
+ rescue Exception => exception
69
+ rescue_with_handler(exception) || raise
70
+ end
71
+
62
72
  # {include:RestApiClient::API_DOCUMENTATION}
63
73
  # @param [Hash] options
64
74
  # @return [String]
@@ -106,7 +116,12 @@ module Rubydora
106
116
  # @return [String]
107
117
  def ingest options = {}
108
118
  query_options = options.dup
109
- pid = query_options.delete(:pid) || 'new'
119
+ pid = query_options.delete(:pid)
120
+
121
+ if pid.nil?
122
+ return mint_pid_and_ingest options
123
+ end
124
+
110
125
  file = query_options.delete(:file)
111
126
  assigned_pid = client[object_url(pid, query_options)].post((file.dup if file), :content_type => 'text/xml')
112
127
  run_hook :after_ingest, :pid => assigned_pid, :file => file, :options => options
@@ -115,6 +130,17 @@ module Rubydora
115
130
  rescue_with_handler(exception) || raise
116
131
  end
117
132
 
133
+ def mint_pid_and_ingest options = {}
134
+ query_options = options.dup
135
+ file = query_options.delete(:file)
136
+
137
+ assigned_pid = client[new_object_url(query_options)].post((file.dup if file), :content_type => 'text/xml')
138
+ run_hook :after_ingest, :pid => assigned_pid, :file => file, :options => options
139
+ assigned_pid
140
+ rescue Exception => exception
141
+ rescue_with_handler(exception) || raise
142
+ end
143
+
118
144
  # {include:RestApiClient::API_DOCUMENTATION}
119
145
  # @param [Hash] options
120
146
  # @option options [String] :pid
@@ -193,10 +219,16 @@ module Rubydora
193
219
  query_options = options.dup
194
220
  pid = query_options.delete(:pid)
195
221
  dsid = query_options.delete(:dsid)
222
+ raise ArgumentError, "Missing required parameter :pid" unless pid
223
+
224
+ if dsid.nil?
225
+ #raise ArgumentError, "Missing required parameter :dsid" unless dsid
226
+ Deprecation.warn(RestApiClient, "Calling Rubydora::RestApiClient#datastream without a :dsid is deprecated, use #datastreams instead")
227
+ return datastreams(options)
228
+ end
196
229
  query_options[:format] ||= 'xml'
197
230
  val = nil
198
- message = dsid.nil? ? "Loaded datastream list for #{pid}" : "Loaded datastream profile #{pid}/#{dsid}"
199
- benchmark message, :level=>:debug do
231
+ benchmark "Loaded datastream profile #{pid}/#{dsid}", :level=>:debug do
200
232
  val = client[datastream_url(pid, dsid, query_options)].get
201
233
  end
202
234
 
@@ -208,7 +240,29 @@ module Rubydora
208
240
  rescue_with_handler(exception) || raise
209
241
  end
210
242
 
211
- alias_method :datastreams, :datastream
243
+ def datastreams options = {}
244
+ unless options[:dsid].nil?
245
+ #raise ArgumentError, "Missing required parameter :dsid" unless dsid
246
+ Deprecation.warn(RestApiClient, "Calling Rubydora::RestApiClient#datastreams with a :dsid is deprecated, use #datastream instead")
247
+ return datastream(options)
248
+ end
249
+ query_options = options.dup
250
+ pid = query_options.delete(:pid)
251
+ raise ArgumentError, "Missing required parameter :pid" unless pid
252
+ query_options[:format] ||= 'xml'
253
+ val = nil
254
+ benchmark "Loaded datastream list for #{pid}", :level=>:debug do
255
+ val = client[datastreams_url(pid, query_options)].get
256
+ end
257
+
258
+ val
259
+ rescue RestClient::Unauthorized => e
260
+ logger.error "Unauthorized at #{client.url}/#{datastreams_url(pid, query_options)}"
261
+ raise e
262
+ rescue Exception => exception
263
+ rescue_with_handler(exception) || raise
264
+
265
+ end
212
266
 
213
267
  # {include:RestApiClient::API_DOCUMENTATION}
214
268
  # @param [Hash] options
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "mime-types"
24
24
  s.add_dependency "activesupport"
25
25
  s.add_dependency "activemodel"
26
- s.add_dependency "hooks"
26
+ s.add_dependency "hooks", "~> 0.2.2"
27
27
  s.add_dependency "deprecation"
28
28
 
29
29
  s.add_development_dependency("rake")
@@ -123,6 +123,10 @@ describe Rubydora::Datastream do
123
123
  @datastream.versionable.should be_false
124
124
  end
125
125
 
126
+ it "should be the current version" do
127
+ @datastream.current_version?.should be_true
128
+ end
129
+
126
130
  # it "should cast versionable to boolean" do
127
131
  # @datastream.profile['versionable'] = 'true'
128
132
  # @datastream.versionable.should be_true
@@ -466,6 +470,36 @@ describe Rubydora::Datastream do
466
470
  Rubydora::Datastream.any_instance.stub(:new? => false)
467
471
  @datastream.versions.last.content
468
472
  end
473
+
474
+ it "should be the current version" do
475
+ @mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return <<-XML
476
+ <datastreamProfile>
477
+ <dsVersionID>dsid.1</dsVersionID>
478
+ <dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
479
+ </datastreamProfile>
480
+ XML
481
+ @datastream.current_version?.should be_true
482
+ end
483
+
484
+ it "should be the current version if it's the first version" do
485
+ @mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime =>'2010-01-02T00:00:00.012Z')).and_return <<-XML
486
+ <datastreamProfile>
487
+ <dsVersionID>dsid.1</dsVersionID>
488
+ <dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
489
+ </datastreamProfile>
490
+ XML
491
+ @datastream.versions.first.current_version?.should be_true
492
+ end
493
+
494
+ it "should not be the current version if it's the second version" do
495
+ @mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime => '2008-08-05T01:30:05.012Z')).and_return <<-XML
496
+ <datastreamProfile>
497
+ <dsVersionID>dsid.0</dsVersionID>
498
+ <dsCreateDate>2008-08-05T01:30:05.012Z</dsCreateDate>
499
+ </datastreamProfile>
500
+ XML
501
+ @datastream.versions[1].current_version?.should be_false
502
+ end
469
503
  end
470
504
  describe "when no versions are found" do
471
505
  before(:each) do
@@ -477,6 +511,11 @@ describe Rubydora::Datastream do
477
511
  @datastream.versions.should be_empty
478
512
  end
479
513
 
514
+ it "should be the current version" do
515
+ @datastream.stub(:new? => false)
516
+ @datastream.current_version?.should be_true
517
+ end
518
+
480
519
  end
481
520
 
482
521
  end
@@ -34,17 +34,17 @@ describe "Integration testing against a live Fedora repository", :integration =>
34
34
  end
35
35
 
36
36
  it "should create an object" do
37
- obj = Rubydora::DigitalObject.new('test:1', @repository)
37
+ obj = @repository.find_or_initialize('test:1')
38
38
  obj.new?.should == true
39
39
  obj.save
40
40
  obj.new?.should == false
41
41
  end
42
42
 
43
43
  it "new should not return true until the profile is read" do
44
- obj = Rubydora::DigitalObject.new('test:1', @repository)
44
+ obj = @repository.find_or_initialize('test:1')
45
45
  obj.save
46
- new_obj = Rubydora::DigitalObject.new('test:1', @repository)
47
- new_obj.new?.should == false
46
+ obj = @repository.find('test:1')
47
+ obj.should_not be_new
48
48
  end
49
49
 
50
50
  it "should have default datastreams" do
@@ -58,13 +58,13 @@ describe "Integration testing against a live Fedora repository", :integration =>
58
58
  end
59
59
 
60
60
  it "should create another object" do
61
- obj = Rubydora::DigitalObject.new('test:2', @repository)
61
+ obj = @repository.find_or_initialize('test:2')
62
62
  obj.save
63
63
  obj.new?.should == false
64
64
  end
65
65
 
66
66
  it "should create and update object labels" do
67
- obj = Rubydora::DigitalObject.new('test:3', @repository)
67
+ obj = @repository.find_or_initialize('test:3')
68
68
  obj.label = 'asdf'
69
69
  obj.save
70
70
 
@@ -78,12 +78,10 @@ describe "Integration testing against a live Fedora repository", :integration =>
78
78
 
79
79
  end
80
80
 
81
- it "should persist parts" do
82
- obj = @repository.find('test:1')
83
- end
81
+ describe "datastream stuff" do
84
82
 
85
83
  it "should create a managed datastream" do
86
- obj = @repository.find('test:1')
84
+ obj = @repository.find_or_initialize('test:1')
87
85
  obj.save
88
86
  ds = obj.datastreams["Test"]
89
87
 
@@ -93,7 +91,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
93
91
  end
94
92
 
95
93
  it "should create a redirect datastream" do
96
- obj = @repository.find('test:1')
94
+ obj = @repository.find_or_initialize('test:1')
97
95
  ds = obj.datastreams["Redirect"]
98
96
  ds.controlGroup = "R"
99
97
  ds.dsLocation = "http://example.org"
@@ -101,7 +99,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
101
99
  end
102
100
 
103
101
  it "should have datastreams" do
104
- obj = @repository.find('test:1')
102
+ obj = @repository.find_or_initialize('test:1')
105
103
  obj.datastreams.keys.should include("Test")
106
104
  obj.datastreams.keys.should include("Redirect")
107
105
  end
@@ -112,7 +110,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
112
110
  end
113
111
 
114
112
  it "should have profile attributes" do
115
- obj = @repository.find('test:1')
113
+ obj = @repository.find_or_initialize('test:1')
116
114
  ds = obj.datastreams["Test"]
117
115
 
118
116
  ds.versionID.should == "Test.0"
@@ -122,15 +120,16 @@ describe "Integration testing against a live Fedora repository", :integration =>
122
120
  ds.controlGroup.should == "M"
123
121
  ds.size.should be > 100
124
122
  end
123
+ end
125
124
 
126
125
  it "should delete datastreams" do
127
- obj = @repository.find('test:1')
126
+ obj = @repository.find_or_initialize('test:1')
128
127
  ds = obj.datastreams["Test"].delete
129
128
  obj.datastreams.keys.should_not include("Test")
130
129
  end
131
130
 
132
131
  it "should save changed datastreams when the object is saved" do
133
- obj = Rubydora::DigitalObject.new('test:1', @repository)
132
+ obj = @repository.find_or_initialize('test:1')
134
133
  obj.datastreams["new_ds"].content = "XXX"
135
134
  obj.datastreams["empty_ds"].new?
136
135
  obj.save
@@ -140,7 +139,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
140
139
  end
141
140
 
142
141
  it "should update datastream attributes without changing the content (or mime type)" do
143
- obj = Rubydora::DigitalObject.new('test:1', @repository)
142
+ obj = @repository.find_or_initialize('test:1')
144
143
  obj.datastreams["my_ds"].content = "XXX"
145
144
  obj.datastreams["my_ds"].mimeType = "application/x-text"
146
145
  obj.save
@@ -156,7 +155,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
156
155
  end
157
156
 
158
157
  it "should save IO-based datastreams" do
159
- obj = @repository.find('test:1')
158
+ obj = @repository.find_or_initialize('test:1')
160
159
  ds = obj.datastreams['gemspec']
161
160
  ds.controlGroup = 'M'
162
161
  ds.content = File.open('rubydora.gemspec', 'r')
@@ -170,7 +169,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
170
169
  @repository.find('transactions:1').delete rescue nil
171
170
 
172
171
  @repository.transaction do |t|
173
- obj = Rubydora::DigitalObject.new('transactions:1', @repository)
172
+ obj = @repository.find_or_initialize('transactions:1')
174
173
  obj.save
175
174
 
176
175
  t.rollback
@@ -182,7 +181,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
182
181
  it "should work on purge" do
183
182
  @repository.find('transactions:1').delete rescue nil
184
183
 
185
- obj = Rubydora::DigitalObject.new('transactions:1', @repository)
184
+ obj = @repository.find_or_initialize('transactions:1')
186
185
  obj.save
187
186
 
188
187
  @repository.transaction do |t|
@@ -239,9 +238,10 @@ describe "Integration testing against a live Fedora repository", :integration =>
239
238
  end
240
239
 
241
240
  it "should work on relationships" do
241
+ pending("fcrepo 3.6's relationship api is busted; skipping") if @repository.version == 3.6
242
242
  @repository.find('transactions:1').delete rescue nil
243
243
 
244
- obj = Rubydora::DigitalObject.new('transactions:1', @repository)
244
+ obj = @repository.find_or_initialize('transactions:1')
245
245
  obj.save
246
246
  @repository.add_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
247
247
 
@@ -266,7 +266,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
266
266
  end
267
267
 
268
268
  it "should have read-only versions" do
269
- obj = Rubydora::DigitalObject.new('test:1', @repository)
269
+ obj = @repository.find_or_initialize('test:1')
270
270
  expect { obj.versions.first.label = "asdf" }.to raise_error
271
271
  end
272
272
 
@@ -285,7 +285,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
285
285
  #end
286
286
 
287
287
  it "should access datastreams list using asOfDateTime (and pass the asOfDateTime through to the datastreams)" do
288
- obj = Rubydora::DigitalObject.new('test:1', @repository)
288
+ obj = @repository.find_or_initialize('test:1')
289
289
  oldest = obj.versions.first.datastreams.keys
290
290
  newest = obj.versions.last.datastreams.keys
291
291
  (newest - oldest).should_not be_empty
@@ -297,21 +297,21 @@ describe "Integration testing against a live Fedora repository", :integration =>
297
297
  describe "datastream versions" do
298
298
 
299
299
  it "should have versions" do
300
- obj = Rubydora::DigitalObject.new('test:1', @repository)
300
+ obj = @repository.find_or_initialize('test:1')
301
301
  versions = obj.datastreams["my_ds"].versions
302
302
  versions.should_not be_empty
303
303
  versions.map { |x| x.versionID }.should include('my_ds.1', 'my_ds.0')
304
304
  end
305
305
 
306
306
  it "should have read-only versions" do
307
- obj = Rubydora::DigitalObject.new('test:1', @repository)
307
+ obj = @repository.find_or_initialize('test:1')
308
308
  ds = obj.datastreams["my_ds"].asOfDateTime(Time.now)
309
309
  expect { ds.dsLabel = 'asdf' }.to raise_error
310
310
  expect { ds.content = 'asdf' }.to raise_error
311
311
  end
312
312
 
313
313
  it "should access the content of older datastreams" do
314
- obj = Rubydora::DigitalObject.new('test:1', @repository)
314
+ obj = @repository.find_or_initialize('test:1')
315
315
 
316
316
  ds = obj.datastreams["my_ds"]
317
317
  ds.content = "YYY"
@@ -322,7 +322,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
322
322
  end
323
323
 
324
324
  it "should allow the user to go from a versioned datastream to an unversioned datastream" do
325
- obj = Rubydora::DigitalObject.new('test:1', @repository)
325
+ obj = @repository.find_or_initialize('test:1')
326
326
  versions_count = obj.datastreams["my_ds"].versions.length
327
327
 
328
328
  obj.datastreams["my_ds"].versionable.should be_true
@@ -345,12 +345,12 @@ describe "Integration testing against a live Fedora repository", :integration =>
345
345
 
346
346
  context "mime types" do
347
347
  before(:each) do
348
- obj = @repository.find('test:1')
348
+ obj = @repository.find_or_initialize('test:1')
349
349
  obj.datastreams["my_ds"].delete rescue nil
350
350
  end
351
351
 
352
352
  it "should default to application/octet-stream" do
353
- obj = Rubydora::DigitalObject.new('test:1', @repository)
353
+ obj = @repository.find_or_initialize('test:1')
354
354
  obj.datastreams["my_ds"].content = "XXX"
355
355
  obj.save
356
356
 
@@ -359,7 +359,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
359
359
  end
360
360
 
361
361
  it "should allow the user to specify a mimetype" do
362
- obj = Rubydora::DigitalObject.new('test:1', @repository)
362
+ obj = @repository.find_or_initialize('test:1')
363
363
  obj.datastreams["my_ds"].content = "XXX"
364
364
  obj.datastreams["my_ds"].mimeType = "text/plain"
365
365
  obj.save
@@ -369,7 +369,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
369
369
  end
370
370
 
371
371
  it "should preserve the mimetype on update" do
372
- obj = Rubydora::DigitalObject.new('test:1', @repository)
372
+ obj = @repository.find_or_initialize('test:1')
373
373
  obj.datastreams["my_ds"].content = "XXX"
374
374
  obj.datastreams["my_ds"].mimeType = "text/plain"
375
375
  obj.save
@@ -383,7 +383,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
383
383
  end
384
384
 
385
385
  it "should allow the mimetype to be changed" do
386
- obj = @repository.find('test:1')
386
+ obj = @repository.find_or_initialize('test:1')
387
387
  obj.datastreams["my_ds"].content = "XXX"
388
388
  obj.datastreams["my_ds"].mimeType = "text/plain"
389
389
  obj.save
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rubydora::Repository do
4
+ include Rubydora::FedoraUrlHelpers
5
+
4
6
  before(:each) do
5
7
  @repository = Rubydora::Repository.new
6
8
  end
@@ -45,7 +47,7 @@ describe Rubydora::Repository do
45
47
  @mock_response.should_receive(:get).and_return <<-XML
46
48
  <?xml version="1.0" encoding="UTF-8"?><fedoraRepository xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/ http://www.fedora.info/definitions/1/0/fedoraRepository.xsd"><repositoryName>Fedora Repository</repositoryName><repositoryBaseURL>http://localhost:8983/fedora</repositoryBaseURL><repositoryVersion>3.3</repositoryVersion><repositoryPID> <PID-namespaceIdentifier>changeme</PID-namespaceIdentifier> <PID-delimiter>:</PID-delimiter> <PID-sample>changeme:100</PID-sample> <retainPID>*</retainPID></repositoryPID><repositoryOAI-identifier> <OAI-namespaceIdentifier>example.org</OAI-namespaceIdentifier> <OAI-delimiter>:</OAI-delimiter> <OAI-sample>oai:example.org:changeme:100</OAI-sample></repositoryOAI-identifier><sampleSearch-URL>http://localhost:8983/fedora/search</sampleSearch-URL><sampleAccess-URL>http://localhost:8983/fedora/get/demo:5</sampleAccess-URL><sampleOAI-URL>http://localhost:8983/fedora/oai?verb=Identify</sampleOAI-URL><adminEmail>bob@example.org</adminEmail><adminEmail>sally@example.org</adminEmail></fedoraRepository>
47
49
  XML
48
- @mock_client.should_receive(:[]).with('describe?xml=true').and_return(@mock_response)
50
+ @mock_client.should_receive(:[]).with(describe_repository_url(:xml=> true)).and_return(@mock_response)
49
51
  @repository.should_receive(:client).and_return(@mock_client)
50
52
  profile = @repository.profile
51
53
  profile['repositoryVersion'].should == '3.3'
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rubydora::RestApiClient do
4
+
5
+ include Rubydora::FedoraUrlHelpers
6
+
4
7
  class FakeException < Exception
5
8
 
6
9
  end
@@ -24,6 +27,7 @@ describe Rubydora::RestApiClient do
24
27
  }
25
28
 
26
29
  it "should replace a RestClient exception with a Rubydora one" do
30
+ Deprecation.stub(:warn)
27
31
  subject.stub_chain(:client, :[], :get).and_raise RestClient::InternalServerError.new
28
32
  subject.stub_chain(:client, :[], :put).and_raise RestClient::InternalServerError.new
29
33
  subject.stub_chain(:client, :[], :delete).and_raise RestClient::InternalServerError.new
@@ -32,7 +36,7 @@ describe Rubydora::RestApiClient do
32
36
  end
33
37
  end
34
38
 
35
- [:next_pid, :find_objects, :object, :ingest, :export, :modify_object, :purge_object, :object_versions, :object_xml, :datastream, :datastreams, :set_datastream_options, :datastream_versions, :datastream_history, :datastream_dissemination, :add_datastream, :modify_datastream, :purge_datastream, :relationships, :add_relationship, :purge_relationship, :dissemination].each do |method|
39
+ [:next_pid, :find_objects, :object, :ingest, :mint_pid_and_ingest, :export, :modify_object, :purge_object, :object_versions, :object_xml, :datastream, :datastreams, :set_datastream_options, :datastream_versions, :datastream_history, :datastream_dissemination, :add_datastream, :modify_datastream, :purge_datastream, :relationships, :add_relationship, :purge_relationship, :dissemination].each do |method|
36
40
 
37
41
  class_eval %Q{
38
42
  describe "##{method}" do
@@ -45,13 +49,16 @@ describe Rubydora::RestApiClient do
45
49
  end
46
50
 
47
51
 
52
+ let :base_url do
53
+ "http://example.org"
54
+ end
48
55
 
49
56
 
50
57
  before(:each) do
51
58
  @fedora_user = 'fedoraAdmin'
52
59
  @fedora_password = 'fedoraAdmin'
53
60
  @mock_repository = MockRepository.new
54
- @mock_repository.config = { :url => 'http://example.org',:user => @fedora_user, :password => @fedora_password}
61
+ @mock_repository.config = { :url => base_url,:user => @fedora_user, :password => @fedora_password}
55
62
  end
56
63
 
57
64
  it "should create a REST client" do
@@ -76,42 +83,48 @@ describe Rubydora::RestApiClient do
76
83
  end
77
84
 
78
85
  it "should call nextPID" do
79
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/nextPID?format=xml"))
86
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + next_pid_url(:format => 'xml')))
80
87
  @mock_repository.next_pid
81
88
  end
82
89
 
83
90
  it "should find objects" do
84
91
  RestClient::Request.should_receive(:execute) do |params|
85
92
  params.should have_key(:url)
86
- params[:url].should =~ /^#{Regexp.escape("http://example.org/objects?")}.*query=a/
93
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + find_objects_url + "?")}.*query=a/
87
94
  end
88
95
  @mock_repository.find_objects :query => 'a'
89
96
  end
90
97
 
91
98
 
92
99
  it "should show object properties" do
93
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/z?format=xml"))
100
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('z', :format => 'xml')))
94
101
  @mock_repository.object :pid => 'z'
95
102
  end
96
103
 
97
104
  it "should raise not found exception when retrieving object" do
98
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/z?format=xml")).and_raise( RestClient::ResourceNotFound)
105
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('z', :format => 'xml'))).and_raise( RestClient::ResourceNotFound)
99
106
  lambda {@mock_repository.object(:pid => 'z')}.should raise_error RestClient::ResourceNotFound
100
107
  end
101
108
 
102
109
  it "ingest" do
103
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/new"))
110
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + new_object_url))
111
+ @mock_repository.ingest
112
+ end
113
+
114
+
115
+ it "mint_pid_and_ingest" do
116
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + new_object_url))
104
117
  @mock_repository.ingest
105
118
  end
106
119
 
107
120
  it "ingest with pid" do
108
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid"))
121
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
109
122
  @mock_repository.ingest :pid => 'mypid'
110
123
  end
111
124
 
112
125
  describe "export" do
113
126
  it "should work on the happy path" do
114
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/export"))
127
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + export_object_url('mypid')))
115
128
  @mock_repository.export :pid => 'mypid'
116
129
  end
117
130
  it "should require a pid" do
@@ -122,56 +135,68 @@ describe Rubydora::RestApiClient do
122
135
  it "modify_object" do
123
136
  RestClient::Request.should_receive(:execute) do |params|
124
137
  params.should have_key(:url)
125
- params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid?")}.*state=Z/
138
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_url('mypid'))}.*state=Z/
126
139
  end
127
140
  @mock_repository.modify_object :pid => 'mypid', :state => 'Z'
128
141
  end
129
142
 
130
143
  it "purge_object" do
131
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid"))
144
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
132
145
  @mock_repository.purge_object :pid => 'mypid'
133
146
  end
134
147
 
135
148
  it "should raise not found exception when purging" do
136
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid")).and_raise( RestClient::ResourceNotFound)
149
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid'))).and_raise( RestClient::ResourceNotFound)
137
150
  lambda {@mock_repository.purge_object(:pid => 'mypid')}.should raise_error RestClient::ResourceNotFound
138
151
  end
139
152
 
140
153
  it "object_versions" do
141
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/versions?format=xml"))
154
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_versions_url('mypid', :format => 'xml')))
142
155
  @mock_repository.object_versions :pid => 'mypid'
143
156
  end
144
157
 
145
158
  it "object_xml" do
146
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/objectXML?format=xml"))
159
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_xml_url('mypid', :format => 'xml')))
147
160
  @mock_repository.object_xml :pid => 'mypid'
148
161
  end
149
162
 
150
163
  it "datastream" do
151
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams?format=xml"))
164
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastreams_url('mypid', :format => 'xml')))
152
165
  logger.should_receive(:debug) # squelch message "Loaded datastream list for mypid (time)"
166
+ @mock_repository.datastreams :pid => 'mypid'
167
+ end
168
+
169
+ it "datastreams" do
170
+ @mock_repository.should_receive(:datastream).with(:pid => 'mypid', :dsid => 'asdf')
171
+ Deprecation.should_receive(:warn)
172
+ @mock_repository.datastreams :pid => 'mypid', :dsid => 'asdf'
173
+ end
174
+
175
+ it "datastream" do
176
+ @mock_repository.should_receive(:datastreams).with(:pid => 'mypid')
177
+ Deprecation.should_receive(:warn)
153
178
  @mock_repository.datastream :pid => 'mypid'
154
179
  end
155
180
 
156
181
  it "datastream" do
157
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
182
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa', :format => 'xml')))
158
183
  logger.should_receive(:debug) # squelch message "Loaded datastream mypid/aaa (time)"
159
184
  @mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'
160
185
  end
161
186
 
162
187
  it "should raise not found exception when getting a datastream" do
163
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml")).and_raise( RestClient::ResourceNotFound)
188
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa', :format => 'xml'))).and_raise( RestClient::ResourceNotFound)
164
189
  lambda {@mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::ResourceNotFound
165
190
  end
166
191
 
167
192
  it "should raise Unauthorized exception when getting a datastream" do
168
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml")).and_raise( RestClient::Unauthorized)
169
- logger.should_receive(:error).with("Unauthorized at http://example.org/objects/mypid/datastreams/aaa?format=xml")
193
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa', :format => 'xml'))).and_raise( RestClient::Unauthorized)
194
+ logger.should_receive(:error).with("Unauthorized at #{base_url + "/" + datastream_url('mypid', 'aaa', :format => 'xml')}")
170
195
  lambda {@mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::Unauthorized
171
196
  end
172
197
 
173
198
  it "datastream_dissemination" do
174
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content"))
199
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa')))
175
200
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'
176
201
  end
177
202
  it "should allow http methods besides GET on datastream_dissemination" do
@@ -184,13 +209,13 @@ describe Rubydora::RestApiClient do
184
209
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa', &_proc
185
210
  end
186
211
  it "should raise not found exception when retrieving datastream_dissemination" do
187
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content")).and_raise( RestClient::ResourceNotFound)
212
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa'))).and_raise( RestClient::ResourceNotFound)
188
213
  lambda {@mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::ResourceNotFound
189
214
  end
190
215
 
191
216
  describe "add_datastream" do
192
217
  it "should post to the correct url" do
193
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa"))
218
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa')))
194
219
  @mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
195
220
  end
196
221
 
@@ -206,11 +231,11 @@ describe Rubydora::RestApiClient do
206
231
 
207
232
  describe "modify datastream" do
208
233
  it "should not set mime-type when it's not provided" do
209
- RestClient::Request.should_receive(:execute).with(:url => "http://example.org/objects/mypid/datastreams/aaa",:open_timeout=>nil, :payload=>nil, :user=>@fedora_user, :password=>@fedora_password, :method=>:put, :headers=>{})
234
+ RestClient::Request.should_receive(:execute).with(:url => base_url + "/" + datastream_url('mypid', 'aaa'),:open_timeout=>nil, :payload=>nil, :user=>@fedora_user, :password=>@fedora_password, :method=>:put, :headers=>{})
210
235
  @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
211
236
  end
212
237
  it "should pass the provided mimeType header" do
213
- RestClient::Request.should_receive(:execute).with(:url => "http://example.org/objects/mypid/datastreams/aaa?mimeType=application%2Fjson",:open_timeout=>nil, :payload=>nil, :user=>@fedora_user, :password=>@fedora_password, :method=>:put, :headers=>{})
238
+ RestClient::Request.should_receive(:execute).with(:url => base_url + "/" + datastream_url('mypid', 'aaa', :mimeType => 'application/json'),:open_timeout=>nil, :payload=>nil, :user=>@fedora_user, :password=>@fedora_password, :method=>:put, :headers=>{})
214
239
  @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa', :mimeType=>'application/json'
215
240
  end
216
241
  describe "when a file is passed" do
@@ -224,43 +249,43 @@ describe Rubydora::RestApiClient do
224
249
  end
225
250
 
226
251
  it "purge_datastream" do
227
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa"))
252
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa')))
228
253
  @mock_repository.purge_datastream :pid => 'mypid', :dsid => 'aaa'
229
254
  end
230
255
 
231
256
  it "set_datastream_options" do
232
257
  RestClient::Request.should_receive(:execute) do |params|
233
258
  params.should have_key(:url)
234
- params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/datastreams/aaa?")}.*aparam=true/
259
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + datastream_url('mypid', 'aaa') + "?")}.*aparam=true/
235
260
  end
236
261
  @mock_repository.set_datastream_options :pid => 'mypid', :dsid => 'aaa', :aparam => true
237
262
  end
238
263
 
239
264
  describe "datastream_versions" do
240
265
  it "should be successful" do
241
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/history?format=xml")).and_return("expected result")
266
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_return("expected result")
242
267
  @mock_repository.datastream_versions(:pid => 'mypid', :dsid => 'aaa').should == 'expected result'
243
268
  end
244
269
  it "should not break when fedora doesn't have datastream history" do
245
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/history?format=xml")).and_raise(RestClient::ResourceNotFound)
270
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_raise(RestClient::ResourceNotFound)
246
271
  @mock_repository.datastream_versions(:pid => 'mypid', :dsid => 'aaa').should be_nil
247
272
  end
248
273
  end
249
274
 
250
275
  it "datastream_history" do
251
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/history?format=xml"))
276
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml')))
252
277
  @mock_repository.datastream_history :pid => 'mypid', :dsid => 'aaa'
253
278
  end
254
279
 
255
280
  it "relationships" do
256
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/relationships?format=xml"))
281
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_relationship_url('mypid', :format => 'xml')))
257
282
  @mock_repository.relationships :pid => 'mypid'
258
283
  end
259
284
 
260
285
  it "add_relationship" do
261
286
  RestClient::Request.should_receive(:execute) do |params|
262
287
  params.should have_key(:url)
263
- params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/relationships/new?")}.*subject=z/
288
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + new_object_relationship_url('mypid') + "?")}.*subject=z/
264
289
  end
265
290
  @mock_repository.add_relationship :pid => 'mypid', :subject => 'z'
266
291
  end
@@ -268,23 +293,23 @@ describe Rubydora::RestApiClient do
268
293
  it "purge_relationships" do
269
294
  RestClient::Request.should_receive(:execute) do |params|
270
295
  params.should have_key(:url)
271
- params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/relationships?")}.*subject=z/
296
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_relationship_url('mypid') + "?")}.*subject=z/
272
297
  end
273
298
  @mock_repository.purge_relationship :pid => 'mypid', :subject => 'z'
274
299
  end
275
300
 
276
301
  it "dissemination" do
277
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods?format=xml"))
302
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', nil, nil, :format => 'xml')))
278
303
  @mock_repository.dissemination :pid => 'mypid'
279
304
  end
280
305
 
281
306
  it "dissemination" do
282
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef?format=xml"))
307
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', nil, :format => 'xml')))
283
308
  @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef'
284
309
  end
285
310
 
286
311
  it "dissemination" do
287
- RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef/method"))
312
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', 'method')))
288
313
  @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method'
289
314
  end
290
315
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydora
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-02 00:00:00.000000000 Z
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastercsv
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: hooks
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.2.2
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 0.2.2
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: deprecation
127
127
  requirement: !ruby/object:Gem::Requirement