jnicklas-carrierwave 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +35 -20
 - data/Rakefile +1 -1
 - data/lib/carrierwave/compatibility/paperclip.rb +91 -0
 - data/lib/carrierwave/core_ext/inheritable_attributes.rb +102 -0
 - data/lib/carrierwave/core_ext/module_setup.rb +49 -0
 - data/lib/carrierwave/mount.rb +119 -103
 - data/lib/carrierwave/orm/activerecord.rb +6 -1
 - data/lib/carrierwave/orm/sequel.rb +15 -2
 - data/lib/carrierwave/processing/rmagick.rb +8 -7
 - data/lib/carrierwave/storage/abstract.rb +16 -1
 - data/lib/carrierwave/storage/file.rb +20 -1
 - data/lib/carrierwave/uploader/cache.rb +114 -0
 - data/lib/carrierwave/uploader/callbacks.rb +40 -0
 - data/lib/carrierwave/uploader/default_path.rb +21 -0
 - data/lib/carrierwave/uploader/extension_whitelist.rb +35 -0
 - data/lib/carrierwave/uploader/mountable.rb +37 -0
 - data/lib/carrierwave/uploader/paths.rb +25 -0
 - data/lib/carrierwave/uploader/processing.rb +79 -0
 - data/lib/carrierwave/uploader/proxy.rb +60 -0
 - data/lib/carrierwave/uploader/remove.rb +21 -0
 - data/lib/carrierwave/uploader/store.rb +154 -0
 - data/lib/carrierwave/uploader/url.rb +22 -0
 - data/lib/carrierwave/uploader/versions.rb +145 -0
 - data/lib/carrierwave/uploader.rb +31 -593
 - data/lib/carrierwave.rb +55 -7
 - data/lib/generators/uploader_generator.rb +1 -1
 - data/rails_generators/uploader/templates/uploader.rb +12 -8
 - data/spec/compatibility/paperclip_spec.rb +41 -0
 - data/spec/mount_spec.rb +88 -25
 - data/spec/orm/activerecord_spec.rb +7 -9
 - data/spec/orm/datamapper_spec.rb +7 -9
 - data/spec/orm/sequel_spec.rb +47 -32
 - data/spec/spec_helper.rb +13 -0
 - data/spec/uploader/cache_spec.rb +194 -0
 - data/spec/uploader/default_path_spec.rb +66 -0
 - data/spec/uploader/extension_whitelist_spec.rb +42 -0
 - data/spec/uploader/mountable_spec.rb +31 -0
 - data/spec/uploader/paths_spec.rb +20 -0
 - data/spec/uploader/processing_spec.rb +60 -0
 - data/spec/uploader/proxy_spec.rb +52 -0
 - data/spec/uploader/remove_spec.rb +65 -0
 - data/spec/uploader/store_spec.rb +260 -0
 - data/spec/uploader/url_spec.rb +85 -0
 - data/spec/uploader/versions_spec.rb +275 -0
 - metadata +34 -3
 - data/spec/uploader_spec.rb +0 -887
 
| 
         @@ -0,0 +1,260 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe CarrierWave::Uploader do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @uploader_class = Class.new(CarrierWave::Uploader::Base)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @uploader = @uploader_class.new
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              after do
         
     | 
| 
      
 11 
     | 
    
         
            +
                FileUtils.rm_rf(public_path)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe ".storage" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                before do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  CarrierWave::Storage::File.stub!(:setup!)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  CarrierWave::Storage::S3.stub!(:setup!)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                it "should set the storage if an argument is given" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  storage = mock('some kind of storage')
         
     | 
| 
      
 22 
     | 
    
         
            +
                  storage.should_receive(:setup!)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @uploader_class.storage storage
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @uploader_class.storage.should == storage
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                it "should default to file" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @uploader_class.storage.should == CarrierWave::Storage::File
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                it "should set the storage from the configured shortcuts if a symbol is given" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @uploader_class.storage :file
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @uploader_class.storage.should == CarrierWave::Storage::File
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                it "should remember the storage when inherited" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  @uploader_class.storage :s3
         
     | 
| 
      
 38 
     | 
    
         
            +
                  subclass = Class.new(@uploader_class)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  subclass.storage.should == CarrierWave::Storage::S3
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                it "should be changeable when inherited" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @uploader_class.storage :s3
         
     | 
