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