rubydora 1.8.0 → 1.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd98e937d5d4111adfe04d29ff9222f04e350e2e
4
- data.tar.gz: 112cb370a7149ba0421f145b099652a86a1b3ff0
3
+ metadata.gz: d68bb2a59b1fdc8fde14dca5e6a8c3f570d1beb5
4
+ data.tar.gz: e7d55248a5428826c53434e045f9b916584ea37e
5
5
  SHA512:
6
- metadata.gz: 40f19e1bf21b91c1340b1bf240b200624853e450a6f84f31ba092de3ef951d9ed44743ae76636a128031a8538078a56e0b13d074bbbd8fba2d62e959a414b41c
7
- data.tar.gz: ff8ac5c951403577be066a384edc28ef44fefd75ed162dcb9b468940cbaf0b9b16cdfaaa472107dff230d2684eb9650efe940a777556d5579af60166f530034f
6
+ metadata.gz: 0306cd415381d6925ccb5e4b2175b9404269a991d8d808df4b1d8ce235c17d54e9c82e0c22a86bd30b5a682e5ec67025b5b0ed7e04368da5a6e4fcc8d6cf33ba
7
+ data.tar.gz: 5062367721f76db12c88c62e2981665e40720a49c3fa233becf914e3d406a93a2b63dd313e4af543a688994f30b8954c07df16588a3b39cfaf7ca3f1b4a6fea4
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1
5
6
 
6
7
  gemfile:
7
8
  - gemfiles/gemfile.rails3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.8.1
@@ -226,11 +226,14 @@ module Rubydora
226
226
  # @param [Integer] from (bytes) the starting point you want to return.
227
227
  #
228
228
  def stream (from = 0, length = nil)
229
- raise "Can't determine dsSize" unless dsSize
230
- length = dsSize - from unless length
231
229
  counter = 0
232
230
  Enumerator.new do |blk|
233
231
  repository.datastream_dissemination(:pid => pid, :dsid => dsid) do |response|
232
+ unless length
233
+ size = external? ? entity_size(response) : dsSize
234
+ raise "Can't determine content length" unless size
235
+ length = size - from
236
+ end
234
237
  response.read_body do |chunk|
235
238
  last_counter = counter
236
239
  counter += chunk.size
@@ -303,11 +306,14 @@ module Rubydora
303
306
  check_if_read_only
304
307
  run_callbacks :save do
305
308
  raise RubydoraError.new("Unable to save #{self.inspect} without content") unless has_content?
306
- return create if new?
307
- p = repository.modify_datastream(to_api_params.merge({ :pid => pid, :dsid => dsid })) || {}
308
- reset_profile_attributes
309
- self.profile= p unless p.empty?
310
- self.class.new(digital_object, dsid, @options)
309
+ if new?
310
+ create
311
+ else
312
+ p = repository.modify_datastream(to_api_params.merge({ :pid => pid, :dsid => dsid })) || {}
313
+ reset_profile_attributes
314
+ self.profile= p unless p.empty?
315
+ self.class.new(digital_object, dsid, @options)
316
+ end
311
317
  end
312
318
  end
313
319
 
@@ -409,5 +415,13 @@ module Rubydora
409
415
  check_if_read_only
410
416
  super
411
417
  end
418
+
419
+ def entity_size(response)
420
+ if content_length = response.headers[:content_length]
421
+ return content_length.to_i
422
+ end
423
+ response.body.length
424
+ end
425
+
412
426
  end
413
427
  end
@@ -27,45 +27,65 @@ describe Rubydora::Datastream do
27
27
  before do
28
28
  stub_response = double
29
29
  stub_response.stub(:read_body).and_yield("one1").and_yield('two2').and_yield('thre').and_yield('four')
