Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Falling back to wand if content_type returns blank.

Rails returns uploaded files that have content_type but sometimes returns blank. This makes it so it doesn't try to use rails blank types.
  • Loading branch information...
commit 6d9e25cb6a570b0febe2f3e3b5f7795342af0b31 1 parent 7ac3e19
@jnunemaker authored
Showing with 20 additions and 5 deletions.
  1. +11 −4 lib/joint.rb
  2. +9 −1 test/test_joint.rb
View
15 lib/joint.rb
@@ -26,11 +26,18 @@ def self.size(file)
end
def self.type(file)
- if file.respond_to?(:content_type)
- file.content_type
- else
- Wand.wave(file.path, :original_filename => Joint.name(file))
+ type = file.content_type if file.respond_to?(:content_type)
+
+ if blank?(type)
+ type = Wand.wave(file.path, :original_filename => Joint.name(file))
end
+
+ type
+ end
+
+private
+ def self.blank?(str)
+ str.nil? || str !~ /\S/
end
end
View
10 test/test_joint.rb
@@ -43,13 +43,21 @@ def @image.size
end
context ".type" do
- should "return type" do
+ should "return content_type if responds to it" do
def @image.content_type
'plain/text'
end
Joint.type(@image).should == 'plain/text'
end
+ should "fall back to Wand if content_type is blank" do
+ def @image.content_type; '' end
+ Joint.type(@image).should == 'image/jpeg'
+
+ def @image.content_type; ' ' end
+ Joint.type(@image).should == 'image/jpeg'
+ end
+
should "fall back to Wand" do
Joint.type(@image).should == 'image/jpeg'
end
Please sign in to comment.
Something went wrong with that request. Please try again.