| 
      
 44 
     | 
    
         
            +
                  subclass = Class.new(@uploader_class)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  subclass.storage.should == CarrierWave::Storage::S3
         
     | 
| 
      
 46 
     | 
    
         
            +
                  subclass.storage :file
         
     | 
| 
      
 47 
     | 
    
         
            +
                  subclass.storage.should == CarrierWave::Storage::File
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              describe '#store_dir' do
         
     | 
| 
      
 52 
     | 
    
         
            +
                it "should default to the config option" do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @uploader.store_dir.should == 'uploads'
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              describe '#filename' do
         
     | 
| 
      
 58 
     | 
    
         
            +
                it "should default to nil" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @uploader.filename.should be_nil
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
              describe '#store!' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                before do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  @file = File.open(file_path('test.jpg'))
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  @stored_file = mock('a stored file')
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @stored_file.stub!(:identifier).and_return('this-is-me')
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  @uploader_class.storage.stub!(:store!).and_return(@stored_file)
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                it "should set the current path" do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it "should not be cached" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  @uploader.should_not be_cached
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                it "should set the url" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                it "should set the identifier" do
         
     | 
| 
      
 91 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 92 
     | 
    
         
            +
                  @uploader.identifier.should == 'this-is-me'
         
     | 
| 
      
 93 
     | 
    
         
            +
                end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                it "should, if a file is given as argument, cache that file" do
         
     | 
| 
      
 96 
     | 
    
         
            +
                  @uploader.should_receive(:cache!).with(@file)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                it "should use a previously cached file if no argument is given" do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 102 
     | 
    
         
            +
                  @uploader.should_not_receive(:cache!)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  @uploader.store!
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                it "should instruct the storage engine to store the file" do
         
     | 
| 
      
 107 
     | 
    
         
            +
                  @uploader.cache!(@file)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  @uploader_class.storage.should_receive(:store!).with(@uploader, @uploader.file).and_return(:monkey)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  @uploader.store!
         
     | 
| 
      
 110 
     | 
    
         
            +
                end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                it "should reset the cache_name" do
         
     | 
| 
      
 113 
     | 
    
         
            +
                  @uploader.cache!(@file)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  @uploader.store!
         
     | 
| 
      
 115 
     | 
    
         
            +
                  @uploader.cache_name.should be_nil
         
     | 
| 
      
 116 
     | 
    
         
            +
                end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                it "should cache the result given by the storage engine" do
         
     | 
| 
      
 119 
     | 
    
         
            +
                  @uploader.store!(@file)
         
     | 
| 
      
 120 
     | 
    
         
            +
                  @uploader.file.should == @stored_file
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                it "should do nothing when trying to store an empty file" do
         
     | 
| 
      
 124 
     | 
    
         
            +
                  @uploader.store!(nil)
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                it "should not re-store a retrieved file" do
         
     | 
| 
      
 128 
     | 
    
         
            +
                  @stored_file = mock('a stored file')
         
     | 
| 
      
 129 
     | 
    
         
            +
                  @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                  @uploader_class.storage.should_not_receive(:store!)
         
     | 
| 
      
 132 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 133 
     | 
    
         
            +
                  @uploader.store!
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
              end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
              describe '#retrieve_from_store!' do
         
     | 
| 
      
 138 
     | 
    
         
            +
                before do
         
     | 
| 
      
 139 
     | 
    
         
            +
                  @stored_file = mock('a stored file')
         
     | 
| 
      
 140 
     | 
    
         
            +
                  @stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 141 
     | 
    
         
            +
                  @stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 142 
     | 
    
         
            +
                  @stored_file.stub!(:identifier).and_return('this-is-me')
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                  @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
         
     | 
| 
      
 145 
     | 
    
         
            +
                end
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
                it "should set the current path" do
         
     | 
| 
      
 148 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 149 
     | 
    
         
            +
                  @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 150 
     | 
    
         
            +
                end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                it "should not be cached" do
         
     | 
| 
      
 153 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 154 
     | 
    
         
            +
                  @uploader.should_not be_cached
         
     | 
| 
      
 155 
     | 
    
         
            +
                end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                it "should set the url" do
         
     | 
| 
      
 158 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 159 
     | 
    
         
            +
                  @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 160 
     | 
    
         
            +
                end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                it "should set the identifier" do
         
     | 
