Browse files

SanitizedFile#copy_to preserves the content_type

of the copied file.

This is important for storage systems like GridFS
where the content_type is persisted in the DB
  • Loading branch information...
1 parent 695bb99 commit e37bec3c704646bf8db32bcf1a3c5165d4e0a301 @iwarshak iwarshak committed with jnicklas May 29, 2010
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/carrierwave/sanitized_file.rb
  2. +5 −0 spec/sanitized_file_spec.rb
View
2 lib/carrierwave/sanitized_file.rb
@@ -199,7 +199,7 @@ def copy_to(new_path, permissions=nil)
File.open(new_path, "wb") { |f| f.write(read) }
end
chmod!(new_path, permissions)
- self.class.new(new_path)
+ self.class.new({:tempfile => File.open(new_path), :content_type => content_type})
end
##
View
5 spec/sanitized_file_spec.rb
@@ -275,6 +275,11 @@
new_file = @sanitized_file.copy_to(file_path('gurr.png'), 0755)
new_file.should have_permissions(0755)
end
+
+ it "should preserve the file's content type" do
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
+ new_file.content_type.should ==(@sanitized_file.content_type)
+ end
end

0 comments on commit e37bec3

Please sign in to comment.