test/helper.rb in paperclip-2.3.1.1 vs test/helper.rb in paperclip-2.3.2
- old
+ new
@@ -1,35 +1,65 @@
require 'rubygems'
-require 'test/unit'
-require 'shoulda'
require 'tempfile'
+require 'test/unit'
-gem 'jferris-mocha', '0.9.5.0.1241126838'
+require 'shoulda'
require 'mocha'
-gem 'sqlite3-ruby'
+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}"
+
begin
require 'ruby-debug'
-rescue LoadError
- puts "ruby-debug not loaded"
+rescue LoadError => e
+ puts "debugger disabled"
end
-ROOT = File.join(File.dirname(__FILE__), '..')
-RAILS_ROOT = ROOT
-RAILS_ENV = "test"
+ROOT = File.join(File.dirname(__FILE__), '..')
+def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ensure
+ $VERBOSE = old_verbose
+end
+
+class Test::Unit::TestCase
+ def setup
+ silence_warnings do
+ Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
+ end
+ end
+end
+
$LOAD_PATH << File.join(ROOT, 'lib')
$LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
require File.join(ROOT, 'lib', 'paperclip.rb')
require 'shoulda_macros/paperclip'
-FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
+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.establish_connection(config['test'])
def reset_class class_name
@@ -68,21 +98,10 @@
include Paperclip
has_attached_file :avatar, options
end
end
-def temporary_rails_env(new_env)
- old_env = Object.const_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
-
class FakeModel
attr_accessor :avatar_file_name,
:avatar_file_size,
:avatar_last_updated,
:avatar_content_type,
@@ -90,12 +109,13 @@
def errors
@errors ||= []
end
- def run_callbacks name, *args
+ def run_paperclip_callbacks name, *args
end
+
end
def attachment options
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
end
@@ -103,6 +123,26 @@
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
+end
+
+def should_accept_dummy_class
+ should "accept the class" do
+ assert_accepts @matcher, @dummy_class
+ end
+
+ should "accept an instance of that class" do
+ assert_accepts @matcher, @dummy_class.new
+ end
+end
+
+def should_reject_dummy_class
+ should "reject the class" do
+ assert_rejects @matcher, @dummy_class
+ end
+
+ should "reject an instance of that class" do
+ assert_rejects @matcher, @dummy_class.new
+ end
end