rubydora 1.8.1 → 1.9.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.
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  # These tests require a fedora repository with the resource index enabled (and with syncUpdates = true)
5
4
  describe "Integration testing against a live Fedora repository", :integration => true do
6
5
  REPOSITORY_CONFIG = { :url => "http://localhost:#{ENV['TEST_JETTY_PORT'] || 8983}/fedora", :user => 'fedoraAdmin', :password => 'fedoraAdmin' }
@@ -81,54 +80,54 @@ describe "Integration testing against a live Fedora repository", :integration =>
81
80
 
82
81
  describe "datastream stuff" do
83
82
 
84
- it "should create a managed datastream" do
85
- obj = @repository.find_or_initialize('test:1')
86
- obj.save
87
- ds = obj.datastreams["Test"]
83
+ it "should create a managed datastream" do
84
+ obj = @repository.find_or_initialize('test:1')
85
+ obj.save
86
+ ds = obj.datastreams["Test"]
88
87
 
89
- ds.content = open(__FILE__).read
90
- ds.mimeType = 'text/plain'
91
- ds.save
92
- end
88
+ ds.content = open(__FILE__).read
89
+ ds.mimeType = 'text/plain'
90
+ ds.save
91
+ end
93
92
 
94
- it "should create a redirect datastream" do
95
- obj = @repository.find_or_initialize('test:1')
96
- ds = obj.datastreams["Redirect"]
97
- ds.controlGroup = "R"
98
- ds.dsLocation = "http://example.org"
99
- ds.save
100
- end
93
+ it "should create a redirect datastream" do
94
+ obj = @repository.find_or_initialize('test:1')
95
+ ds = obj.datastreams["Redirect"]
96
+ ds.controlGroup = "R"
97
+ ds.dsLocation = "http://example.org"
98
+ ds.save
99
+ end
101
100
 
102
- it "should have datastreams" do
103
- obj = @repository.find_or_initialize('test:1')
104
- obj.datastreams.keys.should include("Test")
105
- obj.datastreams.keys.should include("Redirect")
106
- end
101
+ it "should have datastreams" do
102
+ obj = @repository.find_or_initialize('test:1')
103
+ obj.datastreams.keys.should include("Test")
104
+ obj.datastreams.keys.should include("Redirect")
105
+ end
107
106
 
108
- it "should have datastream content" do
109
- obj = @repository.find('test:1')
110
- obj.datastreams["Test"].content.should match( "Integration testing against a live Fedora repository")
111
- end
107
+ it "should have datastream content" do
108
+ obj = @repository.find('test:1')
109
+ obj.datastreams["Test"].content.should match( "Integration testing against a live Fedora repository")
110
+ end
112
111
 
113
- it "should have profile attributes" do
114
- obj = @repository.find_or_initialize('test:1')
115
- ds = obj.datastreams["Test"]
112
+ it "should have profile attributes" do
113
+ obj = @repository.find_or_initialize('test:1')
114
+ ds = obj.datastreams["Test"]
116
115
 
117
- ds.versionID.should == "Test.0"
116
+ ds.versionID.should == "Test.0"
118
117
 
119
- (Time.now - ds.createDate).should be < 60*60 # 1 hour
120
- ds.state.should == "A"
121
- ds.controlGroup.should == "M"
122
- ds.size.should be > 100
123
- end
118
+ (Time.now - ds.createDate).should be < 60*60 # 1 hour
119
+ ds.state.should == "A"
120
+ ds.controlGroup.should == "M"
121
+ ds.size.should be > 100
122
+ end
124
123
 
125
- it "should not mark existing datastreams as changed on load" do
126
- obj = @repository.find('fedora-system:ContentModel-3.0')
127
- obj.datastreams.each do |k,v|
128
- v.changed?.should be false
129
- v.new?.should be false
124
+ it "should not mark existing datastreams as changed on load" do
125
+ obj = @repository.find('fedora-system:ContentModel-3.0')
126
+ obj.datastreams.each do |k,v|
127
+ v.changed?.should be false
128
+ v.new?.should be false
129
+ end
130
130
  end
