rubydora 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -122,12 +122,18 @@ module Rubydora
122
122
  digital_object.nil? || digital_object.new? || profile_xml.blank?
123
123
  end
124
124
 
125
+ # This method is overridden in ActiveFedora, so we didn't
126
+ def content
127
+ local_or_remote_content(true)
128
+ end
129
+
125
130
  # Retrieve the content of the datastream (and cache it)
131
+ # @param [Boolean] ensure_fetch <true> if true, it will grab the content from the repository if is not already loaded
126
132
  # @return [String]
127
- def content
128
- return @content if new?
133
+ def local_or_remote_content(ensure_fetch = true)
134
+ return @content if new?
129
135
 
130
- @content ||= datastream_content
136
+ @content ||= ensure_fetch ? datastream_content : @datastream_content
131
137
 
132
138
  if behaves_like_io?(@content)
133
139
  begin
@@ -166,27 +172,23 @@ module Rubydora
166
172
  # @param [String or IO]
167
173
  # @return [String or IO]
168
174
  def content= new_content
169
- content_will_change! if (self.eager_load_datastream_content and content != new_content) or (@content.nil? or @content != new_content)
170
- @content = new_content
171
- end
172
-
173
- # Content_will_change! would be dynamically created by ActiveModel::Dirty, but it would eagerly load the content.
174
- # We don't want to do that.
175
- def content_will_change!
176
175
  raise "Can't change values on older versions" if @asOfDateTime
177
- changed_attributes['content'] = nil
176
+ @content = new_content
178
177
  end
179
178
 
180
179
  def content_changed?
181
180
  return false if ['E','R'].include? controlGroup
182
- return true if new? and !content.blank? # new datastreams must have content
181
+ return true if new? and !local_or_remote_content(false).blank? # new datastreams must have content
183
182
 
184
183
  if controlGroup == "X"
185
- return true unless EquivalentXml.equivalent?(Nokogiri::XML(content), Nokogiri::XML(datastream_content))
184
+ return !EquivalentXml.equivalent?(Nokogiri::XML(content), Nokogiri::XML(datastream_content))
186
185
  else
187
- return true unless content == datastream_content
186
+ if self.eager_load_datastream_content
187
+ return local_or_remote_content(false) != datastream_content
188
+ else
189
+ return local_or_remote_content(false) != @datastream_content
190
+ end
188
191
  end
189
-
190
192
  super
191
193
  end
192
194
 
@@ -345,6 +347,7 @@ module Rubydora
345
347
  @profile = nil
346
348
  @profile_xml = nil
347
349
  @datastream_content = nil
350
+ @content = nil
348
351
  @changed_attributes = {}
349
352
  end
350
353
 
@@ -194,7 +194,7 @@ module Rubydora
194
194
  dsid = query_options.delete(:dsid)
195
195
  query_options[:format] ||= 'xml'
196
196
  val = nil
197
- message = dsid.nil? ? "Loaded datastream list for #{pid}" : "Loaded datastream #{pid}/#{dsid}"
197
+ message = dsid.nil? ? "Loaded datastream list for #{pid}" : "Loaded datastream profile #{pid}/#{dsid}"
198
198
  benchmark message, :level=>:debug do
199
199
  val = client[datastream_url(pid, dsid, query_options)].get
200
200
  end
@@ -262,7 +262,11 @@ module Rubydora
262
262
  else
263
263
  resource = client[datastream_content_url(pid, dsid, query_options)]
264
264
  end
265
- resource.send(method)
265
+ val = nil
266
+ benchmark "Loaded datastream content #{pid}/#{dsid}", :level=>:debug do
267
+ val = resource.send(method)
268
+ end
269
+ val
266
270
  rescue Exception => exception
267
271
  rescue_with_handler(exception) || raise
268
272
  end
@@ -158,6 +158,11 @@ describe Rubydora::Datastream do
158
158
  @datastream.content.should == "asdf"
159
159
  end
160
160
 
161
+ it "should not load contents if they say not to" do
162
+ @mock_repository.should_not_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid'))
163
+ @datastream.local_or_remote_content(false).should be_nil
164
+ end
165
+
161
166
  it "should rewind IO-type contents" do
162
167
  @mock_io = File.open('rubydora.gemspec')
163
168
  @mock_io.readline # start with a dirty file
@@ -188,6 +193,10 @@ describe Rubydora::Datastream do
188
193
  @datastream.content
189
194
  @datastream.content_changed?.should == false
190
195
  end