30
+ allow(stub_response).to receive(:headers) { {content_length: "16"} }
30
31
  @mock_api.should_receive(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_yield(stub_response)
31
- prof = <<-XML
32
- <datastreamProfile>
33
- <dsSize>16</dsSize>
34
- </datastreamProfile>
35
- XML
36
32
  subject.profile = Rubydora::ProfileParser.parse_datastream_profile(prof)
37
33
  end
38
- it "should send the whole thing" do
39
- e = subject.stream()
40
- result = ''
41
- e.each do |blk|
42
- result << blk
34
+ shared_examples "a streamable datastream" do
35
+ it "should send the whole thing" do
36
+ e = subject.stream()
37
+ result = ''
38
+ e.each do |blk|
39
+ result << blk
40
+ end
41
+ result.should == 'one1two2threfour'
43
42
  end
44
- result.should == 'one1two2threfour'
45
- end
46
- it "should send the whole thing when the range is open ended" do
47
- e = subject.stream(0)
48
- result = ''
49
- e.each do |blk|
50
- result << blk
43
+ it "should send the whole thing when the range is open ended" do
44
+ e = subject.stream(0)
45
+ result = ''
46
+ e.each do |blk|
47
+ result << blk
48
+ end
49
+ result.should == 'one1two2threfour'
50
+ end
51
+ it "should get a range not starting at the beginning" do
52
+ e = subject.stream(3, 13)
53
+ result = ''
54
+ e.each do |blk|
55
+ result << blk
56
+ end
57
+ result.should == '1two2threfour'
58
+ end
59
+ it "should get a range not ending at the end" do
60
+ e = subject.stream(4, 8)
61
+ result = ''
62
+ e.each do |blk|
63
+ result << blk
64
+ end
65
+ result.should == 'two2thre'
51
66
  end
52
- result.should == 'one1two2threfour'
53
67
  end
54
- it "should get a range not starting at the beginning" do
55
- e = subject.stream(3, 13)
56
- result = ''
57
- e.each do |blk|
58
- result << blk
68
+ describe "default" do
69
+ let(:prof) do
70
+ <<-XML
71
+ <datastreamProfile>
72
+ <dsSize>16</dsSize>
73
+ </datastreamProfile>
74
+ XML
59
75
  end
60
- result.should == '1two2threfour'
76
+ it_behaves_like "a streamable datastream"
61
77
  end
62
- it "should get a range not ending at the end" do
63
- e = subject.stream(4, 8)
64
- result = ''
65
- e.each do |blk|
66
- result << blk
78
+ describe "controlGroup 'E'" do
79
+ let(:prof) do
80
+ <<-XML
81
+ <datastreamProfile>
82
+ <dsSize>0</dsSize>
83
+ <dsLocation>file:/path/to/some/file</dsLocation>
84
+ <dsControlGroup>E</dsControlGroup>
85
+ </datastreamProfile>
86
+ XML
67
87
  end
68
- result.should == 'two2thre'
88
+ it_behaves_like "a streamable datastream"
69
89
  end
70
90
  end
71
91
 
@@ -837,5 +857,60 @@ describe Rubydora::Datastream do
837
857
  @datastream.url.should == "http://example.org/foo/content"
838
858
  end
839
859
  end
860
+
861
+ describe "callbacks" do
862
+ before(:all) do
863
+ class MyDatastream < Rubydora::Datastream
864
+ before_save :before_save_callback
865
+ def before_save_callback; end
866
+
867
+ after_save :after_save_callback
868
+ def after_save_callback; end
869
+
870
+ before_create :before_create_callback
871
+ def before_create_callback; end
872
+
873
+ after_create :after_create_callback
874
+ def after_create_callback; end
875
+ end
876
+ end
877
+
878
+ before(:each) { @datastream = MyDatastream.new @mock_object, 'dsid' }
879
+
880
+ after(:all) do
881
+ Object.send(:remove_const, :MyDatastream)
882
+ end
883
+
884
+ describe "saving new datastream" do
885
+ before do
886
+ allow(@mock_api).to receive(:add_datastream).with(hash_including(:content => 'content', :pid => 'pid', :dsid => 'dsid', :controlGroup => 'M', :dsState => 'A')) { {} }
887
+ end
888
+ it "should fire save and create callbacks" do
889
+ @datastream = MyDatastream.new @mock_object, 'dsid'
890
+ expect(@datastream).to receive(:before_save_callback)
891
+ expect(@datastream).to receive(:after_save_callback)
892
+ expect(@datastream).to receive(:before_create_callback)
893
+ expect(@datastream).to receive(:after_create_callback)
894
+ @datastream.content = 'content'
895
+ @datastream.stub(:profile => {})
896
+ @datastream.save
897
+ end
898
+ end
899
+ describe "saving persisted datastream" do
900
+ before do
901
+ allow(@mock_api).to receive(:modify_datastream).with(hash_including(:content => 'content', :pid => 'pid', :dsid => 'dsid')) { {} }
902
+ end
903
+ it "should fire only save callbacks" do
904
+ expect(@datastream).to receive(:before_save_callback)
905
+ expect(@datastream).to receive(:after_save_callback)
906
+ expect(@datastream).not_to receive(:before_create_callback)
907
+ expect(@datastream).not_to receive(:after_create_callback)
908
+ @datastream.content = 'content'
909
+ @datastream.stub(:profile => {dsLabel: "label"})
910
+ @datastream.save
911
+ end
912
+ end
913
+ end
914
+
840
915
  end
841
916
 
@@ -9,7 +9,6 @@ describe Rubydora::RestApiClient do
9
9
  end
10
10
  class MockRepository
11
11
  include Rubydora::RestApiClient
12
- include Loggable
13
12
 
14
13
  attr_accessor :config
15
14
  end
@@ -11,7 +11,6 @@ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
11
11
  end
12
12
 
13
13
  require 'rspec/autorun'
14
- require 'loggable'
15
14
  require 'rubydora'
16
15
  require 'webmock/rspec'
17
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydora
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastercsv