From cda2d14898347fa949c8e7d7ddbf9b1b7298fe7f Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 6 Oct 2008 14:42:58 -0700 Subject: [PATCH] remove temp_path= and temp_data= methods so they cant be assigned with multiple attributes --- lib/technoweenie/attachment_fu.rb | 17 +++++------------ .../processors/core_image_processor.rb | 2 +- .../attachment_fu/processors/gd2_processor.rb | 2 +- .../processors/image_science_processor.rb | 2 +- .../processors/mini_magick_processor.rb | 2 +- .../processors/rmagick_processor.rb | 2 +- test/backends/file_system_test.rb | 2 +- test/base_attachment_tests.rb | 6 +++--- test/processors/rmagick_test.rb | 4 ++-- 9 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/technoweenie/attachment_fu.rb b/lib/technoweenie/attachment_fu.rb index fe86455..e29b320 100644 --- a/lib/technoweenie/attachment_fu.rb +++ b/lib/technoweenie/attachment_fu.rb @@ -167,6 +167,7 @@ module Technoweenie # :nodoc: 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 @@ module Technoweenie # :nodoc: 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 @@ module Technoweenie # :nodoc: [] : [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. diff --git a/lib/technoweenie/attachment_fu/processors/core_image_processor.rb b/lib/technoweenie/attachment_fu/processors/core_image_processor.rb index 2672e37..fc85c31 100644 --- a/lib/technoweenie/attachment_fu/processors/core_image_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/core_image_processor.rb @@ -46,7 +46,7 @@ module Technoweenie # :nodoc: 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 diff --git a/lib/technoweenie/attachment_fu/processors/gd2_processor.rb b/lib/technoweenie/attachment_fu/processors/gd2_processor.rb index d120b25..6d8e7ba 100644 --- a/lib/technoweenie/attachment_fu/processors/gd2_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/gd2_processor.rb @@ -44,7 +44,7 @@ module Technoweenie # :nodoc: 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 diff --git a/lib/technoweenie/attachment_fu/processors/image_science_processor.rb b/lib/technoweenie/attachment_fu/processors/image_science_processor.rb index 6f27833..e46f376 100644 --- a/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/image_science_processor.rb @@ -34,7 +34,7 @@ module Technoweenie # :nodoc: # 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) diff --git a/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb b/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb index 668a720..3fc1750 100644 --- a/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb @@ -51,7 +51,7 @@ module Technoweenie # :nodoc: commands.resize(size.to_s) end end - self.temp_path = img + temp_paths.unshift img end end end diff --git a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb index aa83b29..0b99929 100644 --- a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb @@ -46,7 +46,7 @@ module Technoweenie # :nodoc: 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 diff --git a/test/backends/file_system_test.rb b/test/backends/file_system_test.rb index d3250c1..7215d8b 100644 --- a/test/backends/file_system_test.rb +++ b/test/backends/file_system_test.rb @@ -52,7 +52,7 @@ class FileSystemTest < Test::Unit::TestCase 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" diff --git a/test/base_attachment_tests.rb b/test/base_attachment_tests.rb index f764a71..a35ab1c 100644 --- a/test/base_attachment_tests.rb +++ b/test/base_attachment_tests.rb @@ -31,7 +31,7 @@ module BaseAttachmentTests 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 @@ module BaseAttachmentTests 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 @@ module BaseAttachmentTests 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 diff --git a/test/processors/rmagick_test.rb b/test/processors/rmagick_test.rb index 98b67dd..8e07f21 100644 --- a/test/processors/rmagick_test.rb +++ b/test/processors/rmagick_test.rb @@ -181,7 +181,7 @@ class RmagickTest < Test::Unit::TestCase 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 @@ class RmagickTest < Test::Unit::TestCase # #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