196
+ it "should not load content just to check and see if it was changed." do
197
+ @mock_repository.should_not_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid'))
198
+ @datastream.content_changed?.should == false
199
+ end
191
200
  it "should be changed when the new content is different than the old content" do
192
201
  @mock_repository.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('asdf')
193
202
  @datastream.content = "test"
@@ -245,10 +254,8 @@ describe Rubydora::Datastream do
245
254
  end
246
255
 
247
256
  describe "update" do
248
-
249
257
  before(:each) do
250
258
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
251
- @datastream.stub :content_changed? => false
252
259
  @mock_repository.should_receive(:datastream).any_number_of_times.and_return <<-XML
253
260
  <datastreamProfile>
254
261
  <dsLocation>some:uri</dsLocation>
@@ -257,35 +264,41 @@ describe Rubydora::Datastream do
257
264
  XML
258
265
  end
259
266
 
260
- it "should not say changed if the value is set the same" do
261
- @datastream.stub :content_changed? => false
262
- @datastream.dsLabel = "label"
263
- @datastream.should_not be_changed
264
- end
267
+ describe "when content is unchanged" do
268
+ before do
269
+ @datastream.stub :content_changed? => false
270
+ end
271
+ it "should not say changed if the value is set the same" do
272
+ @datastream.dsLabel = "label"
273
+ @datastream.should_not be_changed
274
+ end
265
275
 
266
- it "should allow profile attributes to be replaced" do
267
- @datastream.dsLabel = "New Label"
268
- @datastream.dsLabel.should == "New Label"
269
- end
276
+ it "should allow profile attributes to be replaced" do
277
+ @datastream.dsLabel = "New Label"
278
+ @datastream.dsLabel.should == "New Label"
279
+ end
270
280
 
271
- it "should call the appropriate api with any dirty attributes" do
272
- @mock_repository.should_receive(:modify_datastream).with(hash_including(:dsLabel => "New Label"))
273
- @datastream.dsLabel = "New Label"
274
- @datastream.save
281
+ it "should call the appropriate api with any dirty attributes" do
282
+ @mock_repository.should_receive(:modify_datastream).with(hash_including(:dsLabel => "New Label"))
283
+ @datastream.dsLabel = "New Label"
284
+ @datastream.save
285
+ end
275
286
  end
276
287
 
277
- it "should update the datastream when the content is changed" do
278
- @mock_repository.should_receive(:modify_datastream).with(hash_including(:content => 'test'))
279
- @datastream.content = "test"
280
- @datastream.save
281
- end
288
+ describe "update when content is changed" do
289
+ it "should update the datastream when the content is changed" do
290
+ @mock_repository.should_receive(:modify_datastream).with(hash_including(:content => 'test'))
291
+ @datastream.content = "test"
292
+ @datastream.save
293
+ end
282
294
 
283
- it "should be marked as changed when the content is updated" do
284
- @datastream.changed?.should be_false
285
- @datastream.content = "test"
286
- @datastream.changed?.should be_true
287
- end
295
+ it "should be marked as changed when the content is updated" do
296
+ @datastream.changed?.should be_false
297
+ @datastream.content = "test"
298
+ @datastream.changed?.should be_true
299
+ end
288
300
 
301
+ end
289
302
  end
290
303
 
291
304
  describe "should check if an object is read-only" do
@@ -635,7 +648,7 @@ describe Rubydora::Datastream do
635
648
  before(:each) do
636
649
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
637
650
  @datastream.stub(:new? => true )
638
- @datastream.stub(:content => '123')
651
+ @datastream.stub(:local_or_remote_content => '123')
639
652
  @datastream.stub(:profile) { {} }
640
653
  end
641
654
  it "should compile parameters to hash" 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: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  type: :runtime
