Permalink
Browse files

Enforce saving content_type as a string with test

  • Loading branch information...
1 parent e59d0b5 commit 8b778b301990da7b70877c81c20ef358a7708a4f @jyurek jyurek committed Apr 24, 2012
Showing with 17 additions and 2 deletions.
  1. +1 −1 lib/paperclip/attachment.rb
  2. +1 −1 lib/paperclip/io_adapters/stringio_adapter.rb
  3. +15 −0 test/attachment_test.rb
View
2 lib/paperclip/attachment.rb
@@ -95,7 +95,7 @@ def assign uploaded_file
@queued_for_write[:original] = file
instance_write(:file_name, cleanup_filename(file.original_filename))
- instance_write(:content_type, file.content_type)
+ instance_write(:content_type, file.content_type.to_s.strip)
instance_write(:file_size, file.size)
instance_write(:fingerprint, file.fingerprint) if instance_respond_to?(:fingerprint)
instance_write(:updated_at, Time.now)
View
2 lib/paperclip/io_adapters/stringio_adapter.rb
@@ -16,7 +16,7 @@ def original_filename
def content_type
@content_type ||= @target.content_type if @target.respond_to?(:content_type)
@content_type ||= "text/plain"
- @content_type.strip
+ @content_type
end
def size
View
15 test/attachment_test.rb
@@ -691,6 +691,21 @@ def do_after_all; end
end
end
+ context "Assigning an attachment" do
+ setup do
+ rebuild_model :styles => { :something => "100x100#" }
+ @file = StringIO.new(".")
+ @file.stubs(:original_filename).returns("5k.png\n\n")
+ @file.stubs(:content_type).returns(MIME::Type.new("image/png"))
@sikachu
thoughtbot, inc. member
sikachu added a line comment Apr 24, 2012

This is actually not possible anymore after 3f1d30f, as before we were forgot to call #to_s on the MIME::Type object returning from the MIME::Type.type_for and caused the problem. I've fixed that and make sure that we called #to_s on the adapter level already.

Should I revert this?

@mike-burns
thoughtbot, inc. member
mike-burns added a line comment May 7, 2012

Probably!

(Is this already reverted?)

@sikachu
thoughtbot, inc. member
sikachu added a line comment May 7, 2012

No, not yet. We've talked IRL and seems like keeping it in would be fine, for the sake of making sure that there'll be no regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
+
+ should "make sure the content_type is a string" do
+ assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
+ end
+ end
+
context "Attachment with strange letters" do
setup do
rebuild_model

0 comments on commit 8b778b3

Please sign in to comment.