2006-07-08 14:14:49 -04:00
|
|
|
# Stub to enable testing without Active Record
|
2005-06-20 07:15:46 -04:00
|
|
|
module ActiveRecord
|
|
|
|
class Base
|
|
|
|
def save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-05 08:31:04 -05:00
|
|
|
require 'abstract_unit'
|
2006-07-08 14:14:49 -04:00
|
|
|
require 'active_support/whiny_nil'
|
2005-06-20 07:15:46 -04:00
|
|
|
|
2010-03-07 09:24:30 -05:00
|
|
|
NilClass.add_whiner ::ActiveRecord::Base
|
|
|
|
|
2005-06-20 07:15:46 -04:00
|
|
|
class WhinyNilTest < Test::Unit::TestCase
|
|
|
|
def test_unchanged
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.method_thats_not_in_whiners
|
|
|
|
rescue NoMethodError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_match(/nil:NilClass/, nme.message)
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-06-20 07:15:46 -04:00
|
|
|
def test_active_record
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.save!
|
|
|
|
rescue NoMethodError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_no_match(/nil:NilClass/, nme.message)
|
2005-10-14 22:24:05 -04:00
|
|
|
assert_match(/nil\.save!/, nme.message)
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-06-20 07:15:46 -04:00
|
|
|
def test_array
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.each
|
|
|
|
rescue NoMethodError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_no_match(/nil:NilClass/, nme.message)
|
2005-10-14 22:24:05 -04:00
|
|
|
assert_match(/nil\.each/, nme.message)
|
2005-06-25 07:15:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_id
|
|
|
|
nil.id
|
|
|
|
rescue RuntimeError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_no_match(/nil:NilClass/, nme.message)
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2009-11-13 15:15:49 -05:00
|
|
|
|
|
|
|
def test_no_to_ary_coercion
|
|
|
|
nil.to_ary
|
|
|
|
rescue NoMethodError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_no_match(/nil:NilClass/, nme.message)
|
|
|
|
assert_match(/nil\.to_ary/, nme.message)
|
2009-11-13 15:15:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_to_str_coercion
|
|
|
|
nil.to_str
|
|
|
|
rescue NoMethodError => nme
|
2009-12-25 15:59:00 -05:00
|
|
|
assert_match(/nil:NilClass/, nme.message)
|
2009-11-13 15:15:49 -05:00
|
|
|
end
|
2005-06-25 07:15:38 -04:00
|
|
|
end
|