| 
      
 163 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 164 
     | 
    
         
            +
                  @uploader.identifier.should == 'this-is-me'
         
     | 
| 
      
 165 
     | 
    
         
            +
                end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                it "should instruct the storage engine to retrieve the file and store the result" do
         
     | 
| 
      
 168 
     | 
    
         
            +
                  @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
         
     | 
| 
      
 169 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 170 
     | 
    
         
            +
                  @uploader.file.should == @stored_file
         
     | 
| 
      
 171 
     | 
    
         
            +
                end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                it "should overwrite a file that has already been cached" do
         
     | 
| 
      
 174 
     | 
    
         
            +
                  @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
         
     | 
| 
      
 175 
     | 
    
         
            +
                  @uploader.retrieve_from_store!('bork.txt')
         
     | 
| 
      
 176 
     | 
    
         
            +
                  @uploader.file.should == @stored_file
         
     | 
| 
      
 177 
     | 
    
         
            +
                end
         
     | 
| 
      
 178 
     | 
    
         
            +
              end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
              describe 'with an overridden, reversing, filename' do
         
     | 
| 
      
 181 
     | 
    
         
            +
                before do
         
     | 
| 
      
 182 
     | 
    
         
            +
                  @uploader_class.class_eval do
         
     | 
| 
      
 183 
     | 
    
         
            +
                    def filename
         
     | 
| 
      
 184 
     | 
    
         
            +
                      super.reverse unless super.blank?
         
     | 
| 
      
 185 
     | 
    
         
            +
                    end
         
     | 
| 
      
 186 
     | 
    
         
            +
                  end
         
     | 
| 
      
 187 
     | 
    
         
            +
                end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
                describe '#store!' do
         
     | 
| 
      
 190 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 191 
     | 
    
         
            +
                    @file = File.open(file_path('test.jpg'))
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                    @stored_file = mock('a stored file')
         
     | 
| 
      
 194 
     | 
    
         
            +
                    @stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 195 
     | 
    
         
            +
                    @stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:store!).and_return(@stored_file)
         
     | 
| 
      
 198 
     | 
    
         
            +
                  end
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                  after do
         
     | 
| 
      
 201 
     | 
    
         
            +
                    CarrierWave.config[:use_cache] = true
         
     | 
| 
      
 202 
     | 
    
         
            +
                  end
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                  it "should set the current path" do
         
     | 
| 
      
 205 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 206 
     | 
    
         
            +
                    @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 207 
     | 
    
         
            +
                  end
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                  it "should set the url" do
         
     | 
| 
      
 210 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 211 
     | 
    
         
            +
                    @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
                  it "should, if a file is given as argument, reverse the filename" do
         
     | 
| 
      
 215 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 216 
     | 
    
         
            +
                    @uploader.filename.should == 'gpj.tset'
         
     | 
| 
      
 217 
     | 
    
         
            +
                  end
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
                  it "should, if a files is given as an argument and use_cache is false, reverse the filename" do
         
     | 
| 
      
 220 
     | 
    
         
            +
                    CarrierWave.config[:use_cache] = false
         
     | 
| 
      
 221 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 222 
     | 
    
         
            +
                    @uploader.filename.should == 'gpj.tset'
         
     | 
| 
      
 223 
     | 
    
         
            +
                  end
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
                end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                describe '#retrieve_from_store!' do
         
     | 
| 
      
 228 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 229 
     | 
    
         
            +
                    @stored_file = mock('a stored file')
         
     | 
| 
      
 230 
     | 
    
         
            +
                    @stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 231 
     | 
    
         
            +
                    @stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
         
     | 
| 
      
 234 
     | 
    
         
            +
                  end
         
     | 
| 
      
 235 
     | 
    
         
            +
             
     | 
| 
      
 236 
     | 
    
         
            +
                  it "should set the current path" do
         
     | 
| 
      
 237 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 238 
     | 
    
         
            +
                    @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 239 
     | 
    
         
            +
                  end
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
      
 241 
     | 
    
         
            +
                  it "should set the url" do
         
     | 
| 
      
 242 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 243 
     | 
    
         
            +
                    @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 244 
     | 
    
         
            +
                  end
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
                  it "should pass the identifier to the storage engine" do
         
     | 
| 
      
 247 
     | 
    
         
            +
                    @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
         
     | 
