rubydora 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +573 -0
- data/.travis.yml +6 -6
- data/Gemfile +2 -3
- data/README.md +86 -0
- data/Rakefile +22 -25
- data/VERSION +1 -1
- data/lib/rubydora.rb +3 -6
- data/lib/rubydora/array_with_callback.rb +4 -4
- data/lib/rubydora/audit_trail.rb +7 -7
- data/lib/rubydora/callbacks.rb +9 -9
- data/lib/rubydora/datastream.rb +43 -39
- data/lib/rubydora/digital_object.rb +31 -33
- data/lib/rubydora/fc3_service.rb +10 -14
- data/lib/rubydora/fedora_url_helpers.rb +21 -22
- data/lib/rubydora/models_mixin.rb +4 -4
- data/lib/rubydora/profile_parser.rb +8 -8
- data/lib/rubydora/relationships_mixin.rb +15 -16
- data/lib/rubydora/repository.rb +11 -11
- data/lib/rubydora/resource_index.rb +10 -14
- data/lib/rubydora/rest_api_client.rb +52 -53
- data/lib/rubydora/transactions.rb +42 -51
- data/rubydora.gemspec +25 -25
- data/spec/audit_trail_spec.rb +1 -1
- data/spec/lib/datastream_spec.rb +34 -32
- data/spec/lib/digital_object_spec.rb +13 -10
- data/spec/lib/integration_test_spec.rb +116 -119
- data/spec/lib/profile_parser_spec.rb +1 -1
- data/spec/lib/repository_spec.rb +5 -5
- data/spec/lib/rest_api_client_spec.rb +60 -66
- data/spec/lib/transactions_spec.rb +4 -6
- data/spec/spec_helper.rb +2 -9
- metadata +30 -31
- data/.gitmodules +0 -0
- data/README.rdoc +0 -79
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
ds.content = open(__FILE__).read
|
89
|
+
ds.mimeType = 'text/plain'
|
90
|
+
ds.save
|
91
|
+
end
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
112
|
+
it "should have profile attributes" do
|
113
|
+
obj = @repository.find_or_initialize('test:1')
|
114
|
+
ds = obj.datastreams["Test"]
|
116
115
|
|
117
|
-
|
116
|
+
ds.versionID.should == "Test.0"
|
118
117
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
190
|
+
@repository.find('transactions:1').delete rescue nil
|
193
191
|
|
194
|
-
|
195
|
-
|
196
|
-
|
192
|
+
@repository.transaction do |t|
|
193
|
+
obj = @repository.find_or_initialize('transactions:1')
|
194
|
+
obj.save
|
197
195
|
|
198
|
-
|
199
|
-
|
196
|
+
t.rollback
|
197
|
+
end
|
200
198
|
|
201
|
-
|
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
|
-
|
203
|
+
@repository.find('transactions:1').delete rescue nil
|
206
204
|
|
207
|
-
|
208
|
-
|
205
|
+
obj = @repository.find_or_initialize('transactions:1')
|
206
|
+
obj.save
|
209
207
|
|
210
|
-
|
211
|
-
|
208
|
+
@repository.transaction do |t|
|
209
|
+
obj.delete
|
212
210
|
|
213
|
-
|
214
|
-
|
211
|
+
t.rollback
|
212
|
+
end
|
215
213
|
|
216
|
-
|
217
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
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
|
-
|
263
|
+
@repository.find('transactions:1').delete rescue nil
|
266
264
|
|
267
265
|
obj = @repository.find_or_initialize('transactions:1')
|
268
|
-
|
269
|
-
|
266
|
+
obj.save
|
267
|
+
@repository.add_relationship :subject => obj.pid, :predicate => 'uri:asdf', :object => 'fedora:object'
|
270
268
|
|
271
|
-
|
269
|
+
ds = obj.datastreams['RELS-EXT'].content
|
272
270
|
|
273
|
-
|
274
|
-
|
275
|
-
|
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
|
-
|
275
|
+
t.rollback
|
278
276
|
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
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
|
-
|
460
|
-
|
461
|
-
|
457
|
+
obj = @repository.find('test:1')
|
458
|
+
obj.datastreams["my_ds"].mimeType = 'application/json'
|
459
|
+
obj.save
|
462
460
|
|
463
|
-
|
464
|
-
|
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
|
data/spec/lib/repository_spec.rb
CHANGED
@@ -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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
235
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
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
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
388
|
-
|
389
|
-
|
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
|