ensure that StoredFile is providing correct content for small files
authorLunar <lunar@anargeek.net>
Tue, 6 Mar 2012 10:11:31 +0000 (11:11 +0100)
committerLunar <lunar@anargeek.net>
Fri, 23 Mar 2012 17:11:28 +0000 (18:11 +0100)
lib/coquelicot/stored_file.rb
spec/coquelicot/stored_file_spec.rb
spec/fixtures/small-secret-1.0/reference [new file with mode: 0644]
spec/fixtures/small-secret-1.0/stored_file [new file with mode: 0644]

index 82cfaef..dcd0a9e 100644 (file)
@@ -95,10 +95,12 @@ module Coquelicot
       # output content
       yield @initial_content
       @initial_content = nil
-      until (buf = @file.read(BUFFER_LEN)).nil?
-        yield @cipher.update(buf)
+      unless @file.eof?
+        until (buf = @file.read(BUFFER_LEN)).nil?
+          yield @cipher.update(buf)
+        end
+        yield @cipher.final
       end
-      yield @cipher.final
       @fully_sent = true
     end
 
index eff5981..4a735a0 100644 (file)
@@ -108,6 +108,12 @@ module Coquelicot
     let(:reference) {
       YAML.load_file(File.expand_path('../../fixtures/LICENSE-secret-1.0/reference', __FILE__))
     }
+    let(:small_stored_file_path) {
+      File.expand_path('../../fixtures/small-secret-1.0/stored_file', __FILE__)
+    }
+    let(:small_reference) {
+      YAML.load_file(File.expand_path('../../fixtures/small-secret-1.0/reference', __FILE__))
+    }
 
     describe '.open' do
       context 'when the given file does not exist' do
@@ -318,13 +324,25 @@ module Coquelicot
 
     describe '#each' do
       context 'when the right pass has been given' do
-        let(:stored_file) { StoredFile.open(stored_file_path, 'secret') }
-        it 'should output the whole content with several yields' do
-          buf = ''
-          stored_file.each do |data|
-            buf << data
+        context 'for an usual file' do
+          let(:stored_file) { StoredFile.open(stored_file_path, 'secret') }
+          it 'should output the whole content with several yields' do
+            buf = ''
+            stored_file.each do |data|
+              buf << data
+            end
+            buf.should == reference['Content']
+          end
+        end
+        context 'for a small file' do
+          let(:small_stored_file) { StoredFile.open(small_stored_file_path, 'secret') }
+          it 'should output the whole content' do
+            buf = ''
+            small_stored_file.each do |data|
+              buf << data
+            end
+            buf.should == small_reference['Content']
           end
-          buf.should == reference['Content']
         end
       end
       context 'when no password has been given' do
diff --git a/spec/fixtures/small-secret-1.0/reference b/spec/fixtures/small-secret-1.0/reference
new file mode 100644 (file)
index 0000000..5bc90c4
--- /dev/null
@@ -0,0 +1,5 @@
+--- 
+Created-at: 1331028513
+Content: Content
+Expire-at: 0
+Length: 7
diff --git a/spec/fixtures/small-secret-1.0/stored_file b/spec/fixtures/small-secret-1.0/stored_file
new file mode 100644 (file)
index 0000000..d622cec
Binary files /dev/null and b/spec/fixtures/small-secret-1.0/stored_file differ