131
- end
132
131
 
133
132
  end
134
133
 
@@ -186,99 +185,98 @@ describe "Integration testing against a live Fedora repository", :integration =>
186
185
  obj.save
187
186
  end
188
187
 
189
-
190
188
  describe "with transactions" do
191
189
  it "should work on ingest" do
192
- @repository.find('transactions:1').delete rescue nil
190
+ @repository.find('transactions:1').delete rescue nil
193
191
 
194
- @repository.transaction do |t|
195
- obj = @repository.find_or_initialize('transactions:1')
196
- obj.save
192
+ @repository.transaction do |t|
193
+ obj = @repository.find_or_initialize('transactions:1')
194
+ obj.save
197
195
 
198
- t.rollback
199
- end
196
+ t.rollback
197
+ end
200
198
 
201
- lambda { @repository.find('transactions:1') }.should raise_error Rubydora::RecordNotFound
199
+ lambda { @repository.find('transactions:1') }.should raise_error Rubydora::RecordNotFound
202
200
  end
203
201
 
204
202
  it "should work on purge" do
205
- @repository.find('transactions:1').delete rescue nil
203
+ @repository.find('transactions:1').delete rescue nil
206
204
 
207
- obj = @repository.find_or_initialize('transactions:1')
208
- obj.save
205
+ obj = @repository.find_or_initialize('transactions:1')
206
+ obj.save
209
207
 
210
- @repository.transaction do |t|
211
- obj.delete
208
+ @repository.transaction do |t|
209
+ obj.delete
212
210
 
213
- t.rollback
214
- end
211
+ t.rollback
212
+ end
215
213
 
216
- obj = @repository.find('transactions:1')
217
- obj.should_not be_new
214
+ obj = @repository.find('transactions:1')
215
+ obj.should_not be_new
218
216
  end
219
217
 
220
218
  it "should work on datastreams" do
221
- @repository.find('transactions:1').delete rescue nil
222
- obj = Rubydora::DigitalObject.new('transactions:1', @repository)
223
- obj.save
224
-
225
- ds = obj.datastreams['datastream_to_delete']
226
- ds.content = 'asdf'
227
- ds.save
228
-
229
- ds2 = obj.datastreams['datastream_to_change']
230
- ds2.content = 'asdf'
231
- ds2.save
232
-
233
- ds3 = obj.datastreams['datastream_to_change_properties']
234
- ds3.content = 'asdf'
235
- ds3.versionable = true
236
- ds3.dsState = 'I'
237
- ds3.save
238
-
239
- @repository.transaction do |t|
240
- ds.delete
241
-
242
- ds2.content = '1234'
243
- ds2.save
244
-
245
- @repository.set_datastream_options :pid => obj.pid, :dsid => 'datastream_to_change_properties', :state => 'A'
246
- @repository.set_datastream_options :pid => obj.pid, :dsid => 'datastream_to_change_properties', :versionable => false
247
-
248
- ds4 = obj.datastreams['datastream_to_create']
249
- ds4.content = 'asdf'
250
- ds4.save
251
-
252
- t.rollback
253
- end
254
-
255
- obj = @repository.find('transactions:1')
256
- obj.datastreams.keys.should_not include('datsatream_to_create')
257
- obj.datastreams.keys.should include('datastream_to_delete')
258
- obj.datastreams['datastream_to_change'].content.should == 'asdf'
259
- obj.datastreams['datastream_to_change_properties'].versionable.should == true
260
- obj.datastreams['datastream_to_change_properties'].dsState.should == 'I'
219
+ @repository.find('transactions:1').delete rescue nil
220
+ obj = Rubydora::DigitalObject.new('transactions:1', @repository)
221
+ obj.save
222
+
223
+ ds = obj.datastreams['datastream_to_delete']
224
+ ds.content = 'asdf'
225
+ ds.save
226
+
227
+ ds2 = obj.datastreams['datastream_to_change']
228
+ ds2.content = 'asdf'
229
+ ds2.save
230
+
231
+ ds3 = obj.datastreams['datastream_to_change_properties']
232
+ ds3.content = 'asdf'
233
+ ds3.versionable = true
234
+ ds3.dsState = 'I'
235
+ ds3.save
236
+
237
+ @repository.transaction do |t|
238
+ ds.delete
239
+
240
+ ds2.content = '1234'
241
+ ds2.save
242
+
243
+ @repository.set_datastream_options :pid => obj.pid, :dsid => 'datastream_to_change_properties', :state => 'A'
244
+ @repository.set_datastream_options :pid => obj.pid, :dsid => 'datastream_to_change_properties', :versionable => false
245
+
246
+ ds4 = obj.datastreams['datastream_to_create']
247
+ ds4.content = 'asdf'
248
+ ds4.save
249
+
250
+ t.rollback
251
+ end
252
+
253
+ obj = @repository.find('transactions:1')
254
+ obj.datastreams.keys.should_not include('datsatream_to_create')
255
+ obj.datastreams.keys.should include('datastream_to_delete')
256
+ obj.datastreams['datastream_to_change'].content.should == 'asdf'
257
+ obj.datastreams['datastream_to_change_properties'].versionable.should == true
258
+ obj.datastreams['datastream_to_change_properties'].dsState.should == 'I'
261
259
  end
