Skip to content

Commit

Permalink
Merge pull request #686 from skyeagle/master
Browse files Browse the repository at this point in the history
avoid double generation of cache_id
  • Loading branch information
bensie committed Apr 13, 2012
2 parents 38f9ccc + ab86fb5 commit ca91f30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/uploader/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def cache_versions!(new_file)
active_versions.each do |name, v|
next if v.cached?

v.send(:cache_id=, cache_id)
# If option :from_version is present, create cache using cached file from
# version indicated
if self.class.versions[name][:options] && self.class.versions[name][:options][:from_version]
Expand All @@ -229,7 +230,6 @@ def cache_versions!(new_file)
else
v.cache!(processed_parent)
end
v.send(:cache_id=, cache_id)
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/uploader/versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ def rotate
end

it "should set store_path with versions" do
CarrierWave.should_receive(:generate_cache_id).once
@uploader.cache!(File.open(file_path('test.jpg')))
@uploader.store_path.should == 'uploads/test.jpg'
@uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
@uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
end

it "should move it to the tmp dir with the filename prefixed" do
CarrierWave.should_receive(:generate_cache_id).once
@uploader.cache!(File.open(file_path('test.jpg')))
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
@uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
Expand All @@ -194,6 +196,7 @@ def rotate
end

it "should cache the files based on the parent" do
CarrierWave.should_receive(:generate_cache_id).once
@uploader.cache!(File.open(file_path('bork.txt')))

File.read(public_path(@uploader.to_s)).should == File.read(public_path(@uploader.thumb.to_s))
Expand Down

0 comments on commit ca91f30

Please sign in to comment.