Skip to content

Commit

Permalink
fixed bug in get_content_type
Browse files Browse the repository at this point in the history
git-svn-id: http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk@52 6a5db2c9-b104-0410-84e5-917aad89f9d9
  • Loading branch information
skanthak committed Jan 1, 2006
1 parent 9bac6ed commit cf0a662
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/file_column.rb
Expand Up @@ -327,7 +327,7 @@ def delete_files
def get_content_type(fallback=nil)
if options[:file_exec]
begin
content_type = `#{options[:file_exec]} -bi "#{@local_file_path}"`.chomp
content_type = `#{options[:file_exec]} -bi "#{File.join(@dir,@filename)}"`.chomp
content_type = fallback unless $?.success?
content_type.gsub!(/;.+$/,"") if content_type
content_type
Expand Down
17 changes: 16 additions & 1 deletion test/file_column_test.rb
Expand Up @@ -126,14 +126,29 @@ def test_get_content_type_with_file
if File.executable?(FILE_UTILITY)
e = Entry.new
file = FileColumn::TempUploadedFile.new(e, "image")
file.instance_variable_set :@local_file_path, file_path("kerb.jpg")
file.instance_variable_set :@dir, File.dirname(file_path("kerb.jpg"))
file.instance_variable_set :@filename, File.basename(file_path("kerb.jpg"))

assert_equal "image/jpeg", file.get_content_type
else
puts "Warning: Skipping test_get_content_type_with_file test as '#{options[:file_exec]}' does not exist"
end
end

def test_fix_extension_with_file
Entry.file_column :image, :file_exec => FILE_UTILITY

# run this test only if the machine we are running on
# has the file utility installed
if File.executable?(FILE_UTILITY)
e = Entry.new(:image => uploaded_file(file_path("skanthak.png"), "", "skanthak.jpg"))

assert_equal "skanthak.png", File.basename(e.image)
else
puts "Warning: Skipping test_fix_extension_with_file test as '#{options[:file_exec]}' does not exist"
end
end

def test_do_not_fix_file_extensions
Entry.file_column :image, :fix_file_extensions => false

Expand Down

0 comments on commit cf0a662

Please sign in to comment.