diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-20 11:22:38 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-20 11:22:38 +0000 |
commit | 427fb035a3d03b23e903ca499abf3c1bfa53b10a (patch) | |
tree | 3610839d6204b352c896b3c88cd1b19cb97d1c0f /activerecord/test | |
parent | 6fc8e143c6aafa85c7b392f39a912f2545f23f8d (diff) | |
download | rails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.tar.gz rails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.tar.bz2 rails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.zip |
Simplify query_attribute by typecasting the attribute value and checking whether it's nil, false, zero or blank. Closes #6659.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5593 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index bddfa882b9..bb057e75f8 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -269,7 +269,34 @@ class BasicsTest < Test::Unit::TestCase assert topic.approved?, "approved should be true" # puts "" end - + + def test_query_attribute_string + [nil, "", " "].each do |value| + assert_equal false, Topic.new(:author_name => value).author_name? + end + + assert_equal true, Topic.new(:author_name => "Name").author_name? + end + + def test_query_attribute_number + [nil, 0, "0"].each do |value| + assert_equal false, Developer.new(:salary => value).salary? + end + + assert_equal true, Developer.new(:salary => 1).salary? + assert_equal true, Developer.new(:salary => "1").salary? + end + + def test_query_attribute_boolean + [nil, "", false, "false", "f", 0].each do |value| + assert_equal false, Topic.new(:approved => value).approved? + end + + [true, "true", "1", 1].each do |value| + assert_equal true, Topic.new(:approved => value).approved? + end + end + def test_reader_generation Topic.find(:first).title Firm.find(:first).name |