From 7a2e2ed8f2cedf407a818ab27f3ef3818a35d672 Mon Sep 17 00:00:00 2001 From: Pavel Forkert Date: Thu, 29 Sep 2011 18:12:08 +0300 Subject: [PATCH] Do not save class instances, save their names. Saving instances causes memory leaks in development mode in rails. --- lib/paperclip.rb | 2 +- lib/paperclip/missing_attachment_styles.rb | 3 ++- test/paperclip_missing_attachment_styles_test.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 2b75f0017..aadc460a9 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -318,7 +318,7 @@ def has_attached_file name, options = {} end attachment_definitions[name] = {:validations => []}.merge(options) - Paperclip.classes_with_attachments << self unless Paperclip.classes_with_attachments.include?(self) + Paperclip.classes_with_attachments << self.name unless Paperclip.classes_with_attachments.include?(self.name) Paperclip.check_for_url_clash(name,attachment_definitions[name][:url],self.name) after_save :save_attached_files diff --git a/lib/paperclip/missing_attachment_styles.rb b/lib/paperclip/missing_attachment_styles.rb index 5384d9d4a..934dc8d64 100644 --- a/lib/paperclip/missing_attachment_styles.rb +++ b/lib/paperclip/missing_attachment_styles.rb @@ -38,7 +38,8 @@ def self.save_current_attachments_styles! # } def self.current_attachments_styles Hash.new.tap do |current_styles| - Paperclip.classes_with_attachments.each do |klass| + Paperclip.classes_with_attachments.each do |klass_name| + klass = Paperclip.class_for(klass_name) klass.attachment_definitions.each do |attachment_name, attachment_attributes| # TODO: is it even possible to take into account Procs? next if attachment_attributes[:styles].kind_of?(Proc) diff --git a/test/paperclip_missing_attachment_styles_test.rb b/test/paperclip_missing_attachment_styles_test.rb index 19b45550b..ea1608bad 100644 --- a/test/paperclip_missing_attachment_styles_test.rb +++ b/test/paperclip_missing_attachment_styles_test.rb @@ -15,7 +15,7 @@ class PaperclipMissingAttachmentStylesTest < Test::Unit::TestCase assert_kind_of Set, Paperclip.classes_with_attachments assert Paperclip.classes_with_attachments.empty?, 'list should be empty' rebuild_model - assert_equal [Dummy].to_set, Paperclip.classes_with_attachments + assert_equal ['Dummy'].to_set, Paperclip.classes_with_attachments end should "enable to get and set path to registered styles file" do