test/helper.rb in paperclip-3.0.2 vs test/helper.rb in paperclip-3.0.3

- old
+ new

@@ -28,11 +28,14 @@ ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..'))) class Test::Unit::TestCase def setup silence_warnings do - Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test')) + Object.const_set(:Rails, stub('Rails')) + Rails.stubs(:root).returns(Pathname.new(ROOT).join('tmp')) + Rails.stubs(:env).returns('test') + Rails.stubs(:const_defined?).with(:Railtie).returns(false) end end end $LOAD_PATH << File.join(ROOT, 'lib') @@ -63,10 +66,13 @@ klass.class_eval do include Paperclip::Glue end + klass.reset_column_information + klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!) + klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache) klass end def reset_table table_name, &block block ||= lambda { |table| true } @@ -89,19 +95,14 @@ end rebuild_class options end def rebuild_class options = {} - ActiveRecord::Base.send(:include, Paperclip::Glue) - Object.send(:remove_const, "Dummy") rescue nil - Object.const_set("Dummy", Class.new(ActiveRecord::Base)) - Paperclip.reset_duplicate_clash_check! - Dummy.class_eval do - include Paperclip::Glue - has_attached_file :avatar, options + reset_class("Dummy").tap do |klass| + klass.has_attached_file :avatar, options + Paperclip.reset_duplicate_clash_check! end - Dummy.reset_column_information end class FakeModel attr_accessor :avatar_file_name, :avatar_file_size, @@ -114,10 +115,9 @@ @errors ||= [] end def run_paperclip_callbacks name, *args end - end def attachment(options={}) Paperclip::Attachment.new(:avatar, FakeModel.new, options) end