test/helper.rb in paperclip-2.1.2 vs test/helper.rb in paperclip-2.1.5

- old
+ new

@@ -3,10 +3,11 @@ require 'shoulda' require 'mocha' require 'tempfile' require 'active_record' +require 'active_support' begin require 'ruby-debug' rescue LoadError puts "ruby-debug not loaded" end @@ -30,15 +31,30 @@ ActiveRecord::Base.connection.create_table :dummies, :force => true do |table| table.column :other, :string table.column :avatar_file_name, :string table.column :avatar_content_type, :string table.column :avatar_file_size, :integer + table.column :avatar_updated_at, :datetime end + rebuild_class options +end +def rebuild_class options = {} ActiveRecord::Base.send(:include, Paperclip) Object.send(:remove_const, "Dummy") rescue nil Object.const_set("Dummy", Class.new(ActiveRecord::Base)) Dummy.class_eval do include Paperclip has_attached_file :avatar, options + end +end + +def temporary_rails_env(new_env) + old_env = defined?(RAILS_ENV) ? RAILS_ENV : nil + silence_warnings do + Object.const_set("RAILS_ENV", new_env) + end + yield + silence_warnings do + Object.const_set("RAILS_ENV", old_env) end end