rubydora 1.1.1 → 1.1.2

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 CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -128,8 +128,16 @@ module Rubydora
128
128
 
129
129
  @content ||= datastream_content
130
130
 
131
- content = @content.read and @content.rewind if @content.kind_of? IO
132
- content ||= @content
131
+ if @content.kind_of? IO
132
+ begin
133
+ @content.rewind
134
+ @content.read
135
+ ensure
136
+ @content.rewind
137
+ end
138
+ else
139
+ @content
140
+ end
133
141
  end
134
142
  alias_method :read, :content
135
143
 
@@ -169,6 +177,7 @@ module Rubydora
169
177
  end
170
178
 
171
179
  def content_changed?
180
+ return false if ['E','R'].include? controlGroup
172
181
  return true if new? and !content.blank? # new datastreams must have content
173
182
 
174
183
  return true unless content == datastream_content
@@ -280,6 +289,7 @@ module Rubydora
280
289
  def save
281
290
  check_if_read_only
282
291
  run_callbacks :save do
292
+ raise RubydoraError.new("Unable to save #{self.inspect} without content") unless has_content?
283
293
  return create if new?
284
294
  repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
285
295
  reset_profile_attributes
@@ -61,6 +61,7 @@ describe Rubydora::Datastream do
61
61
  it "should be able to override defaults" do
62
62
  @mock_repository.should_receive(:add_datastream).with(hash_including(:controlGroup => 'E'))
63
63
  @datastream.controlGroup = 'E'
64
+ @datastream.dsLocation = "uri:asdf"
64
65
  @datastream.save
65
66
  end
66
67
  end
@@ -140,6 +141,7 @@ describe Rubydora::Datastream do
140
141
  end
141
142
 
142
143
  it "should not be new" do
144
+ @datastream.stub :content_changed? => false
143
145
  @datastream.new?.should == false
144
146
  @datastream.changed?.should == false
145
147
  end
@@ -157,11 +159,12 @@ describe Rubydora::Datastream do
157
159
 
158
160
  it "should rewind IO-type contents" do
159
161
  @mock_io = File.open('rubydora.gemspec')
160
- @mock_io.should_receive(:rewind)
162
+ @mock_io.readline # start with a dirty file
161
163
 
162
164
  @datastream.content = @mock_io
163
165
 
164
166
  @datastream.content.should be_a(String)
167
+ @datastream.content.should == File.read('rubydora.gemspec')
165
168
 
166
169
  end
167
170
 
@@ -244,6 +247,7 @@ describe Rubydora::Datastream do
244
247
 
245
248
  before(:each) do
246
249
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
250
+ @datastream.stub :content_changed? => false
247
251
  @mock_repository.should_receive(:datastream).any_number_of_times.and_return <<-XML
248
252
  <datastreamProfile>
249
253
  <dsLocation>some:uri</dsLocation>
@@ -253,6 +257,7 @@ describe Rubydora::Datastream do
253
257
  end
254
258
 
255
259
  it "should not say changed if the value is set the same" do
260
+ @datastream.stub :content_changed? => false
256
261
  @datastream.dsLabel = "label"
257
262
  @datastream.should_not be_changed
258
263
  end
@@ -285,6 +290,7 @@ describe Rubydora::Datastream do
285
290
  describe "should check if an object is read-only" do
286
291
  before(:each) do
287
292
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
293
+ @datastream.stub :content_changed? => false
288
294
  @mock_repository.should_receive(:datastream).any_number_of_times.and_return <<-XML
289
295
  <datastreamProfile>
290
296
  <dsLocation>some:uri</dsLocation>
@@ -392,7 +398,7 @@ describe Rubydora::Datastream do
392
398
 
393
399
  describe "setter" do
394
400
  before do
395
- subject.stub(:datastreams => [])
401
+ subject.stub(:datastreams => [], :content_changed? => false)
396
402
  end
397
403
  it "should mark the object as changed after setting" do
398
404
  subject.send("#{method}=", 'new_value')
@@ -452,6 +458,7 @@ describe Rubydora::Datastream do
452
458
 
453
459
  it "should appear in the save request" do
454
460
  @mock_repository.should_receive(:modify_datastream).with(hash_including(method.to_sym => 'http://example.com'))
461
+ subject.stub(:content_changed? => false)
455
462
  subject.dsLocation = 'http://example.com'
456
463
  subject.save
457
464
  end
@@ -608,6 +615,7 @@ describe Rubydora::Datastream do
608
615
  before(:each) do
609
616
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
610
617
  @datastream.stub(:new? => false)
618
+ @datastream.stub(:content_changed? => false)
611
619
  @datastream.stub(:profile) { {'dsMIME' => 'application/rdf+xml', 'dsChecksumType' =>'DISABLED', 'dsVersionable'=>true, 'dsControlGroup'=>'M', 'dsState'=>'A'} }
612
620
  end
613
621
  it "should not set unchanged values except for mimeType" do
@@ -626,14 +634,15 @@ describe Rubydora::Datastream do
626
634
  before(:each) do
627
635
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
628
636
  @datastream.stub(:new? => true )
637
+ @datastream.stub(:content => '123')
629
638
  @datastream.stub(:profile) { {} }
630
639
  end
631
640
  it "should compile parameters to hash" do
632
- @datastream.send(:to_api_params).should == {:versionable=>true, :controlGroup=>"M", :dsState=>"A"}
641
+ @datastream.send(:to_api_params).should == {:versionable=>true, :controlGroup=>"M", :dsState=>"A", :content => '123' }
633
642
  end
634
643
  it "should not send parameters that are set to nil" do
635
644
  @datastream.dsLabel = nil
636
- @datastream.send(:to_api_params).should == {:versionable=>true, :controlGroup=>"M", :dsState=>"A"}
645
+ @datastream.send(:to_api_params).should == {:versionable=>true, :controlGroup=>"M", :dsState=>"A", :content => '123' }
637
646
  end
638
647
  end
639
648
  end
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.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-17 00:00:00.000000000 Z
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv
@@ -286,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
286
  version: '0'
287
287
  segments:
288
288
  - 0
289
- hash: 206159229600052997
289
+ hash: -1646482824081762239
290
290
  required_rubygems_version: !ruby/object:Gem::Requirement
291
291
  none: false
292
292
  requirements:
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  version: '0'
296
296
  segments:
297
297
  - 0
298
- hash: 206159229600052997
298
+ hash: -1646482824081762239
299
299
  requirements: []
300
300
  rubyforge_project:
301
301
  rubygems_version: 1.8.23