spec/uploader/url_spec.rb in carrierwave-0.4.4 vs spec/uploader/url_spec.rb in carrierwave-0.4.5
- old
+ new
@@ -61,10 +61,25 @@
@uploader.file.stub!(:url).and_return('')
@uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
end
end
+ describe '#to_json' do
+ before do
+ CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
+ end
+
+ it "should return a hash with a blank URL" do
+ JSON.parse(@uploader.to_json)['url'].should be_nil
+ end
+
+ it "should return a hash including a cached URL" do
+ @uploader.cache!(File.open(file_path('test.jpg')))
+ JSON.parse(@uploader.to_json)['url'].should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
+ end
+ end
+
describe '#to_s' do
before do
CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
end
@@ -82,6 +97,6 @@
@uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
@uploader.to_s.should == 'http://www.example.com/someurl.jpg'
end
end
-end
\ No newline at end of file
+end