Permalink
Browse files

small tweaks with tempfile path

git-svn-id: http://svn.techno-weenie.net/projects/plugins/attachment_fu@2567 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information...
1 parent 88f42fb commit 1c56f39b9c6a861002aa1623f0caa7943b52e3ea technoweenie committed Dec 23, 2006
Showing with 8 additions and 10 deletions.
  1. +6 −8 lib/technoweenie/attachment_fu.rb
  2. +1 −1 test/backends/file_system_test.rb
  3. +1 −1 test/base_attachment_tests.rb
View
14 lib/technoweenie/attachment_fu.rb
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
View
2 test/backends/file_system_test.rb
@@ -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"
View
2 test/base_attachment_tests.rb
@@ -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

0 comments on commit 1c56f39

Please sign in to comment.