Commit 26444ced by jyurek

On the way to good-code-dom

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@241 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent d68a9421
require File.join(File.dirname(__FILE__), "lib", "paperclip") require File.join(File.dirname(__FILE__), "lib", "paperclip")
ActiveRecord::Base.extend( Thoughtbot::Paperclip::ClassMethods ) ActiveRecord::Base.extend( Paperclip::ClassMethods )
File.send :include, Thoughtbot::Paperclip::Upfile File.send :include, Paperclip::Upfile
\ No newline at end of file \ No newline at end of file
...@@ -395,11 +395,12 @@ module Paperclip ...@@ -395,11 +395,12 @@ module Paperclip
options = attachment_names.last.is_a?(Hash) ? attachment_names.pop : {} options = attachment_names.last.is_a?(Hash) ? attachment_names.pop : {}
include InstanceMethods include InstanceMethods
class_inheritable_hash :attachment_definitions #class_inheritable_hash :attachment_definitions
@attachment_definitions ||= {}
attachment_names.each do |aname| attachment_names.each do |aname|
whine_about_columns_for 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 define_method aname do
attachment_for(aname) attachment_for(aname)
...@@ -412,7 +413,11 @@ module Paperclip ...@@ -412,7 +413,11 @@ module Paperclip
end end
def attached_files def attached_files
attachment_definitions.keys @attachment_definitions.keys
end
def attachment_definition_for attachment
@attachment_definitions[attachment]
end end
# Adds errors if the attachments you specify are either missing or had errors on them. # Adds errors if the attachments you specify are either missing or had errors on them.
...@@ -426,10 +431,9 @@ module Paperclip ...@@ -426,10 +431,9 @@ module Paperclip
end end
def whine_about_columns_for attachment #:nodoc: def whine_about_columns_for attachment #:nodoc:
name = attachment[:name] unless column_names.include?("#{attachment}_file_name") && column_names.include?("#{attachment}_content_type")
unless column_names.include?("#{name}_file_name") && column_names.include?("#{name}_content_type") error = "Class #{name} does not have the necessary columns to have an attachment named #{attachment}. " +
error = "Class #{self.name} does not have the necessary columns to have an attachment named #{name}. " + "(#{attachment}_file_name and #{attachment}_content_type)"
"(#{name}_file_name and #{name}_content_type)"
raise PaperclipError, error raise PaperclipError, error
end end
end end
......
require 'test/unit' require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb" require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/simply_shoulda.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 class PaperclipTest < Test::Unit::TestCase
...@@ -29,6 +29,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -29,6 +29,7 @@ class PaperclipTest < Test::Unit::TestCase
table.column :document_content_type, :string table.column :document_content_type, :string
table.column :document_file_size, :integer table.column :document_file_size, :integer
end end
Object.send(:remove_const, :Foo) rescue nil
class ::Foo < ActiveRecord::Base; end class ::Foo < ActiveRecord::Base; end
end end
...@@ -51,6 +52,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -51,6 +52,7 @@ class PaperclipTest < Test::Unit::TestCase
should "be able to set options on attachments" do should "be able to set options on attachments" do
assert Foo.has_attached_file :image, :thumbnails => {:thumb => "100x100"} assert Foo.has_attached_file :image, :thumbnails => {:thumb => "100x100"}
assert_equal [:image], Foo.attached_files assert_equal [:image], Foo.attached_files
assert_equal( {:thumb => "100x100"}, Foo.attachment_definition_for(:image).thumbnails )
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment