spec/mongo/grid/stream/write_spec.rb in mongo-2.6.4 vs spec/mongo/grid/stream/write_spec.rb in mongo-2.7.0.rc0

- old
+ new

@@ -1,9 +1,18 @@ require 'spec_helper' describe Mongo::Grid::FSBucket::Stream::Write do + let(:support_fs) do + authorized_client.database.fs(fs_options) + end + + before do + support_fs.files_collection.drop rescue nil + support_fs.chunks_collection.drop rescue nil + end + let(:file) do File.open(__FILE__) end let(:file2) do @@ -28,15 +37,10 @@ let(:options) do { filename: filename }.merge(extra_options).merge(fs.options) end - after do - fs.files_collection.delete_many - fs.chunks_collection.delete_many - end - let(:stream) do described_class.new(fs, options) end describe '#initialize' do @@ -229,15 +233,10 @@ end end describe '#write' do - after do - fs.files_collection.delete_many - fs.chunks_collection.delete_many - end - let(:file_from_db) do fs.find_one(filename: filename) end context 'when the stream is written to' do @@ -254,12 +253,10 @@ context 'when indexes need to be ensured' do context 'when the files collection is empty' do before do - fs.files_collection.delete_many - fs.chunks_collection.delete_many expect(fs.files_collection).to receive(:indexes).and_call_original expect(fs.chunks_collection).to receive(:indexes).and_call_original stream.write(file) end @@ -292,21 +289,17 @@ end context 'when the files collection is not empty' do before do - fs.files_collection.insert_one(a: 1) + support_fs.send(:ensure_indexes!) + support_fs.files_collection.insert_one(a: 1) expect(fs.files_collection).not_to receive(:indexes) expect(fs.chunks_collection).not_to receive(:indexes) stream.write(file) end - after do - fs.files_collection.delete_many - fs.chunks_collection.delete_many - end - let(:files_index) do fs.database[fs.files_collection.name].indexes.get(:filename => 1, :uploadDate => 1) end it 'assumes indexes already exist' do @@ -315,17 +308,12 @@ end context 'when the index creation encounters an error' do before do - fs.chunks_collection.drop fs.chunks_collection.indexes.create_one(Mongo::Grid::FSBucket::CHUNKS_INDEX, :unique => false) expect(fs.chunks_collection).to receive(:indexes).and_call_original expect(fs.files_collection).not_to receive(:indexes) - end - - after do - fs.database[fs.chunks_collection.name].indexes.drop_one('files_id_1_n_1') end it 'raises the error to the user' do expect { stream.write(file)