diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-10-22 16:43:39 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-10-22 16:43:39 +0000 |
commit | 3ab3a70b7cc2d40d8c0682f814e5f0bb0caf6213 (patch) | |
tree | 913e2aaf78a4b166866cc154d24a4bf284d18530 /activerecord/test | |
parent | d0a3185062d87358013de455360725600d700175 (diff) | |
download | rails-3ab3a70b7cc2d40d8c0682f814e5f0bb0caf6213.tar.gz rails-3ab3a70b7cc2d40d8c0682f814e5f0bb0caf6213.tar.bz2 rails-3ab3a70b7cc2d40d8c0682f814e5f0bb0caf6213.zip |
Clarify semantics of ActiveRecord::Base#respond_to? Closes #2560.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2705 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 16 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/finder_test.rb | 8 |
3 files changed, 30 insertions, 1 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 2d7ebc2b42..70f0eac7ee 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -1099,6 +1099,22 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase assert_equal 3, project.access_level.to_i end + def test_hatbm_attribute_access_and_respond_to + project = developers(:jamis).projects[0] + assert project.has_attribute?("name") + assert project.has_attribute?("joined_on") + assert project.has_attribute?("access_level") + assert project.respond_to?("name") + assert project.respond_to?("name=") + assert project.respond_to?("name?") + assert project.respond_to?("joined_on") + assert project.respond_to?("joined_on=") + assert project.respond_to?("joined_on?") + assert project.respond_to?("access_level") + assert project.respond_to?("access_level=") + assert project.respond_to?("access_level?") + end + def test_habtm_adding_before_save no_of_devels = Developer.count no_of_projects = Project.count diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index e4204c76cc..2a7c2ed670 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -211,6 +211,13 @@ class BasicsTest < Test::Unit::TestCase end end + def test_non_attribute_access_and_assignment + topic = Topic.new + assert !topic.respond_to?("mumbo") + assert_raises(NoMethodError) { topic.mumbo } + assert_raises(NoMethodError) { topic.mumbo = 5 } + end + def test_preserving_date_objects # SQL Server doesn't have a separate column type just for dates, so all are returned as time if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 073eea92ad..5ac6f2348c 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -96,7 +96,13 @@ class FinderTest < Test::Unit::TestCase end def test_find_only_some_columns - assert_raises(NoMethodError) { Topic.find(1, :select => "author_name").title } + topic = Topic.find(1, :select => "author_name") + assert_raises(NoMethodError) { topic.title } + assert_equal "David", topic.author_name + assert !topic.attribute_present?("title") + assert !topic.respond_to?("title") + assert topic.attribute_present?("author_name") + assert topic.respond_to?("author_name") end def test_find_on_conditions |