Permalink
Browse files

Getting explicit with Joint.type.

Was trying to be all ducky, but rails was being a PITA. Explicitly checking for Joint::IO instance instead of looking for content_type as rails gets it wrong sometimes in their uploaded files.
  • Loading branch information...
1 parent a802b16 commit 2b1e378b84ab8613013f2de3b24c6a68201847aa @jnunemaker committed Jan 22, 2011
Showing with 12 additions and 27 deletions.
  1. +2 −7 lib/joint.rb
  2. +2 −2 lib/joint/io.rb
  3. +2 −2 test/joint/test_io.rb
  4. +6 −16 test/test_joint.rb
View
@@ -26,13 +26,8 @@ def self.size(file)
end
def self.type(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
+ return file.type if file.is_a?(Joint::IO)
+ Wand.wave(file.path, :original_filename => Joint.name(file))
end
private
View
@@ -1,10 +1,10 @@
module Joint
class IO
- attr_accessor :name, :content, :content_type, :size
+ attr_accessor :name, :content, :type, :size
def initialize(attrs={})
attrs.each { |key, value| send("#{key}=", value) }
- @content_type ||= 'plain/text'
+ @type ||= 'plain/text'
@size ||= @content.size unless @content.nil?
end
View
@@ -7,8 +7,8 @@ class IOTest < Test::Unit::TestCase
end
end
- should "default content_type to plain text" do
- Joint::IO.new.content_type.should == 'plain/text'
+ should "default type to plain text" do
+ Joint::IO.new.type.should == 'plain/text'
end
should "default size to content size" do
View
@@ -43,18 +43,8 @@ def @image.size
end
context ".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
+ should "return type if Joint::Io instance" do
+ file = Joint::IO.new(:type => 'image/jpeg')
Joint.type(@image).should == 'image/jpeg'
end
@@ -354,10 +344,10 @@ def @image.original_filename
context "Assigning joint io instance" do
setup do
io = Joint::IO.new({
- :name => 'foo.txt',
- :content_type => 'plain/text',
- :content => 'This is my stuff',
- :size => 19,
+ :name => 'foo.txt',
+ :type => 'plain/text',
+ :content => 'This is my stuff',
+ :size => 19,
})
@asset = Asset.create(:file => io)
end

0 comments on commit 2b1e378

Please sign in to comment.