262
260
 
263
261
  it "should work on relationships" do
264
262
  pending("fcrepo 3.6's relationship api is busted; skipping") if @repository.version == 3.6
265
- @repository.find('transactions:1').delete rescue nil
263
+ @repository.find('transactions:1').delete rescue nil
266
264
 
267
265
  obj = @repository.find_or_initialize('transactions:1')
268
- obj.save
269
- @repository.add_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
266
+ obj.save
267
+ @repository.add_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
270
268
 
271
- ds = obj.datastreams['RELS-EXT'].content
269
+ ds = obj.datastreams['RELS-EXT'].content
272
270
 
273
- @repository.transaction do |t|
274
- @repository.purge_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
275
- @repository.add_relationship :subject => obj.pid, :predicate => 'uri:qwerty', :object => 'fedora:object'
271
+ @repository.transaction do |t|
272
+ @repository.purge_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
273
+ @repository.add_relationship :subject => obj.pid, :predicate => 'uri:qwerty', :object => 'fedora:object'
276
274
 
277
- t.rollback
275
+ t.rollback
278
276
 
279
- end
280
- obj = @repository.find('transactions:1')
281
- obj.datastreams['RELS-EXT'].content.should == ds
277
+ end
278
+ obj = @repository.find('transactions:1')
279
+ obj.datastreams['RELS-EXT'].content.should == ds
282
280
  end
283
281
  end
284
282
 
@@ -341,7 +339,7 @@ describe "Integration testing against a live Fedora repository", :integration =>
341
339
  ds.save
342
340
 
343
341
  versions = obj.datastreams["my_ds"].versions
344
- versions.map { |x| x.content }.should include("XXX", "YYY")
342
+ versions.map { |x| x.content }.should include("XXX", "YYY")
345
343
  end
346
344
 
347
345
  it "should allow the user to go from a versioned datastream to an unversioned datastream" do
@@ -451,20 +449,19 @@ describe "Integration testing against a live Fedora repository", :integration =>
451
449
  end
452
450
 
453
451
  it "should not destroy content when datastream properties are changed" do
454
- obj = @repository.find('test:1')
455
- obj.datastreams["my_ds"].content = "XXX"
456
- obj.datastreams["my_ds"].mimeType = "text/plain"
457
- obj.save
452
+ obj = @repository.find('test:1')
453
+ obj.datastreams["my_ds"].content = "XXX"
454
+ obj.datastreams["my_ds"].mimeType = "text/plain"
455
+ obj.save
458
456
 
