Commit 9e6afe4f by Jon Yurek

Include a module other than top-level Paperclip to prevent namespace collisions.

parent 6868ff95
......@@ -103,15 +103,6 @@ module Paperclip
CommandLine.new(cmd, *params).run
end
def included base #:nodoc:
base.extend ClassMethods
if base.respond_to?("set_callback")
base.send :include, Paperclip::CallbackCompatability::Rails3
else
base.send :include, Paperclip::CallbackCompatability::Rails21
end
end
def processor name #:nodoc:
name = name.to_s.camelize
processor = Paperclip.const_get(name)
......@@ -159,6 +150,17 @@ module Paperclip
class InfiniteInterpolationError < PaperclipError #:nodoc:
end
module Glue
def self.included base #:nodoc:
base.extend ClassMethods
if base.respond_to?("set_callback")
base.send :include, Paperclip::CallbackCompatability::Rails3
else
base.send :include, Paperclip::CallbackCompatability::Rails21
end
end
end
module ClassMethods
# +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
# is typically a file stored somewhere on the filesystem and has been uploaded by a user.
......
......@@ -17,7 +17,7 @@ module Paperclip
class Railtie
def self.insert
ActiveRecord::Base.send(:include, Paperclip)
ActiveRecord::Base.send(:include, Paperclip::Glue)
File.send(:include, Paperclip::Upfile)
end
end
......
......@@ -61,10 +61,10 @@ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FIL
ActiveRecord::Base.establish_connection(config['test'])
def reset_class class_name
ActiveRecord::Base.send(:include, Paperclip)
ActiveRecord::Base.send(:include, Paperclip::Glue)
Object.send(:remove_const, class_name) rescue nil
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
klass.class_eval{ include Paperclip }
klass.class_eval{ include Paperclip::Glue }
klass
end
......@@ -90,11 +90,11 @@ def rebuild_model options = {}
end
def rebuild_class options = {}
ActiveRecord::Base.send(:include, Paperclip)
ActiveRecord::Base.send(:include, Paperclip::Glue)
Object.send(:remove_const, "Dummy") rescue nil
Object.const_set("Dummy", Class.new(ActiveRecord::Base))
Dummy.class_eval do
include Paperclip
include Paperclip::Glue
has_attached_file :avatar, options
end
end
......
......@@ -172,6 +172,12 @@ class PaperclipTest < Test::Unit::TestCase
end
end
should "not have Attachment in the ActiveRecord::Base namespace" do
assert_raises(NameError) do
ActiveRecord::Base::Attachment
end
end
def self.should_validate validation, options, valid_file, invalid_file
context "with #{validation} validation and #{options.inspect} options" do
setup do
......
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