Skip to content
Browse files

remove temp_path= and temp_data= methods so they cant be assigned wit…

…h multiple attributes
  • Loading branch information...
1 parent 88af790 commit cda2d14898347fa949c8e7d7ddbf9b1b7298fe7f @technoweenie technoweenie committed Oct 6, 2008
View
17 lib/technoweenie/attachment_fu.rb
@@ -167,6 +167,7 @@ def self.extended(base)
base.after_save :after_process_attachment
base.after_destroy :destroy_file
base.after_validation :process_attachment
+ base.attr_accessible
if defined?(::ActiveSupport::Callbacks)
base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
end
@@ -331,9 +332,9 @@ def uploaded_data=(file_data)
end
if file_data.is_a?(StringIO)
file_data.rewind
- self.temp_data = file_data.read
+ set_temp_data file_data.read
else
- self.temp_path = file_data
+ self.temp_paths.unshift file_data
end
end
@@ -352,22 +353,14 @@ def temp_paths
[] : [copy_to_temp_file(full_filename)])
end
- # Adds a new temp_path to the array. This should take a string or a Tempfile. This class makes no
- # attempt to remove the files, so Tempfiles should be used. Tempfiles remove themselves when they go out of scope.
- # You can also use string paths for temporary files, such as those used for uploaded files in a web server.
- def temp_path=(value)
- temp_paths.unshift value
- temp_path
- end
-
# Gets the data from the latest temp file. This will read the file into memory.
def temp_data
save_attachment? ? File.read(temp_path) : nil
end
# Writes the given data to a Tempfile and adds it to the collection of temp files.
- def temp_data=(data)
- self.temp_path = write_to_temp_file data unless data.nil?
+ def set_temp_data(data)
+ temp_paths.unshift write_to_temp_file data unless data.nil?
end
# Copies the given file to a randomly named Tempfile.
View
2 lib/technoweenie/attachment_fu/processors/core_image_processor.rb
@@ -46,7 +46,7 @@ def resize_image(img, size)
self.height = result.extent.size.height if respond_to?(:height)
# Get a new temp_path for the image before saving
- self.temp_path = Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
+ temp_paths.unshift Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
result.save self.temp_path, OSX::NSJPEGFileType
self.size = File.size(self.temp_path)
end
View
2 lib/technoweenie/attachment_fu/processors/gd2_processor.rb
@@ -44,7 +44,7 @@ def resize_image(img, size)
w, h = [img.width, img.height] / size.to_s
img.resize!(w, h, false)
end
- self.temp_path = random_tempfile_filename
+ temp_paths.unshift random_tempfile_filename
self.size = img.export(self.temp_path)
end
View
2 lib/technoweenie/attachment_fu/processors/image_science_processor.rb
@@ -34,7 +34,7 @@ def resize_image(img, size)
# supports.
filename.sub! /gif$/, 'png'
content_type.sub!(/gif$/, 'png')
- self.temp_path = write_to_temp_file(filename)
+ temp_paths.unshift write_to_temp_file(filename)
grab_dimensions = lambda do |img|
self.width = img.width if respond_to?(:width)
self.height = img.height if respond_to?(:height)
View
2 lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb
@@ -51,7 +51,7 @@ def resize_image(img, size)
commands.resize(size.to_s)
end
end
- self.temp_path = img
+ temp_paths.unshift img
end
end
end
View
2 lib/technoweenie/attachment_fu/processors/rmagick_processor.rb
@@ -46,7 +46,7 @@ def resize_image(img, size)
img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
end
img.strip! unless attachment_options[:keep_profile]
- self.temp_path = write_to_temp_file(img.to_blob)
+ temp_paths.unshift write_to_temp_file(img.to_blob)
end
end
end
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(fixture_path, file)
+ attachment.temp_paths.unshift 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
6 test/base_attachment_tests.rb
@@ -31,7 +31,7 @@ def test_reassign_attribute_data
assert_valid attachment
assert attachment.size > 0, "no data was set"
- attachment.temp_data = 'wtf'
+ attachment.set_temp_data 'wtf'
assert attachment.save_attachment?
attachment.save!
@@ -45,7 +45,7 @@ def test_no_reassign_attribute_data_on_nil
assert_valid attachment
assert attachment.size > 0, "no data was set"
- attachment.temp_data = nil
+ attachment.set_temp_data nil
assert !attachment.save_attachment?
end
end
@@ -55,7 +55,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(fixture_path, file)
+ attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end
View
4 test/processors/rmagick_test.rb
@@ -181,7 +181,7 @@ def test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbs
assert_not_created do
use_temp_file "files/rails.png" do |file|
attachment.filename = 'rails2.png'
- attachment.temp_path = File.join(fixture_path, file)
+ attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save
new_filenames = [attachment.reload.full_filename] + attachment.thumbnails.collect { |t| t.reload.full_filename }
new_filenames.each { |f| assert File.exists?(f), "#{f} does not exist" }
@@ -224,7 +224,7 @@ def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithT
# #temp_path calls #full_filename, which is not getting mixed into the attachment. Maybe we don't need to
# set temp_path at all?
#
- # attachment.temp_path = File.join(fixture_path, file)
+ # attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end

0 comments on commit cda2d14

Please sign in to comment.
Something went wrong with that request. Please try again.