Permalink
Browse files

On the way to good-code-dom

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@241 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent d68a942 commit 26444ced7ca5a64b2697016dc409ba177ad1ff72 jyurek committed Nov 9, 2007
Showing with 16 additions and 10 deletions.
  1. +2 −2 init.rb
  2. +11 −7 lib/paperclip.rb
  3. +3 −1 test/paperclip_test.rb
View
@@ -1,3 +1,3 @@
require File.join(File.dirname(__FILE__), "lib", "paperclip")
-ActiveRecord::Base.extend( Thoughtbot::Paperclip::ClassMethods )
-File.send :include, Thoughtbot::Paperclip::Upfile
+ActiveRecord::Base.extend( Paperclip::ClassMethods )
+File.send :include, Paperclip::Upfile
View
@@ -395,11 +395,12 @@ def has_attached_file *attachment_names
options = attachment_names.last.is_a?(Hash) ? attachment_names.pop : {}
include InstanceMethods
- class_inheritable_hash :attachment_definitions
+ #class_inheritable_hash :attachment_definitions
+ @attachment_definitions ||= {}
attachment_names.each do |aname|
whine_about_columns_for aname
- self.attachment_definitions[aname] = AttachmentDefinition.new(aname, options)
+ @attachment_definitions[aname] = AttachmentDefinition.new(aname, options)
define_method aname do
attachment_for(aname)
@@ -412,7 +413,11 @@ def has_attached_file *attachment_names
end
def attached_files
- attachment_definitions.keys
+ @attachment_definitions.keys
+ end
+
+ def attachment_definition_for attachment
+ @attachment_definitions[attachment]
end
# Adds errors if the attachments you specify are either missing or had errors on them.
@@ -426,10 +431,9 @@ def validates_attached_file *attachment_names
end
def whine_about_columns_for attachment #:nodoc:
- name = attachment[:name]
- unless column_names.include?("#{name}_file_name") && column_names.include?("#{name}_content_type")
- error = "Class #{self.name} does not have the necessary columns to have an attachment named #{name}. " +
- "(#{name}_file_name and #{name}_content_type)"
+ unless column_names.include?("#{attachment}_file_name") && column_names.include?("#{attachment}_content_type")
+ error = "Class #{name} does not have the necessary columns to have an attachment named #{attachment}. " +
+ "(#{attachment}_file_name and #{attachment}_content_type)"
raise PaperclipError, error
end
end
@@ -1,7 +1,7 @@
require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/simply_shoulda.rb"
-require File.dirname(__FILE__) + "/../lib/paperclip-c.rb"
+require File.dirname(__FILE__) + "/../init.rb"
class PaperclipTest < Test::Unit::TestCase
@@ -29,6 +29,7 @@ class PaperclipTest < Test::Unit::TestCase
table.column :document_content_type, :string
table.column :document_file_size, :integer
end
+ Object.send(:remove_const, :Foo) rescue nil
class ::Foo < ActiveRecord::Base; end
end
@@ -51,6 +52,7 @@ class ::Foo < ActiveRecord::Base; end
should "be able to set options on attachments" do
assert Foo.has_attached_file :image, :thumbnails => {:thumb => "100x100"}
assert_equal [:image], Foo.attached_files
+ assert_equal( {:thumb => "100x100"}, Foo.attachment_definition_for(:image).thumbnails )
end
end

0 comments on commit 26444ce

Please sign in to comment.