rubydora 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/rubydora/datastream.rb +3 -1
- data/lib/rubydora/rest_api_client.rb +9 -3
- data/spec/lib/datastream_spec.rb +32 -12
- data/spec/lib/integration_test_spec.rb +60 -1
- data/spec/lib/rest_api_client_spec.rb +14 -6
- metadata +30 -30
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/rubydora/datastream.rb
CHANGED
@@ -156,7 +156,9 @@ module Rubydora
|
|
156
156
|
# @return [Hash]
|
157
157
|
def to_api_params
|
158
158
|
h = default_api_params
|
159
|
-
changes.keys.map { |x| x.to_sym }.select { |x| DS_ATTRIBUTES.key? x }
|
159
|
+
valid_changed_attributes = changes.keys.map { |x| x.to_sym }.select { |x| DS_ATTRIBUTES.key? x }
|
160
|
+
## if we don't provide a mimeType, application/octet-stream will be used instead
|
161
|
+
(valid_changed_attributes | [:mimeType]).each do |attribute|
|
160
162
|
h[attribute] = send(attribute) if send(attribute)
|
161
163
|
end
|
162
164
|
|
@@ -229,7 +229,7 @@ module Rubydora
|
|
229
229
|
pid = options.delete(:pid)
|
230
230
|
dsid = options.delete(:dsid)
|
231
231
|
file = options.delete(:content)
|
232
|
-
content_type = options.delete(:content_type) || options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || '
|
232
|
+
content_type = options.delete(:content_type) || options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || 'application/octet-stream'
|
233
233
|
begin
|
234
234
|
return client[datastream_url(pid, dsid, options)].post file, :content_type => content_type.to_s, :multipart => true
|
235
235
|
rescue => e
|
@@ -247,10 +247,16 @@ module Rubydora
|
|
247
247
|
pid = options.delete(:pid)
|
248
248
|
dsid = options.delete(:dsid)
|
249
249
|
file = options.delete(:content)
|
250
|
-
content_type = options.delete(:content_type) || options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || '
|
250
|
+
content_type = options.delete(:content_type) || options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || 'application/octet-stream'
|
251
|
+
|
252
|
+
rest_client_options = {}
|
253
|
+
if file
|
254
|
+
rest_client_options[:multipart] = true
|
255
|
+
rest_client_options[:content_type] = content_type
|
256
|
+
end
|
251
257
|
|
252
258
|
begin
|
253
|
-
return client[datastream_url(pid, dsid, options)].put(file,
|
259
|
+
return client[datastream_url(pid, dsid, options)].put(file, rest_client_options)
|
254
260
|
rescue => e
|
255
261
|
logger.error e.response
|
256
262
|
raise "Error modifying datastream #{dsid} for #{pid}. See logger for details"
|
data/spec/lib/datastream_spec.rb
CHANGED
@@ -119,18 +119,38 @@ describe Rubydora::Datastream do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
describe "to_api_params" do
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
122
|
+
|
123
|
+
describe "with existing properties" do
|
124
|
+
before(:each) do
|
125
|
+
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
126
|
+
@datastream.stub(:profile) { {'dsMIME' => 'application/rdf+xml', 'dsChecksumType' =>'DISABLED', 'dsVersionable'=>true, 'dsControlGroup'=>'M', 'dsState'=>'A'} }
|
127
|
+
end
|
128
|
+
it "should not set unchanged values except for mimeType" do
|
129
|
+
@datastream.send(:to_api_params).should == {:mimeType=>'application/rdf+xml'}
|
130
|
+
end
|
131
|
+
it "should send changed params except those set to nil" do
|
132
|
+
@datastream.dsLabel = nil
|
133
|
+
@datastream.mimeType = 'application/json'
|
134
|
+
@datastream.controlGroup = 'X'
|
135
|
+
@datastream.send(:to_api_params).should == {:controlGroup=>"X", :mimeType=>"application/json"}
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
describe "without existing properties" do
|
141
|
+
before(:each) do
|
142
|
+
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
143
|
+
@datastream.stub(:profile) { {} }
|
144
|
+
end
|
145
|
+
it "should compile parameters to hash" do
|
146
|
+
@datastream.send(:to_api_params).should == {:checksumType=>"DISABLED", :versionable=>true,
|
147
|
+
:controlGroup=>"M", :dsState=>"A"}
|
148
|
+
end
|
149
|
+
it "should not send parameters that are set to nil" do
|
150
|
+
@datastream.dsLabel = nil
|
151
|
+
@datastream.send(:to_api_params).should == {:checksumType=>"DISABLED", :versionable=>true,
|
152
|
+
:controlGroup=>"M", :dsState=>"A"}
|
153
|
+
end
|
134
154
|
end
|
135
155
|
end
|
136
156
|
end
|
@@ -6,6 +6,8 @@ describe "Integration testing against a live Fedora repository" do
|
|
6
6
|
REPOSITORY_CONFIG = { :url => 'http://localhost:8983/fedora', :user => 'fedoraAdmin', :password => 'fedoraAdmin' }
|
7
7
|
before(:all) do
|
8
8
|
@repository = Rubydora.connect REPOSITORY_CONFIG
|
9
|
+
@repository.find('test:1').delete rescue nil
|
10
|
+
@repository.find('test:2').delete rescue nil
|
9
11
|
end
|
10
12
|
|
11
13
|
it "should connect" do
|
@@ -91,9 +93,10 @@ describe "Integration testing against a live Fedora repository" do
|
|
91
93
|
obj.datastreams["empty_ds"].new?.should == true
|
92
94
|
end
|
93
95
|
|
94
|
-
it "should update datastream attributes without changing the content" do
|
96
|
+
it "should update datastream attributes without changing the content (or mime type)" do
|
95
97
|
obj = @repository.find('test:1')
|
96
98
|
obj.datastreams["my_ds"].content = "XXX"
|
99
|
+
obj.datastreams["my_ds"].mimeType = "application/x-text"
|
97
100
|
obj.save
|
98
101
|
|
99
102
|
obj = @repository.find('test:1')
|
@@ -103,6 +106,62 @@ describe "Integration testing against a live Fedora repository" do
|
|
103
106
|
obj = @repository.find('test:1')
|
104
107
|
obj.datastreams["my_ds"].content.should == "XXX"
|
105
108
|
obj.datastreams["my_ds"].dsLabel.should == "New Label"
|
109
|
+
obj.datastreams["my_ds"].mimeType.should == "application/x-text"
|
110
|
+
end
|
111
|
+
|
112
|
+
context "mime types" do
|
113
|
+
before(:each) do
|
114
|
+
obj = @repository.find('test:1')
|
115
|
+
obj.datastreams["my_ds"].delete rescue nil
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should default to application/octet-stream" do
|
119
|
+
obj = @repository.find('test:1')
|
120
|
+
obj.datastreams["my_ds"].content = "XXX"
|
121
|
+
obj.save
|
122
|
+
|
123
|
+
obj = @repository.find('test:1')
|
124
|
+
obj.datastreams["my_ds"].mimeType.should == "application/octet-stream"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow the user to specify a mimetype" do
|
128
|
+
obj = @repository.find('test:1')
|
129
|
+
obj.datastreams["my_ds"].content = "XXX"
|
130
|
+
obj.datastreams["my_ds"].mimeType = "text/plain"
|
131
|
+
obj.save
|
132
|
+
|
133
|
+
obj = @repository.find('test:1')
|
134
|
+
obj.datastreams["my_ds"].mimeType.should == "text/plain"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should preserve the mimetype on update" do
|
138
|
+
obj = @repository.find('test:1')
|
139
|
+
obj.datastreams["my_ds"].content = "XXX"
|
140
|
+
obj.datastreams["my_ds"].mimeType = "text/plain"
|
141
|
+
obj.save
|
142
|
+
|
143
|
+
obj = @repository.find('test:1')
|
144
|
+
obj.datastreams["my_ds"].content = "ZZZ"
|
145
|
+
obj.save
|
146
|
+
|
147
|
+
obj = @repository.find('test:1')
|
148
|
+
obj.datastreams["my_ds"].mimeType.should == "text/plain"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should allow the mimetype to be changed" do
|
152
|
+
obj = @repository.find('test:1')
|
153
|
+
obj.datastreams["my_ds"].content = "XXX"
|
154
|
+
obj.datastreams["my_ds"].mimeType = "text/plain"
|
155
|
+
obj.save
|
156
|
+
|
157
|
+
obj = @repository.find('test:1')
|
158
|
+
obj.datastreams["my_ds"].mimeType = "application/json"
|
159
|
+
obj.save
|
160
|
+
|
161
|
+
obj = @repository.find('test:1')
|
162
|
+
obj.datastreams["my_ds"].mimeType.should == "application/json"
|
163
|
+
end
|
164
|
+
|
106
165
|
end
|
107
166
|
|
108
167
|
|
@@ -11,21 +11,23 @@ describe Rubydora::RestApiClient do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
before(:each) do
|
14
|
+
@fedora_user = 'fedoraAdmin'
|
15
|
+
@fedora_password = 'fedoraAdmin'
|
14
16
|
@mock_repository = MockRepository.new
|
15
|
-
@mock_repository.config = { :url => 'http://example.org',:user =>
|
17
|
+
@mock_repository.config = { :url => 'http://example.org',:user => @fedora_user, :password => @fedora_password}
|
16
18
|
end
|
17
19
|
|
18
20
|
it "should create a REST client" do
|
19
21
|
client = @mock_repository.client
|
20
22
|
|
21
23
|
client.should be_a_kind_of(RestClient::Resource)
|
22
|
-
client.options[:user].should ==
|
24
|
+
client.options[:user].should == @fedora_user
|
23
25
|
end
|
24
26
|
|
25
27
|
it "should create a REST client with a client certificate" do
|
26
28
|
client = @mock_repository.client :ssl_client_cert => OpenSSL::X509::Certificate.new, :ssl_client_key => OpenSSL::PKey::RSA.new
|
27
29
|
|
28
|
-
client.options[:user].should ==
|
30
|
+
client.options[:user].should == @fedora_user
|
29
31
|
client.options[:ssl_client_cert].should be_a_kind_of(OpenSSL::X509::Certificate)
|
30
32
|
client.options[:ssl_client_key].should be_a_kind_of(OpenSSL::PKey::PKey)
|
31
33
|
end
|
@@ -127,9 +129,15 @@ describe Rubydora::RestApiClient do
|
|
127
129
|
@mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
|
128
130
|
end
|
129
131
|
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
describe "modify datastream" do
|
133
|
+
it "should not set mime-type when it's not provided" do
|
134
|
+
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=>{})
|
135
|
+
@mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
|
136
|
+
end
|
137
|
+
it "should pass the provided mimeType header" do
|
138
|
+
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=>{})
|
139
|
+
@mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa', :mimeType=>'application/json'
|
140
|
+
end
|
133
141
|
end
|
134
142
|
|
135
143
|
it "purge_datastream" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fastercsv
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152300120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152300120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152296900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152296900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152295960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152295960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mime-types
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152294860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152294860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152293940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152293940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activemodel
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152292840 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152292840
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: savon
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152288800 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152288800
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rake
|
93
|
-
requirement: &
|
93
|
+
requirement: &2152286960 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2152286960
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: shoulda
|
104
|
-
requirement: &
|
104
|
+
requirement: &2152286080 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2152286080
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: bundler
|
115
|
-
requirement: &
|
115
|
+
requirement: &2152284820 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 1.0.14
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *2152284820
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rspec
|
126
|
-
requirement: &
|
126
|
+
requirement: &2152283500 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *2152283500
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: yard
|
137
|
-
requirement: &
|
137
|
+
requirement: &2152281700 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *2152281700
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: jettywrapper
|
148
|
-
requirement: &
|
148
|
+
requirement: &2152275140 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,7 +153,7 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *2152275140
|
157
157
|
description: ! 'Fedora Commons REST API ruby library : REQUIRES FCREPO 3.4+'
|
158
158
|
email:
|
159
159
|
- chris@cbeer.info
|
@@ -211,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
211
|
version: '0'
|
212
212
|
segments:
|
213
213
|
- 0
|
214
|
-
hash:
|
214
|
+
hash: 4297992764557344518
|
215
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
216
|
none: false
|
217
217
|
requirements:
|
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
version: '0'
|
221
221
|
segments:
|
222
222
|
- 0
|
223
|
-
hash:
|
223
|
+
hash: 4297992764557344518
|
224
224
|
requirements: []
|
225
225
|
rubyforge_project:
|
226
226
|
rubygems_version: 1.8.10
|