Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix content type being reset when using file cache storage #2117

Merged
merged 2 commits into from
Feb 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/carrierwave/sanitized_file.rb
Original file line number Diff line number Diff line change
@@ -186,9 +186,9 @@ def move_to(new_path, permissions=nil, directory_permissions=nil, keep_filename=
move!(new_path)
chmod!(new_path, permissions)
if keep_filename
self.file = {:tempfile => new_path, :filename => original_filename}
self.file = {:tempfile => new_path, :filename => original_filename, :content_type => content_type}
else
self.file = new_path
self.file = {:tempfile => new_path, :content_type => content_type}
end
self
end
7 changes: 7 additions & 0 deletions spec/sanitized_file_spec.rb
Original file line number Diff line number Diff line change
@@ -307,6 +307,13 @@
it "should return itself" do
expect(sanitized_file.move_to(file_path("gurr.png"))).to eq(sanitized_file)
end

it "should preserve the file's content type" do
content_type = sanitized_file.content_type
sanitized_file.move_to(file_path("new_dir","gurr.png"))

expect(sanitized_file.content_type).to eq(content_type)
end
end

describe "#copy_to" do
18 changes: 16 additions & 2 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
@@ -64,8 +64,8 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end

it "should have a content_type" do
expect(@fog_file.content_type).to eq('image/jpeg')
expect(@directory.files.get(store_path).content_type).to eq('image/jpeg')
expect(@fog_file.content_type).to eq(file.content_type)
expect(@directory.files.get(store_path).content_type).to eq(file.content_type)
end

it "should have an extension" do
@@ -244,6 +244,10 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
it "should upload the file", focus: true do
expect(@directory.files.get('uploads/tmp/test+.jpg').body).to eq('this is stuff')
end

it 'should preserve content type' do
expect(@fog_file.content_type).to eq(file.content_type)
end
end

describe '#retrieve_from_cache!' do
@@ -415,6 +419,16 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base

end

describe "with a valid File object with an explicit content type" do
let(:file) do
CarrierWave::SanitizedFile.new(stub_file('test.jpg', 'image/jpeg')).tap do |f|
f.content_type = 'image/jpg'
end
end

it_should_behave_like "#{fog_credentials[:provider]} storage"
end

describe "with a valid path" do
let(:file) do
CarrierWave::SanitizedFile.new(file_path('test.jpg'))