diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-25 11:15:38 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-25 11:15:38 +0000 |
commit | a995f42be0f9a14705d188c46c1db995baa01cf1 (patch) | |
tree | 5e2c2d38fa9ade6217f42b91ecd35509600075a7 /activesupport | |
parent | f16e0ec3eb2402284d871653df3d6c042c1a852f (diff) | |
download | rails-a995f42be0f9a14705d188c46c1db995baa01cf1.tar.gz rails-a995f42be0f9a14705d188c46c1db995baa01cf1.tar.bz2 rails-a995f42be0f9a14705d188c46c1db995baa01cf1.zip |
Added tests for whiny nil #1476 [court3nay/marcel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/whiny_nil.rb | 3 | ||||
-rw-r--r-- | activesupport/test/whiny_nil_test.rb | 40 |
2 files changed, 20 insertions, 23 deletions
diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index 3612c6acbf..5176e64185 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -6,9 +6,8 @@ # by the framework users will see a message explaining what type of object # was expected. - class NilClass - WHINERS = [ ActiveRecord::Base, Array ] + WHINERS = [ ::ActiveRecord::Base, ::Array ] @@method_class_map = Hash.new diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb index ffa15ceeaa..a3bedd7c14 100644 --- a/activesupport/test/whiny_nil_test.rb +++ b/activesupport/test/whiny_nil_test.rb @@ -1,7 +1,6 @@ require 'test/unit' - -## mock to enable testing without activerecord +# mock to enable testing without activerecord module ActiveRecord class Base def save! @@ -9,32 +8,31 @@ module ActiveRecord end end -require 'active_support/whiny_nil' - - +require File.dirname(__FILE__) + '/../lib/active_support/inflector' +require File.dirname(__FILE__) + '/../lib/active_support/whiny_nil' class WhinyNilTest < Test::Unit::TestCase def test_unchanged - begin - nil.method_thats_not_in_whiners - rescue NoMethodError => nme - assert_match(/nil:NilClass/, nme.message) - end + nil.method_thats_not_in_whiners + rescue NoMethodError => nme + assert_match(/nil:NilClass/, nme.message) end def test_active_record - begin - nil.save! - rescue NoMethodError => nme - assert(!(nme.message =~ /nil:NilClass/)) - end + nil.save! + rescue NoMethodError => nme + assert(!(nme.message =~ /nil:NilClass/)) end def test_array - begin - nil.each - rescue NoMethodError => nme - assert(!(nme.message =~ /nil:NilClass/)) - end + nil.each + rescue NoMethodError => nme + assert(!(nme.message =~ /nil:NilClass/)) + end + + def test_id + nil.id + rescue RuntimeError => nme + assert(!(nme.message =~ /nil:NilClass/)) end -end
\ No newline at end of file +end |