Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…collisions.
  • Loading branch information...
commit 9e6afe4ff5b6b07bb1d50a4cb4bdd85feb1c9bbf 1 parent 6868ff9
Jon Yurek jyurek authored
20 lib/paperclip.rb
@@ -103,15 +103,6 @@ def run cmd, *params
103 103 CommandLine.new(cmd, *params).run
104 104 end
105 105
106   - def included base #:nodoc:
107   - base.extend ClassMethods
108   - if base.respond_to?("set_callback")
109   - base.send :include, Paperclip::CallbackCompatability::Rails3
110   - else
111   - base.send :include, Paperclip::CallbackCompatability::Rails21
112   - end
113   - end
114   -
115 106 def processor name #:nodoc:
116 107 name = name.to_s.camelize
117 108 processor = Paperclip.const_get(name)
@@ -159,6 +150,17 @@ class NotIdentifiedByImageMagickError < PaperclipError #:nodoc:
159 150 class InfiniteInterpolationError < PaperclipError #:nodoc:
160 151 end
161 152
  153 + module Glue
  154 + def self.included base #:nodoc:
  155 + base.extend ClassMethods
  156 + if base.respond_to?("set_callback")
  157 + base.send :include, Paperclip::CallbackCompatability::Rails3
  158 + else
  159 + base.send :include, Paperclip::CallbackCompatability::Rails21
  160 + end
  161 + end
  162 + end
  163 +
162 164 module ClassMethods
163 165 # +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
164 166 # is typically a file stored somewhere on the filesystem and has been uploaded by a user.
2  lib/paperclip/railtie.rb
@@ -17,7 +17,7 @@ class Railtie < Rails::Railtie
17 17
18 18 class Railtie
19 19 def self.insert
20   - ActiveRecord::Base.send(:include, Paperclip)
  20 + ActiveRecord::Base.send(:include, Paperclip::Glue)
21 21 File.send(:include, Paperclip::Upfile)
22 22 end
23 23 end
8 test/helper.rb
@@ -61,10 +61,10 @@ def setup
61 61 ActiveRecord::Base.establish_connection(config['test'])
62 62
63 63 def reset_class class_name
64   - ActiveRecord::Base.send(:include, Paperclip)
  64 + ActiveRecord::Base.send(:include, Paperclip::Glue)
65 65 Object.send(:remove_const, class_name) rescue nil
66 66 klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
67   - klass.class_eval{ include Paperclip }
  67 + klass.class_eval{ include Paperclip::Glue }
68 68 klass
69 69 end
70 70
@@ -90,11 +90,11 @@ def rebuild_model options = {}
90 90 end
91 91
92 92 def rebuild_class options = {}
93   - ActiveRecord::Base.send(:include, Paperclip)
  93 + ActiveRecord::Base.send(:include, Paperclip::Glue)
94 94 Object.send(:remove_const, "Dummy") rescue nil
95 95 Object.const_set("Dummy", Class.new(ActiveRecord::Base))
96 96 Dummy.class_eval do
97   - include Paperclip
  97 + include Paperclip::Glue
98 98 has_attached_file :avatar, options
99 99 end
100 100 end
6 test/paperclip_test.rb
@@ -172,6 +172,12 @@ class ::SubDummy < Dummy; end
172 172 end
173 173 end
174 174
  175 + should "not have Attachment in the ActiveRecord::Base namespace" do
  176 + assert_raises(NameError) do
  177 + ActiveRecord::Base::Attachment
  178 + end
  179 + end
  180 +
175 181 def self.should_validate validation, options, valid_file, invalid_file
176 182 context "with #{validation} validation and #{options.inspect} options" do
177 183 setup do

0 comments on commit 9e6afe4

Please sign in to comment.
Something went wrong with that request. Please try again.