| 
      
 248 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 249 
     | 
    
         
            +
                    @uploader.file.should == @stored_file
         
     | 
| 
      
 250 
     | 
    
         
            +
                  end
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
      
 252 
     | 
    
         
            +
                  it "should not set the filename" do
         
     | 
| 
      
 253 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 254 
     | 
    
         
            +
                    @uploader.filename.should be_nil
         
     | 
| 
      
 255 
     | 
    
         
            +
                  end
         
     | 
| 
      
 256 
     | 
    
         
            +
                end
         
     | 
| 
      
 257 
     | 
    
         
            +
             
     | 
| 
      
 258 
     | 
    
         
            +
              end
         
     | 
| 
      
 259 
     | 
    
         
            +
             
     | 
| 
      
 260 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,85 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe CarrierWave::Uploader do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @uploader_class = Class.new(CarrierWave::Uploader::Base)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @uploader = @uploader_class.new
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              after do
         
     | 
| 
      
 11 
     | 
    
         
            +
                FileUtils.rm_rf(public_path)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe '#url' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                before do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                it "should default to nil" do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @uploader.url.should be_nil
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                it "should raise ArgumentError when version doesn't exist" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  lambda { @uploader.url(:thumb) }.should raise_error ArgumentError
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                it "should not raise ArgumentError when versions version exists" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @uploader_class.version(:thumb)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  lambda { @uploader.url(:thumb) }.should_not raise_error ArgumentError
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                it "should get the directory relative to public, prepending a slash" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                it "should get the directory relative to public for a specific version" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @uploader_class.version(:thumb)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @uploader.url(:thumb).should == '/uploads/tmp/20071201-1234-345-2255/thumb_test.jpg'
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                it "should get the directory relative to public for a nested version" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @uploader_class.version(:thumb) do
         
     | 
| 
      
 45 
     | 
    
         
            +
                    version(:mini)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @uploader.url(:thumb, :mini).should == '/uploads/tmp/20071201-1234-345-2255/thumb_mini_test.jpg'
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                it "should return file#url if available" do
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @uploader.url.should == 'http://www.example.com/someurl.jpg'
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                it "should get the directory relative to public, if file#url is blank" do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @uploader.file.stub!(:url).and_return('')
         
     | 
| 
      
 60 
     | 
    
         
            +
                  @uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              describe '#to_s' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                before do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                it "should default to nil" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @uploader.to_s.should be_nil
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                it "should get the directory relative to public, prepending a slash" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 75 
     | 
    
         
            +
                  @uploader.to_s.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                it "should return file#url if available" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                  @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 80 
     | 
    
         
            +
                  @uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @uploader.to_s.should == 'http://www.example.com/someurl.jpg'
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,275 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe CarrierWave::Uploader do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @uploader_class = Class.new(CarrierWave::Uploader::Base)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @uploader = @uploader_class.new
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              after do
         
     | 
| 
      
 11 
     | 
    
         
            +
                FileUtils.rm_rf(public_path)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe '.version' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                it "should add it to .versions" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @uploader_class.versions[:thumb].should be_a(Class)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @uploader_class.versions[:thumb].ancestors.should include(@uploader_class)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                it "should add an accessor which returns the version" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @uploader.thumb.should be_a(@uploader_class)
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it "should add it to #versions which returns the version" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @uploader.versions[:thumb].should be_a(@uploader_class)
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                it "should set the version name" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @uploader.version_name.should == nil
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @uploader.thumb.version_name.should == :thumb
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                it "should set the version names on the class" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @uploader.class.version_names.should == []
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @uploader.thumb.class.version_names.should == [:thumb]
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                it "should remember mount options" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  model = mock('a model')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @uploader_class.version :thumb
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @uploader = @uploader_class.new(model, :gazelle)
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  @uploader.thumb.model.should == model
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @uploader.thumb.mounted_as.should == :gazelle
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                it "should apply any overrides given in a block" do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @uploader_class.version :thumb do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    def store_dir
         
     | 
| 
      
 55 
     | 
    
         
            +
                      public_path('monkey/apache')
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  @uploader.store_dir.should == 'uploads'
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @uploader.thumb.store_dir.should == public_path('monkey/apache')
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                it "should reopen the same class when called multiple times" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  @uploader_class.version :thumb do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    def self.monkey
         
     | 
