spec/integration/file_upload_spec.rb in rmega-0.1.7 vs spec/integration/file_upload_spec.rb in rmega-0.2.0
- old
+ new
@@ -1,78 +1,32 @@
require 'integration_spec_helper'
-require 'fileutils'
describe 'File upload' do
if account_file_exists?
before(:all) { @storage = login }
- context 'upload a small file to the root folder' do
+ let(:name) { "test_file" }
- before(:all) do
- @name = "i_like_trains_#{rand(1E20)}"
- @content = @name
- end
+ let(:path) { File.join(temp_folder, name)}
- def find_file
- @storage.root.files.find { |f| f.name == @name }
- end
+ [12, 1_024_000].each do |size|
+ context "when a file (#{size} bytes) is uploaded" do
- let(:path) { File.join(temp_folder, @name) }
-
- before do
- File.open(path, 'wb') { |f| f.write(@content) }
- @storage.root.upload(path)
- end
-
- it 'finds the uploaded file' do
- file = find_file
- file.delete
- expect(file).not_to be_nil
- end
-
- context 'download the same file' do
-
- let(:download_path) { "#{path}.downloaded" }
-
before do
- file = find_file
- file.download(download_path)
- file.delete
+ File.open(path, 'wb') { |f| f.write(OpenSSL::Random.random_bytes(size)) }
+ @file = @storage.root.upload(path)
end
- it 'has the expected content' do
- expect(File.read(download_path)).to eql @content
+ it 'it can be found as a file node' do
+ found_node = @storage.root.files.find { |f| f.handle == @file.handle }
+ expect(found_node).not_to be_nil
end
- end
- end
- context 'upload a big file to a specific folder' do
-
- before(:all) do
- @name = "mine_turtles_#{rand(1E20)}"
- @path = File.join(temp_folder, @name)
- @buffer = "rofl" * 1024
-
- File.open(@path, 'wb') do |f|
- 512.times { f.write(@buffer) }
+ after do
+ @file.delete if @file
end
-
- @folder = @storage.root.create_folder(@name)
- @folder.upload(@path)
end
-
- it 'finds the uploaded file and verify its content' do
- file = @folder.files.find { |f| f.name == @name }
- download_path = "#{@path}.downloaded"
- file.download(download_path)
-
- File.open(download_path, 'rb') do |f|
- 512.times { expect(f.read(@buffer.size)).to eq(@buffer) }
- end
- end
-
- after { @folder.delete if @folder }
end
end
end