Skip to content

Commit

Permalink
small tweaks with tempfile path
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.techno-weenie.net/projects/plugins/attachment_fu@2567 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Dec 23, 2006
1 parent 88f42fb commit 1c56f39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions lib/technoweenie/attachment_fu.rb
Expand Up @@ -11,9 +11,9 @@ def make_tmpname(basename, n)

module Technoweenie # :nodoc:
module AttachmentFu # :nodoc:
@@temp_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
@@tempfile_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
@@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
mattr_reader :content_types, :temp_path
mattr_reader :content_types, :tempfile_path

class ThumbnailError < StandardError; end
class AttachmentError < StandardError; end
Expand Down Expand Up @@ -142,7 +142,7 @@ def thumbnail_class

def copy_to_temp_file(file, temp_base_name)
path = nil
Tempfile.open temp_base_name, Technoweenie::AttachmentFu.temp_path do |f|
Tempfile.open temp_base_name, Technoweenie::AttachmentFu.tempfile_path do |f|
path = f.path
end
FileUtils.cp file, path
Expand All @@ -151,7 +151,7 @@ def copy_to_temp_file(file, temp_base_name)

def write_to_temp_file(data, temp_base_name)
path = nil
Tempfile.open temp_base_name, Technoweenie::AttachmentFu.temp_path do |f|
Tempfile.open temp_base_name, Technoweenie::AttachmentFu.tempfile_path do |f|
path = f.path
f.write data
end
Expand Down Expand Up @@ -180,8 +180,7 @@ def thumbnail_name_for(thumbnail = nil)
return filename if thumbnail.blank?
ext = nil
basename = filename.gsub /\.\w+$/ do |s|
ext = s
''
ext = s; ''
end
"#{basename}_#{thumbnail}#{ext}"
end
Expand Down Expand Up @@ -264,8 +263,7 @@ def sanitize_filename(filename)
end

def set_size_from_temp_path
return unless save_attachment?
self.size = File.size(temp_path)
self.size = File.size(temp_path) if save_attachment?
end

# validates the size and content_type attributes according to the current model's options
Expand Down
2 changes: 1 addition & 1 deletion test/backends/file_system_test.rb
Expand Up @@ -52,7 +52,7 @@ def test_should_delete_old_file_when_updating(klass = FileAttachment)
assert_not_created do
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(Test::Unit::TestCase.fixture_path, file)
attachment.temp_path = File.join(fixture_path, file)
attachment.save!
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
Expand Down
2 changes: 1 addition & 1 deletion test/base_attachment_tests.rb
Expand Up @@ -42,7 +42,7 @@ def test_should_overwrite_old_contents_when_updating
assert_not_created do # no new db_file records
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(Test::Unit::TestCase.fixture_path, file)
attachment.temp_path = File.join(fixture_path, file)
attachment.save!
end
end
Expand Down

0 comments on commit 1c56f39

Please sign in to comment.