From e48b062eed430eea43ca94630310e9a7d663cf03 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 18 May 2007 02:11:43 +0000 Subject: Sanitize Base#inspect. Closes #8392. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6761 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 33 +-------------------------------- activerecord/test/base_test.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 33 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index aec6a47583..8f60fc95f1 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -93,43 +93,12 @@ class AssociationProxyTest < Test::Unit::TestCase def test_push_does_not_load_target david = authors(:david) - not_loaded_string = '' - not_loaded_re = Regexp.new(not_loaded_string) david.categories << categories(:technology) - assert_match not_loaded_re, david.inspect - assert_equal not_loaded_string, david.categories.inspect + assert !david.categories.loaded? assert david.categories.include?(categories(:technology)) end - def test_inspect_does_not_load_target - david = authors(:david) - not_loaded_string = '' - not_loaded_re = Regexp.new(not_loaded_string) - - 2.times do - assert !david.posts.loaded?, "Posts should not be loaded yet" - assert_match not_loaded_re, david.inspect - assert_equal not_loaded_string, david.posts.inspect - - assert !david.posts.empty?, "There should be more than one post" - assert !david.posts.loaded?, "Posts should still not be loaded yet" - assert_match not_loaded_re, david.inspect - assert_equal not_loaded_string, david.posts.inspect - - assert !david.posts.find(:all).empty?, "There should be more than one post" - assert !david.posts.loaded?, "Posts should still not be loaded yet" - assert_match not_loaded_re, david.inspect - assert_equal not_loaded_string, david.posts.inspect - - assert !david.posts(true).empty?, "There should be more than one post" - assert david.posts.loaded?, "Posts should be loaded now" - assert_no_match not_loaded_re, david.inspect - assert_not_equal not_loaded_string, david.posts.inspect - - david.reload - end - end end class HasOneAssociationsTest < Test::Unit::TestCase diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 7f629a91f4..152355c9dd 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1623,7 +1623,7 @@ class BasicsTest < Test::Unit::TestCase def test_to_param_should_return_string assert_kind_of String, Client.find(:first).to_param end - + # FIXME: this test ought to run, but it needs to run sandboxed so that it # doesn't b0rk the current test environment by undefing everything. # @@ -1646,6 +1646,19 @@ class BasicsTest < Test::Unit::TestCase # "expected last count (#{counts.last}) to be <= first count (#{counts.first})" #end + def test_inspect + topic = topics(:first) + assert_equal topic.inspect, '#' + end + + def test_attribute_for_inspect + t = topics(:first) + t.content = %(This is some really long content, longer than 50 characters, so I can test that text is truncated correctly by the new ActiveRecord::Base#inspect method! Yay! BOOM!) + + assert_equal t.attribute_for_inspect(:written_on), '"' + t.written_on.to_s(:db) + '"' + assert_equal t.attribute_for_inspect(:content), '"This is some really long content, longer than 50 ch..."' + end + private def assert_readers(model, exceptions) expected_readers = Set.new(model.column_names - ['id']) -- cgit v1.2.3