public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
raise error if you try a db attachment without the db_file_id attribute

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2458 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Nov 08 21:54:25 -0800 2006
commit  7c9c1b0caf06ee977b9533fac4a6a90c9f703bcd
tree    0833249921dc96974e9536a6fc817807499acdd4
parent  f0d8659f0cb797c1a5ef93b2e8a7c5563ef2475f
...
3
4
5
6
 
 
7
8
9
...
50
51
52
53
 
 
54
55
56
...
61
62
63
 
 
 
 
 
64
65
66
...
3
4
5
 
6
7
8
9
10
...
51
52
53
 
54
55
56
57
58
...
63
64
65
66
67
68
69
70
71
72
73
0
@@ -3,7 +3,8 @@ module Technoweenie # :nodoc:
0
     @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
0
     mattr_reader :content_types
0
 
0
- class ThumbnailError < StandardError; end
0
+ class ThumbnailError < StandardError; end
0
+ class AttachmentError < StandardError; end
0
 
0
     def self.included(base) # :nodoc:
0
       base.extend ActMethods
0
@@ -50,7 +51,8 @@ module Technoweenie # :nodoc:
0
         unless included_modules.include? InstanceMethods
0
           class_inheritable_accessor :attachment_options, :attachment_attributes
0
 
0
- self.attachment_attributes = [:parent_id, :filename].inject({}) { |memo, attr_name| memo.update attr_name => column_names.include?(attr_name.to_s) }
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
 
0
           after_destroy :destroy_file
0
 
0
@@ -61,6 +63,11 @@ module Technoweenie # :nodoc:
0
           end if attachment_attributes[:parent_id]
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
...
14
15
16
 
 
 
 
 
 
 
 
 
 
17
18
19
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
0
@@ -14,6 +14,16 @@ 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
...
81
82
83
84
85
86
87
88
89
90
91
 
92
...
81
82
83
 
 
 
 
 
 
 
84
85
86
0
@@ -81,10 +81,4 @@ class MinimalAttachment < ActiveRecord::Base
0
   def filename
0
     "#{id}.file"
0
   end
0
-end
0
-
0
-## db attachment with no db_file_id
0
-#class InvalidAttachment < ActiveRecord::Base
0
-# acts_as_attachment
0
-# validates_as_attachment
0
-#end
0
\ No newline at end of file
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.