public
Fork of halorgium/mephisto
Description: A refactored Mephisto that has multiple spam detection engines.
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/francois/mephisto.git
don't check column_names in the acts_as_attachment macro, just use 
respond_to

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2460 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Fri Nov 10 09:17:15 -0800 2006
commit  d4183f071e40ea47f4e0c7bf139374c196efa7ec
tree    6269500dfe73a30f5c6aa327803427fe42d5b551
parent  7c9c1b0caf06ee977b9533fac4a6a90c9f703bcd
...
49
50
51
52
53
54
55
 
56
57
58
...
60
61
62
63
 
64
65
66
67
68
69
70
71
72
73
...
49
50
51
 
 
 
 
52
53
54
55
...
57
58
59
 
60
61
62
63
 
 
 
 
64
65
66
0
@@ -49,10 +49,7 @@ module Technoweenie # :nodoc:
0
 
0
         # only need to define these once on a class
0
         unless included_modules.include? InstanceMethods
0
- class_inheritable_accessor :attachment_options, :attachment_attributes
0
-
0
- # so far, parent_id is the only attribute i care about checking
0
- self.attachment_attributes = [:parent_id].inject({}) { |memo, attr_name| memo.update attr_name => column_names.include?(attr_name.to_s) }
0
+ class_inheritable_accessor :attachment_options
0
 
0
           after_destroy :destroy_file
0
 
0
@@ -60,14 +57,10 @@ module Technoweenie # :nodoc:
0
           with_options :foreign_key => 'parent_id' do |m|
0
             m.has_many :thumbnails, :dependent => :destroy, :class_name => options[:thumbnail_class].to_s
0
             m.belongs_to :parent, :class_name => self.base_class.to_s
0
- end if attachment_attributes[:parent_id]
0
+ end
0
 
0
           include set_fs_path || options[:storage] == :file_system ? FileSystemMethods : DbFileMethods
0
           
0
- if included_modules.include?(DbFileMethods) && !column_names.include?('db_file_id')
0
- raise AttachmentError.new("Database attachments must have a db_file_id column")
0
- end
0
-
0
           after_save :create_attachment_thumbnails # allows thumbnails with parent_id to be created
0
 
0
           extend ClassMethods
...
38
39
40
41
 
42
43
44
...
38
39
40
 
41
42
43
44
0
@@ -38,7 +38,7 @@ module Technoweenie # :nodoc:
0
 
0
       # The attachment ID used in the full path of a file
0
       def attachment_path_id
0
- ((attachment_attributes[:parent_id] && parent_id) || id).to_s
0
+ ((respond_to?(:parent_id) && parent_id) || id).to_s
0
       end
0
 
0
       # Gets the public path to the file
...
8
9
10
11
 
12
13
14
...
63
64
65
66
 
67
68
69
...
145
146
147
148
 
149
150
151
...
8
9
10
 
11
12
13
14
...
63
64
65
 
66
67
68
69
...
145
146
147
 
148
149
150
151
0
@@ -8,7 +8,7 @@ module Technoweenie # :nodoc:
0
       end
0
       
0
       def thumbnailable?
0
- image? && attachment_attributes[:parent_id]
0
+ image? && respond_to?(:parent_id)
0
       end
0
 
0
       def thumbnail_class
0
@@ -63,7 +63,7 @@ module Technoweenie # :nodoc:
0
           return nil
0
         end
0
         with_image data do |img|
0
- resized_img = (attachment_options[:resize_to] && (!attachment_attributes[:parent_id] || parent_id.nil?)) ?
0
+ resized_img = (attachment_options[:resize_to] && (!respond_to?(:parent_id) || parent_id.nil?)) ?
0
             thumbnail_for_image(img, attachment_options[:resize_to]) : img
0
           data = resized_img.to_blob
0
           self.width = resized_img.columns if respond_to?(:width)
0
@@ -145,7 +145,7 @@ module Technoweenie # :nodoc:
0
         end
0
 
0
         def find_or_initialize_thumbnail(file_name_suffix)
0
- attachment_attributes[:parent_id] ?
0
+ respond_to?(:parent_id) ?
0
             thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
0
             thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
0
         end
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
14
15
16
 
 
 
 
 
 
 
 
 
 
17
18
19
0
@@ -14,16 +14,6 @@ class DbAttachmentTest < Test::Unit::TestCase
0
   end
0
   
0
   test_against_subclass :test_should_call_after_attachment_saved, Attachment
0
-
0
- def test_should_rally_against_db_attachments_without_db_file_id
0
- assert_raise Technoweenie::ActsAsAttachment::AttachmentError do
0
- Class.new ActiveRecord::Base do
0
- set_table_name 'invalid_attachments'
0
- acts_as_attachment
0
- validates_as_attachment
0
- end
0
- end
0
- end
0
 end
0
 
0
 class OrphanAttachmentTest < Test::Unit::TestCase
...
34
35
36
37
38
39
40
41
42
43
...
34
35
36
 
 
 
 
37
38
39
0
@@ -34,10 +34,6 @@ ActiveRecord::Schema.define(:version => 0) do
0
     t.column :size, :integer
0
     t.column :content_type, :string, :limit => 255
0
   end
0
- #
0
- #create_table :invalid_attachments, :force => true do |t|
0
- # t.column :size, :integer
0
- #end
0
 
0
   create_table :db_files, :force => true do |t|
0
     t.column :data, :binary

Comments

    No one has commented yet.