| 
      
 65 
     | 
    
         
            +
                      "monkey"
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @uploader_class.version :thumb do
         
     | 
| 
      
 69 
     | 
    
         
            +
                    def self.llama
         
     | 
| 
      
 70 
     | 
    
         
            +
                      "llama"
         
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @uploader_class.version(:thumb).monkey.should == "monkey"
         
     | 
| 
      
 74 
     | 
    
         
            +
                  @uploader_class.version(:thumb).llama.should == "llama"
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                describe 'with nested versions' do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 79 
     | 
    
         
            +
                    @uploader_class.version :thumb do
         
     | 
| 
      
 80 
     | 
    
         
            +
                      version :mini
         
     | 
| 
      
 81 
     | 
    
         
            +
                      version :micro
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  it "should add an array of version names" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                    @uploader.class.version_names.should == []
         
     | 
| 
      
 87 
     | 
    
         
            +
                    @uploader.thumb.class.version_names.should == [:thumb]
         
     | 
| 
      
 88 
     | 
    
         
            +
                    @uploader.thumb.mini.class.version_names.should == [:thumb, :mini]
         
     | 
| 
      
 89 
     | 
    
         
            +
                    @uploader.thumb.micro.class.version_names.should == [:thumb, :micro]
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                  it "should set the version name for the instances" do
         
     | 
| 
      
 93 
     | 
    
         
            +
                    @uploader.version_name.should be_nil
         
     | 
| 
      
 94 
     | 
    
         
            +
                    @uploader.thumb.version_name.should == :thumb
         
     | 
| 
      
 95 
     | 
    
         
            +
                    @uploader.thumb.mini.version_name.should == :thumb_mini
         
     | 
| 
      
 96 
     | 
    
         
            +
                    @uploader.thumb.micro.version_name.should == :thumb_micro
         
     | 
| 
      
 97 
     | 
    
         
            +
                  end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
              end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
              describe 'with a version' do
         
     | 
| 
      
 104 
     | 
    
         
            +
                before do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  @uploader_class.version(:thumb)
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                describe '#cache!' do
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 111 
     | 
    
         
            +
                    CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  it "should set store_path with versions" do
         
     | 
| 
      
 115 
     | 
    
         
            +
                    @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 116 
     | 
    
         
            +
                    @uploader.store_path.should == 'uploads/test.jpg'
         
     | 
| 
      
 117 
     | 
    
         
            +
                    @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
         
     | 
| 
      
 118 
     | 
    
         
            +
                    @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
         
     | 
| 
      
 119 
     | 
    
         
            +
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                  it "should move it to the tmp dir with the filename prefixed" do
         
     | 
| 
      
 122 
     | 
    
         
            +
                    @uploader.cache!(File.open(file_path('test.jpg')))
         
     | 
| 
      
 123 
     | 
    
         
            +
                    @uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
         
     | 
| 
      
 124 
     | 
    
         
            +
                    @uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
         
     | 
| 
      
 125 
     | 
    
         
            +
                    @uploader.file.exists?.should be_true
         
     | 
| 
      
 126 
     | 
    
         
            +
                    @uploader.thumb.file.exists?.should be_true
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
                end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                describe '#retrieve_from_cache!' do
         
     | 
| 
      
 131 
     | 
    
         
            +
                  it "should set the path to the tmp dir" do
         
     | 
| 
      
 132 
     | 
    
         
            +
                    @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
         
     | 
| 
      
 133 
     | 
    
         
            +
                    @uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
         
     | 
| 
      
 134 
     | 
    
         
            +
                    @uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
         
     | 
| 
      
 135 
     | 
    
         
            +
                  end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                  it "should set store_path with versions" do
         
     | 
| 
      
 138 
     | 
    
         
            +
                    @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
         
     | 
| 
      
 139 
     | 
    
         
            +
                    @uploader.store_path.should == 'uploads/test.jpg'
         
     | 
| 
      
 140 
     | 
    
         
            +
                    @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
         
     | 
| 
      
 141 
     | 
    
         
            +
                    @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
         
     | 
| 
      
 142 
     | 
    
         
            +
                  end
         
     | 
| 
      
 143 
     | 
    
         
            +
                end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                describe '#store!' do
         
     | 
| 
      
 146 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 147 
     | 
    
         
            +
                    @uploader_class.storage = mock_storage('base')
         
     | 