459
- obj = @repository.find('test:1')
460
- obj.datastreams["my_ds"].mimeType = 'application/json'
461
- obj.save
457
+ obj = @repository.find('test:1')
458
+ obj.datastreams["my_ds"].mimeType = 'application/json'
459
+ obj.save
462
460
 
463
- obj = @repository.find('test:1')
464
- obj.datastreams["my_ds"].content.should == "XXX"
461
+ obj = @repository.find('test:1')
462
+ obj.datastreams["my_ds"].content.should == "XXX"
465
463
  end
466
464
 
467
-
468
465
  after(:all) do
469
466
  @repository.find('test:1').delete rescue nil
470
467
  @repository.find('test:2').delete rescue nil
@@ -17,4 +17,4 @@ describe Rubydora::ProfileParser do
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Rubydora::Repository do
4
4
  include Rubydora::FedoraUrlHelpers
5
-
5
+
6
6
  before(:each) do
7
- @repository = Rubydora::Repository.new
7
+ @repository = Rubydora::Repository.new
8
8
  end
9
9
 
10
10
  describe "initialize" do
@@ -34,17 +34,17 @@ describe Rubydora::Repository do
34
34
  describe "mint" do
35
35
  before do
36
36
  xml = "<resp xmlns:fedora=\"http://www.fedora.info/definitions/1/0/management/\"><fedora:pid>test:123</fedora:pid></resp>"
37
- @repository.api.should_receive(:next_pid).and_return xml
37
+ @repository.api.should_receive(:next_pid).and_return xml
38
38
  end
39
39
  it "should call nextPID" do
40
40
  @repository.mint.should == 'test:123'
41
41
  end
42
42
  end
43
-
43
+
44
44
  describe "mint (Fedora 3.4)" do
45
45
  before do
46
46
  xml = "<resp><pid>test:123</pid></resp>"
47
- @repository.api.should_receive(:next_pid).and_return xml
47
+ @repository.api.should_receive(:next_pid).and_return xml
48
48
  end
49
49
  it "should call nextPID" do
50
50
  @repository.mint.should == 'test:123'
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rubydora::RestApiClient do
4
-
4
+
5
5
  include Rubydora::FedoraUrlHelpers
6
6
 
7
7
  class FakeException < Exception
@@ -13,12 +13,10 @@ describe Rubydora::RestApiClient do
13
13
  attr_accessor :config
14
14
  end
15
15
 
16
-
17
-
18
16
  describe "exception handling" do
19
-
17
+
20
18
  shared_examples "RestClient error handling" do
21
- subject {
19
+ subject {
22
20
  mock_repository = MockRepository.new
23
21
  mock_repository.config = { :url => 'http://example.org' }
24
22
 
@@ -47,12 +45,10 @@ describe Rubydora::RestApiClient do
47
45
 
48
46
  end
49
47
 
50
-
51
48
  let :base_url do
52
49
  "http://example.org"
53
50
  end
54
51
 
55
-
56
52
  before(:each) do
57
53
  @fedora_user = 'fedoraAdmin'
58
54
  @fedora_password = 'fedoraAdmin'
@@ -62,11 +58,11 @@ describe Rubydora::RestApiClient do
62
58
 
63
59
  it "should create a REST client" do
64
60
  client = @mock_repository.client
65
-
61
+
66
62
  client.should be_a_kind_of(RestClient::Resource)
67
63
  client.options[:user].should == @fedora_user
68
64
  end
69
-
65
+
70
66
  it "should create a REST client with a client certificate" do
71
67
  client = @mock_repository.client :ssl_client_cert => OpenSSL::X509::Certificate.new, :ssl_client_key => OpenSSL::PKey::RSA.new
72
68
 
@@ -80,21 +76,20 @@ describe Rubydora::RestApiClient do
80
76
  lambda { client.should == @mock_repository.client }.should_not raise_error
81
77
  lambda { @mock_repository.client(:timeout => 120) }.should raise_error(ArgumentError)
82
78
  end
83
-
79
+
84
80
  it "should call nextPID" do
85
81
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + next_pid_url(:format => 'xml')))
86
82
  @mock_repository.next_pid
