test/helper.rb in paperclip-2.3.3 vs test/helper.rb in paperclip-2.3.4

- old
+ new

@@ -7,28 +7,26 @@ case ENV['RAILS_VERSION'] when '2.1' then gem 'activerecord', '~>2.1.0' gem 'activesupport', '~>2.1.0' - gem 'actionpack', '~>2.1.0' when '3.0' then gem 'activerecord', '~>3.0.0' gem 'activesupport', '~>3.0.0' - gem 'actionpack', '~>3.0.0' else gem 'activerecord', '~>2.3.0' gem 'activesupport', '~>2.3.0' - gem 'actionpack', '~>2.3.0' end require 'active_record' require 'active_record/version' require 'active_support' -require 'action_pack' puts "Testing against version #{ActiveRecord::VERSION::STRING}" +`ruby -e 'exit 0'` # Prime $? with a value. + begin require 'ruby-debug' rescue LoadError => e puts "debugger disabled" end @@ -57,18 +55,18 @@ require 'shoulda_macros/paperclip' FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) -ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") +ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log") 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 def reset_table table_name, &block block ||= lambda { |table| true } @@ -84,29 +82,31 @@ 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 + table.column :avatar_fingerprint, :string end rebuild_class 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 class FakeModel attr_accessor :avatar_file_name, :avatar_file_size, :avatar_last_updated, :avatar_content_type, + :avatar_fingerprint, :id def errors @errors ||= [] end @@ -142,7 +142,17 @@ assert_rejects @matcher, @dummy_class end should "reject an instance of that class" do assert_rejects @matcher, @dummy_class.new + end +end + +def with_exitstatus_returning(code) + saved_exitstatus = $?.nil? ? 0 : $?.exitstatus + begin + `ruby -e 'exit #{code.to_i}'` + yield + ensure + `ruby -e 'exit #{saved_exitstatus.to_i}'` end end