| 
      
 148 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage = mock_storage('thumb')
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                    @file = File.open(file_path('test.jpg'))
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    @base_stored_file = mock('a stored file')
         
     | 
| 
      
 153 
     | 
    
         
            +
                    @base_stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 154 
     | 
    
         
            +
                    @base_stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                    @thumb_stored_file = mock('a thumb version of a stored file')
         
     | 
| 
      
 157 
     | 
    
         
            +
                    @thumb_stored_file.stub!(:path).and_return('/path/to/somewhere/thumb')
         
     | 
| 
      
 158 
     | 
    
         
            +
                    @thumb_stored_file.stub!(:url).and_return('http://www.example.com/thumb')
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:store!).and_return(@base_stored_file)
         
     | 
| 
      
 161 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.stub!(:store!).and_return(@thumb_stored_file)
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  after do
         
     | 
| 
      
 165 
     | 
    
         
            +
                    CarrierWave.config[:use_cache] = true
         
     | 
| 
      
 166 
     | 
    
         
            +
                  end
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                  it "should set the current path for the version" do
         
     | 
| 
      
 169 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 170 
     | 
    
         
            +
                    @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 171 
     | 
    
         
            +
                    @uploader.thumb.current_path.should == '/path/to/somewhere/thumb'
         
     | 
| 
      
 172 
     | 
    
         
            +
                  end
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                  it "should set the url" do
         
     | 
| 
      
 175 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 176 
     | 
    
         
            +
                    @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 177 
     | 
    
         
            +
                    @uploader.thumb.url.should == 'http://www.example.com/thumb'
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                  it "should, if a file is given as argument, set the store_path" do
         
     | 
| 
      
 181 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 182 
     | 
    
         
            +
                    @uploader.store_path.should == 'uploads/test.jpg'
         
     | 
| 
      
 183 
     | 
    
         
            +
                    @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
         
     | 
| 
      
 184 
     | 
    
         
            +
                    @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
         
     | 
| 
      
 185 
     | 
    
         
            +
                  end
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                  it "should instruct the storage engine to store the file and its version" do
         
     | 
| 
      
 188 
     | 
    
         
            +
                    @uploader.cache!(@file)
         
     | 
| 
      
 189 
     | 
    
         
            +
                    @uploader_class.storage.should_receive(:store!).with(@uploader, @uploader.file).and_return(:monkey)
         
     | 
| 
      
 190 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.should_receive(:store!).with(@uploader.thumb, @uploader.thumb.file).and_return(:gorilla)
         
     | 
| 
      
 191 
     | 
    
         
            +
                    @uploader.store!
         
     | 
| 
      
 192 
     | 
    
         
            +
                  end
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
                end
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
                describe '#remove!' do
         
     | 
| 
      
 197 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 198 
     | 
    
         
            +
                    @uploader_class.storage = mock_storage('base')
         
     | 
| 
      
 199 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage = mock_storage('thumb')
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                    @file = File.open(file_path('test.jpg'))
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
                    @base_stored_file = mock('a stored file')
         
     | 
| 
      
 204 
     | 
    
         
            +
                    @thumb_stored_file = mock('a thumb version of a stored file')
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:store!).and_return(@base_stored_file)
         
     | 
| 
      
 207 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.stub!(:store!).and_return(@thumb_stored_file)
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:store!).and_return(@base_stored_file)
         
     | 
| 
      
 210 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.stub!(:store!).and_return(@thumb_stored_file)
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:destroy!)
         
     | 
| 
      
 213 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.stub!(:destroy!)
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                    @uploader.store!(@file)
         
     | 
| 
      
 216 
     | 
    
         
            +
                  end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                  after do
         
     | 
| 
      
 219 
     | 
    
         
            +
                    CarrierWave.config[:use_cache] = true
         
     | 
| 
      
 220 
     | 
    
         
            +
                  end
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                  it "should reset the current path for the version" do
         
     | 
| 
      
 223 
     | 
    
         
            +
                    @uploader.remove!
         
     | 
| 
      
 224 
     | 
    
         
            +
                    @uploader.current_path.should be_nil
         
     | 
| 
      
 225 
     | 
    
         
            +
                    @uploader.thumb.current_path.should be_nil
         
     | 