87
83
  end
88
84
 
89
85
  it "should find objects" do
90
- RestClient::Request.should_receive(:execute) do |params|
91
- params.should have_key(:url)
92
- params[:url].should =~ /^#{Regexp.escape(base_url + "/" + find_objects_url + "?")}.*query=a/
93
- end
86
+ RestClient::Request.should_receive(:execute) do |params|
87
+ params.should have_key(:url)
88
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + find_objects_url + "?")}.*query=a/
89
+ end
94
90
  @mock_repository.find_objects :query => 'a'
95
91
  end
96
92
 
97
-
98
93
  it "should show object properties" do
99
94
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('z', :format => 'xml')))
100
95
  @mock_repository.object :pid => 'z'
@@ -104,26 +99,25 @@ describe Rubydora::RestApiClient do
104
99
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('z', :format => 'xml'))).and_raise( RestClient::ResourceNotFound)
105
100
  lambda {@mock_repository.object(:pid => 'z')}.should raise_error RestClient::ResourceNotFound
106
101
  end
107
-
102
+
108
103
  it "ingest" do
109
104
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + new_object_url))
110
105
  @mock_repository.ingest
111
106
  end
112
107
 
113
-
114
108
  it "mint_pid_and_ingest" do
115
109
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + new_object_url))
116
110
  @mock_repository.ingest
117
111
  end
118
112
 
119
113
  it "ingest with pid" do
120
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
114
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
121
115
  @mock_repository.ingest :pid => 'mypid'
122
116
  end
123
117
 
124
118
  describe "export" do
125
119
  it "should work on the happy path" do
126
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + export_object_url('mypid')))
120
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + export_object_url('mypid')))
127
121
  @mock_repository.export :pid => 'mypid'
128
122
  end
129
123
  it "should require a pid" do
@@ -132,15 +126,15 @@ describe Rubydora::RestApiClient do
132
126
  end
133
127
 
134
128
  it "modify_object" do
135
- RestClient::Request.should_receive(:execute) do |params|
136
- params.should have_key(:url)
137
- params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_url('mypid'))}.*state=Z/
138
- end
129
+ RestClient::Request.should_receive(:execute) do |params|
130
+ params.should have_key(:url)
131
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_url('mypid'))}.*state=Z/
132
+ end
139
133
  @mock_repository.modify_object :pid => 'mypid', :state => 'Z'
140
134
  end
141
135
 
142
136
  it "purge_object" do
143
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
137
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_url('mypid')))
144
138
  @mock_repository.purge_object :pid => 'mypid'
145
139
  end
146
140
 
@@ -150,12 +144,12 @@ describe Rubydora::RestApiClient do
150
144
  end
151
145
 
152
146
  it "object_versions" do
153
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_versions_url('mypid', :format => 'xml')))
147
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_versions_url('mypid', :format => 'xml')))
154
148
  @mock_repository.object_versions :pid => 'mypid'
155
149
  end
156
150
 
157
151
  it "object_xml" do
158
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_xml_url('mypid', :format => 'xml')))
152
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_xml_url('mypid', :format => 'xml')))
159
153
  @mock_repository.object_xml :pid => 'mypid'
160
154
  end
161
155
 
@@ -205,45 +199,45 @@ describe Rubydora::RestApiClient do
205
199
  after { Rubydora.logger = @initial_logger }
206
200
 
207
201
  it "datastream" do
208
- RestClient::Request.should_receive(:execute).with(hash_including(request_options))
202
+ RestClient::Request.should_receive(:execute).with(hash_including(request_options))
209
203
  my_logger.should_receive(:debug) # squelch message "Loaded datastream mypid/aaa (time)"
