spec/uploader/store_spec.rb in jnicklas-carrierwave-0.2.4 vs spec/uploader/store_spec.rb in jnicklas-carrierwave-0.3.0
- old
+ new
@@ -65,13 +65,16 @@
@file = File.open(file_path('test.jpg'))
@stored_file = mock('a stored file')
@stored_file.stub!(:path).and_return('/path/to/somewhere')
@stored_file.stub!(:url).and_return('http://www.example.com')
- @stored_file.stub!(:identifier).and_return('this-is-me')
- @uploader_class.storage.stub!(:store!).and_return(@stored_file)
+ @storage = mock('a storage engine')
+ @storage.stub!(:store!).and_return(@stored_file)
+ @storage.stub!(:identifier).and_return('this-is-me')
+
+ @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
end
it "should set the current path" do
@uploader.store!(@file)
@uploader.current_path.should == '/path/to/somewhere'
@@ -103,11 +106,11 @@
@uploader.store!
end
it "should instruct the storage engine to store the file" do
@uploader.cache!(@file)
- @uploader_class.storage.should_receive(:store!).with(@uploader, @uploader.file).and_return(:monkey)
+ @storage.should_receive(:store!).with(@uploader.file).and_return(:monkey)
@uploader.store!
end
it "should reset the cache_name" do
@uploader.cache!(@file)
@@ -124,11 +127,11 @@
@uploader.store!(nil)
end
it "should not re-store a retrieved file" do
@stored_file = mock('a stored file')
- @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
+ @storage.stub!(:retrieve!).and_return(@stored_file)
@uploader_class.storage.should_not_receive(:store!)
@uploader.retrieve_from_store!('monkey.txt')
@uploader.store!
end
@@ -137,13 +140,16 @@
describe '#retrieve_from_store!' do
before do
@stored_file = mock('a stored file')
@stored_file.stub!(:path).and_return('/path/to/somewhere')
@stored_file.stub!(:url).and_return('http://www.example.com')
- @stored_file.stub!(:identifier).and_return('this-is-me')
- @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
+ @storage = mock('a storage engine')
+ @storage.stub!(:retrieve!).and_return(@stored_file)
+ @storage.stub!(:identifier).and_return('this-is-me')
+
+ @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
end
it "should set the current path" do
@uploader.retrieve_from_store!('monkey.txt')
@uploader.current_path.should == '/path/to/somewhere'
@@ -163,11 +169,11 @@
@uploader.retrieve_from_store!('monkey.txt')
@uploader.identifier.should == 'this-is-me'
end
it "should instruct the storage engine to retrieve the file and store the result" do
- @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
+ @storage.should_receive(:retrieve!).with('monkey.txt').and_return(@stored_file)
@uploader.retrieve_from_store!('monkey.txt')
@uploader.file.should == @stored_file
end
it "should overwrite a file that has already been cached" do
@@ -192,11 +198,14 @@
@stored_file = mock('a stored file')
@stored_file.stub!(:path).and_return('/path/to/somewhere')
@stored_file.stub!(:url).and_return('http://www.example.com')
- @uploader_class.storage.stub!(:store!).and_return(@stored_file)
+ @storage = mock('a storage engine')
+ @storage.stub!(:store!).and_return(@stored_file)
+
+ @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
end
after do
CarrierWave.config[:use_cache] = true
end
@@ -228,11 +237,14 @@
before do
@stored_file = mock('a stored file')
@stored_file.stub!(:path).and_return('/path/to/somewhere')
@stored_file.stub!(:url).and_return('http://www.example.com')
- @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
+ @storage = mock('a storage engine')
+ @storage.stub!(:retrieve!).and_return(@stored_file)
+
+ @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
end
it "should set the current path" do
@uploader.retrieve_from_store!('monkey.txt')
@uploader.current_path.should == '/path/to/somewhere'
@@ -242,10 +254,10 @@
@uploader.retrieve_from_store!('monkey.txt')
@uploader.url.should == 'http://www.example.com'
end
it "should pass the identifier to the storage engine" do
- @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
+ @storage.should_receive(:retrieve!).with('monkey.txt').and_return(@stored_file)
@uploader.retrieve_from_store!('monkey.txt')
@uploader.file.should == @stored_file
end
it "should not set the filename" do
\ No newline at end of file