| 
      
 226 
     | 
    
         
            +
                  end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                  it "should reset the url" do
         
     | 
| 
      
 229 
     | 
    
         
            +
                    @uploader.remove!
         
     | 
| 
      
 230 
     | 
    
         
            +
                    @uploader.url.should be_nil
         
     | 
| 
      
 231 
     | 
    
         
            +
                    @uploader.thumb.url.should be_nil
         
     | 
| 
      
 232 
     | 
    
         
            +
                  end
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                  it "should instruct the storage engine to remove the file and its versions" do
         
     | 
| 
      
 235 
     | 
    
         
            +
                    @uploader_class.storage.should_receive(:destroy!).with(@uploader, @uploader.file)
         
     | 
| 
      
 236 
     | 
    
         
            +
                    @uploader_class.version(:thumb).storage.should_receive(:destroy!).with(@uploader.thumb, @uploader.thumb.file)
         
     | 
| 
      
 237 
     | 
    
         
            +
                    @uploader.remove!
         
     | 
| 
      
 238 
     | 
    
         
            +
                  end
         
     | 
| 
      
 239 
     | 
    
         
            +
             
     | 
| 
      
 240 
     | 
    
         
            +
                end
         
     | 
| 
      
 241 
     | 
    
         
            +
             
     | 
| 
      
 242 
     | 
    
         
            +
             
     | 
| 
      
 243 
     | 
    
         
            +
                describe '#retrieve_from_store!' do
         
     | 
| 
      
 244 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 245 
     | 
    
         
            +
                    @stored_file = mock('a stored file')
         
     | 
| 
      
 246 
     | 
    
         
            +
                    @stored_file.stub!(:path).and_return('/path/to/somewhere')
         
     | 
| 
      
 247 
     | 
    
         
            +
                    @stored_file.stub!(:url).and_return('http://www.example.com')
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
                    @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
         
     | 
| 
      
 250 
     | 
    
         
            +
                  end
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
      
 252 
     | 
    
         
            +
                  it "should set the current path" do
         
     | 
| 
      
 253 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 254 
     | 
    
         
            +
                    @uploader.current_path.should == '/path/to/somewhere'
         
     | 
| 
      
 255 
     | 
    
         
            +
                  end
         
     | 
| 
      
 256 
     | 
    
         
            +
             
     | 
| 
      
 257 
     | 
    
         
            +
                  it "should set the url" do
         
     | 
| 
      
 258 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 259 
     | 
    
         
            +
                    @uploader.url.should == 'http://www.example.com'
         
     | 
| 
      
 260 
     | 
    
         
            +
                  end
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
                  it "should pass the identifier to the storage engine" do
         
     | 
| 
      
 263 
     | 
    
         
            +
                    @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
         
     | 
| 
      
 264 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 265 
     | 
    
         
            +
                    @uploader.file.should == @stored_file
         
     | 
| 
      
 266 
     | 
    
         
            +
                  end
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                  it "should not set the filename" do
         
     | 
| 
      
 269 
     | 
    
         
            +
                    @uploader.retrieve_from_store!('monkey.txt')
         
     | 
| 
      
 270 
     | 
    
         
            +
                    @uploader.filename.should be_nil
         
     | 
| 
      
 271 
     | 
    
         
            +
                  end
         
     | 
| 
      
 272 
     | 
    
         
            +
                end
         
     | 
| 
      
 273 
     | 
    
         
            +
              end
         
     | 
| 
      
 274 
     | 
    
         
            +
             
     | 
| 
      
 275 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: jnicklas-carrierwave
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jonas Nicklas
         
     | 
| 
         @@ -9,7 +9,7 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date: 2009-05- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-05-17 00:00:00 -07:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
         @@ -30,6 +30,11 @@ files: 
     | 
|
| 
       30 
30 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       31 
31 
     | 
    
         
             
            - TODO
         
     | 
| 
       32 
32 
     | 
    
         
             
            - lib/carrierwave
         
     | 
| 
      
 33 
     | 
    
         
            +
            - lib/carrierwave/compatibility
         
     | 
| 
      
 34 
     | 
    
         
            +
            - lib/carrierwave/compatibility/paperclip.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - lib/carrierwave/core_ext
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/carrierwave/core_ext/inheritable_attributes.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/carrierwave/core_ext/module_setup.rb
         
     | 
| 
       33 