@@ -40,7 +40,7 @@ dependencies:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :runtime
@@ -56,7 +56,7 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  type: :runtime
@@ -72,7 +72,7 @@ dependencies:
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  type: :runtime
@@ -88,7 +88,7 @@ dependencies:
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
@@ -96,7 +96,7 @@ dependencies:
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :runtime
@@ -104,7 +104,7 @@ dependencies:
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
@@ -112,7 +112,7 @@ dependencies:
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
@@ -120,7 +120,7 @@ dependencies:
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
@@ -128,7 +128,7 @@ dependencies:
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
- - - ! '>='
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  type: :runtime
@@ -136,7 +136,7 @@ dependencies:
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
139
- - - ! '>='
139
+ - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
@@ -144,7 +144,7 @@ dependencies:
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
- - - ! '>='
147
+ - - ">="
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  type: :runtime
@@ -152,7 +152,7 @@ dependencies:
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
- - - ! '>='
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  - !ruby/object:Gem::Dependency
@@ -160,7 +160,7 @@ dependencies:
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
- - - ! '>='
163
+ - - ">="
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  type: :development
@@ -168,7 +168,7 @@ dependencies:
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
171
- - - ! '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  - !ruby/object:Gem::Dependency
@@ -176,7 +176,7 @@ dependencies:
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
179
- - - ! '>='
179
+ - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  type: :development
@@ -184,7 +184,7 @@ dependencies:
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements:
187
- - - ! '>='
187
+ - - ">="
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  - !ruby/object:Gem::Dependency
@@ -192,7 +192,7 @@ dependencies:
192
192
  requirement: !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
- - - ! '>='
195
+ - - ">="
196
196
  - !ruby/object:Gem::Version
197
197
  version: 1.0.14
198
198
  type: :development
@@ -200,7 +200,7 @@ dependencies:
200
200
  version_requirements: !ruby/object:Gem::Requirement
201
201
  none: false
202
202
  requirements:
203
- - - ! '>='
203
+ - - ">="
204
204
  - !ruby/object:Gem::Version
205
205
  version: 1.0.14
206
206
  - !ruby/object:Gem::Dependency
@@ -208,7 +208,7 @@ dependencies:
208
208
  requirement: !ruby/object:Gem::Requirement
209
209
  none: false
210
210
  requirements:
211
- - - ! '>='
211
+ - - ">="
212
212
  - !ruby/object:Gem::Version
213
213
  version: '0'
214
214
  type: :development
@@ -216,7 +216,7 @@ dependencies:
216
216
  version_requirements: !ruby/object:Gem::Requirement
217
217
  none: false
218
218
  requirements:
219
- - - ! '>='
219
+ - - ">="
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  - !ruby/object:Gem::Dependency
@@ -224,7 +224,7 @@ dependencies:
224
224
  requirement: !ruby/object:Gem::Requirement
225
225
  none: false
226
226
  requirements:
227
- - - ! '>='
227
+ - - ">="
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  type: :development
@@ -232,7 +232,7 @@ dependencies:
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  none: false
234
234
  requirements:
235
- - - ! '>='
235
+ - - ">="
236
236
  - !ruby/object:Gem::Version
237
237
  version: '0'
238
238
  - !ruby/object:Gem::Dependency
@@ -240,7 +240,7 @@ dependencies:
240
240
  requirement: !ruby/object:Gem::Requirement
241
241
  none: false
242
242
  requirements:
243
- - - ! '>='
243
+ - - ">="
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  type: :development
@@ -248,7 +248,7 @@ dependencies:
248
248
  version_requirements: !ruby/object:Gem::Requirement
249
249
  none: false
250
250
  requirements:
251
- - - ! '>='
251
+ - - ">="
252
252
  - !ruby/object:Gem::Version
253
253
  version: '0'
254
254
  description: Fedora Commons REST API ruby library
@@ -258,8 +258,8 @@ executables: []
258
258
  extensions: []
259
259
  extra_rdoc_files: []
260
260
  files:
261
- - .gitignore
262
- - .gitmodules
261
+ - ".gitignore"
262
+ - ".gitmodules"
263
263
  - Gemfile
264
264
  - History.textile
265
265
  - LICENSE.txt
@@ -297,24 +297,24 @@ require_paths:
297
297
  required_ruby_version: !ruby/object:Gem::Requirement
298
298
  none: false
299
299
  requirements:
300
- - - ! '>='
300
+ - - ">="
301
301
  - !ruby/object:Gem::Version
302
302
  version: '0'
303
303
  segments:
304
304
  - 0
305
- hash: 3546053973135231573
305
+ hash: -1210235886615853572
306
306
  required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  none: false
308
308
  requirements:
309
- - - ! '>='
309
+ - - ">="
310
310
  - !ruby/object:Gem::Version
311
311
  version: '0'
312
312
  segments:
313
313
  - 0
314
- hash: 3546053973135231573
314
+ hash: -1210235886615853572
315
315
  requirements: []
316
316
  rubyforge_project:
317
- rubygems_version: 1.8.24
317
+ rubygems_version: 1.8.25
318
318
  signing_key:
319
319
  specification_version: 3
320
320
  summary: Fedora Commons REST API ruby library