210
204
  @mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'
211
205
  end
212
206
 
213
207
  it "should raise not found exception when getting a datastream" do
214
- RestClient::Request.should_receive(:execute).with(hash_including(request_options)).and_raise(RestClient::ResourceNotFound)
208
+ RestClient::Request.should_receive(:execute).with(hash_including(request_options)).and_raise(RestClient::ResourceNotFound)
215
209
  lambda {@mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::ResourceNotFound
216
210
  end
217
211
 
218
212
  it "should raise Unauthorized exception when getting a datastream" do
219
- RestClient::Request.should_receive(:execute).with(hash_including(request_options)).and_raise(RestClient::Unauthorized)
213
+ RestClient::Request.should_receive(:execute).with(hash_including(request_options)).and_raise(RestClient::Unauthorized)
220
214
  my_logger.should_receive(:error).with("Unauthorized at #{base_url + "/" + datastream_url('mypid', 'aaa', :format => 'xml')}")
221
215
  lambda {@mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::Unauthorized
222
216
  end
223
217
  end
224
218
 
225
219
  it "datastream_dissemination" do
226
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa')))
220
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa')))
227
221
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'
228
222
  end
229
223
  it "should allow http methods besides GET on datastream_dissemination" do
230
- RestClient::Request.should_receive(:execute).with(hash_including(:method => :head))
224
+ RestClient::Request.should_receive(:execute).with(hash_including(:method => :head))
231
225
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa', :method => :head
232
226
  end
233
227
  it "should pass a block to the rest client to process the response in datastream_dissemination" do
234
- _proc = lambda { |x| x }
235
- RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
228
+ _proc = lambda { |x| x }
229
+ RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
236
230
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa', &_proc
237
231
  end
238
232
  it "should raise not found exception when retrieving datastream_dissemination" do
239
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa'))).and_raise( RestClient::ResourceNotFound)
233
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_content_url('mypid', 'aaa'))).and_raise( RestClient::ResourceNotFound)
240
234
  lambda {@mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::ResourceNotFound
241
235
  end
242
236
 
243
237
  describe "add_datastream" do
244
238
  it "should post to the correct url" do
245
239
  RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa')))
246
- @mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
240
+ @mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
247
241
  end
248
242
  describe "when a file is passed" do
249
243
  let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand it for a real File (it has read, rewind and close)
@@ -279,15 +273,15 @@ describe Rubydora::RestApiClient do
279
273
 
280
274
  describe "modify datastream" do
281
275
  it "should not set mime-type when it's not provided (and a file is not passed)" do
282
- 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=>{})
283
- @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
276
+ 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=>{})
277
+ @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
284
278
  end
285
279
  it "should pass the provided mimeType header" do
286
- 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=>{})
280
+ 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=>{})
287
281
  @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa', :mimeType=>'application/json'
288
282
  end
289
283
  describe "when a file is passed" do
290
- let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand it for a real File (it has read, rewind and close)
284
+ let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand it for a real File (it has read, rewind and close)
291
285
  it "should rewind the file" do
292
286
  RestClient::Request.any_instance.should_receive(:transmit) #stub transmit so that Request.execute can close the file we pass
293
287
  @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa', :content=>file
@@ -319,74 +313,74 @@ describe Rubydora::RestApiClient do
319
313
  end
320
314
 
321
315
  it "purge_datastream" do
322
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa')))
323
- @mock_repository.purge_datastream :pid => 'mypid', :dsid => 'aaa'
316
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_url('mypid', 'aaa')))
317
+ @mock_repository.purge_datastream :pid => 'mypid', :dsid => 'aaa'
324
318
  end
325
319
 
326
320
  it "set_datastream_options" do