38 
     | 
    
         
             
            - lib/carrierwave/mount.rb
         
     | 
| 
       34 
39 
     | 
    
         
             
            - lib/carrierwave/orm
         
     | 
| 
       35 
40 
     | 
    
         
             
            - lib/carrierwave/orm/activerecord.rb
         
     | 
| 
         @@ -45,10 +50,25 @@ files: 
     | 
|
| 
       45 
50 
     | 
    
         
             
            - lib/carrierwave/storage/s3.rb
         
     | 
| 
       46 
51 
     | 
    
         
             
            - lib/carrierwave/test
         
     | 
| 
       47 
52 
     | 
    
         
             
            - lib/carrierwave/test/matchers.rb
         
     | 
| 
      
 53 
     | 
    
         
            +
            - lib/carrierwave/uploader
         
     | 
| 
      
 54 
     | 
    
         
            +
            - lib/carrierwave/uploader/cache.rb
         
     | 
| 
      
 55 
     | 
    
         
            +
            - lib/carrierwave/uploader/callbacks.rb
         
     | 
| 
      
 56 
     | 
    
         
            +
            - lib/carrierwave/uploader/default_path.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            - lib/carrierwave/uploader/extension_whitelist.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - lib/carrierwave/uploader/mountable.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - lib/carrierwave/uploader/paths.rb
         
     | 
| 
      
 60 
     | 
    
         
            +
            - lib/carrierwave/uploader/processing.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/carrierwave/uploader/proxy.rb
         
     | 
| 
      
 62 
     | 
    
         
            +
            - lib/carrierwave/uploader/remove.rb
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/carrierwave/uploader/store.rb
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/carrierwave/uploader/url.rb
         
     | 
| 
      
 65 
     | 
    
         
            +
            - lib/carrierwave/uploader/versions.rb
         
     | 
| 
       48 
66 
     | 
    
         
             
            - lib/carrierwave/uploader.rb
         
     | 
| 
       49 
67 
     | 
    
         
             
            - lib/carrierwave.rb
         
     | 
| 
       50 
68 
     | 
    
         
             
            - lib/generators
         
     | 
| 
       51 
69 
     | 
    
         
             
            - lib/generators/uploader_generator.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            - spec/compatibility
         
     | 
| 
      
 71 
     | 
    
         
            +
            - spec/compatibility/paperclip_spec.rb
         
     | 
| 
       52 
72 
     | 
    
         
             
            - spec/fixtures
         
     | 
| 
       53 
73 
     | 
    
         
             
            - spec/fixtures/bork.txt
         
     | 
| 
       54 
74 
     | 
    
         
             
            - spec/fixtures/test.jpeg
         
     | 
| 
         @@ -60,7 +80,18 @@ files: 
     | 
|
| 
       60 
80 
     | 
    
         
             
            - spec/orm/sequel_spec.rb
         
     | 
| 
       61 
81 
     | 
    
         
             
            - spec/sanitized_file_spec.rb
         
     | 
| 
       62 
82 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       63 
     | 
    
         
            -
            - spec/ 
     | 
| 
      
 83 
     | 
    
         
            +
            - spec/uploader
         
     | 
| 
      
 84 
     | 
    
         
            +
            - spec/uploader/cache_spec.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - spec/uploader/default_path_spec.rb
         
     | 
| 
      
 86 
     | 
    
         
            +
            - spec/uploader/extension_whitelist_spec.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - spec/uploader/mountable_spec.rb
         
     | 
| 
      
 88 
     | 
    
         
            +
            - spec/uploader/paths_spec.rb
         
     | 
| 
      
 89 
     | 
    
         
            +
            - spec/uploader/processing_spec.rb
         
     | 
| 
      
 90 
     | 
    
         
            +
            - spec/uploader/proxy_spec.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - spec/uploader/remove_spec.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - spec/uploader/store_spec.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
            - spec/uploader/url_spec.rb
         
     | 
| 
      
 94 
     | 
    
         
            +
            - spec/uploader/versions_spec.rb
         
     | 
| 
       64 
95 
     | 
    
         
             
            - rails_generators/uploader
         
     | 
| 
       65 
96 
     | 
    
         
             
            - rails_generators/uploader/templates
         
     | 
| 
       66 
97 
     | 
    
         
             
            - rails_generators/uploader/templates/uploader.rb
         
     |