327
- RestClient::Request.should_receive(:execute) do |params|
328
- params.should have_key(:url)
329
- params[:url].should =~ /^#{Regexp.escape(base_url + "/" + datastream_url('mypid', 'aaa') + "?")}.*aparam=true/
330
- end
331
- @mock_repository.set_datastream_options :pid => 'mypid', :dsid => 'aaa', :aparam => true
321
+ RestClient::Request.should_receive(:execute) do |params|
322
+ params.should have_key(:url)
323
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + datastream_url('mypid', 'aaa') + "?")}.*aparam=true/
324
+ end
325
+ @mock_repository.set_datastream_options :pid => 'mypid', :dsid => 'aaa', :aparam => true
332
326
  end
333
327
 
334
328
  describe "datastream_versions" do
335
329
  it "should be successful" do
336
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_return("expected result")
330
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_return("expected result")
337
331
  @mock_repository.datastream_versions(:pid => 'mypid', :dsid => 'aaa').should == 'expected result'
338
332
  end
339
333
  it "should not break when fedora doesn't have datastream history" do
340
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_raise(RestClient::ResourceNotFound)
334
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml'))).and_raise(RestClient::ResourceNotFound)
341
335
  @mock_repository.datastream_versions(:pid => 'mypid', :dsid => 'aaa').should be_nil
342
336
  end
343
337
  end
344
338
 
345
339
  it "datastream_history" do
346
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml')))
340
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + datastream_history_url('mypid', 'aaa', :format=>'xml')))
347
341
  @mock_repository.datastream_history :pid => 'mypid', :dsid => 'aaa'
348
342
  end
349
343
 
350
344
  it "relationships" do
351
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_relationship_url('mypid', :format => 'xml')))
345
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + object_relationship_url('mypid', :format => 'xml')))
352
346
  @mock_repository.relationships :pid => 'mypid'
353
347
  end
354
348
 
355
349
  it "add_relationship" do
356
- RestClient::Request.should_receive(:execute) do |params|
357
- params.should have_key(:url)
358
- params[:url].should =~ /^#{Regexp.escape(base_url + "/" + new_object_relationship_url('mypid') + "?")}.*subject=z/
359
- end
350
+ RestClient::Request.should_receive(:execute) do |params|
351
+ params.should have_key(:url)
352
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + new_object_relationship_url('mypid') + "?")}.*subject=z/
353
+ end
360
354
  @mock_repository.add_relationship :pid => 'mypid', :subject => 'z'
361
355
  end
362
356
 
363
357
  it "purge_relationships" do
364
- RestClient::Request.should_receive(:execute) do |params|
365
- params.should have_key(:url)
366
- params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_relationship_url('mypid') + "?")}.*subject=z/
367
- end
368
- @mock_repository.purge_relationship :pid => 'mypid', :subject => 'z'
358
+ RestClient::Request.should_receive(:execute) do |params|
359
+ params.should have_key(:url)
360
+ params[:url].should =~ /^#{Regexp.escape(base_url + "/" + object_relationship_url('mypid') + "?")}.*subject=z/
361
+ end
362
+ @mock_repository.purge_relationship :pid => 'mypid', :subject => 'z'
369
363
  end
370
364
 
371
365
  it "dissemination" do
372
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', nil, nil, :format => 'xml')))
366
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', nil, nil, :format => 'xml')))
373
367
  @mock_repository.dissemination :pid => 'mypid'
374
368
  end
375
369
 
376
370
  it "dissemination" do
377
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', nil, :format => 'xml')))
371
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', nil, :format => 'xml')))
378
372
  @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef'
379
373
  end
380
374
 
381
375
  it "dissemination" do
382
- RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', 'method')))
376
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => base_url + "/" + dissemination_url('mypid', 'sdef', 'method')))
383
377
  @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method'
384
378
  end
385
379
 
386
380
  it "should pass a block to the rest client to process the response in datastream_dissemination" do
387
- _proc = lambda { |x| x }
388
- RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
389
- @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method', &_proc
381
+ _proc = lambda { |x| x }
382
+ RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
383
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method', &_proc
390
384
  end
391
385
 
392
386
  end