aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-12-29 17:24:35 +0000
committerJamis Buck <jamis@37signals.com>2006-12-29 17:24:35 +0000
commit0bfabaa048bdc70eae0cce399809ebd2bb129ffe (patch)
tree9539b590fa514ac3be68a1426112b84ab65cdf28 /activerecord
parenta8d7215060568c4ad36efd3faa64f861e05b4873 (diff)
downloadrails-0bfabaa048bdc70eae0cce399809ebd2bb129ffe.tar.gz
rails-0bfabaa048bdc70eae0cce399809ebd2bb129ffe.tar.bz2
rails-0bfabaa048bdc70eae0cce399809ebd2bb129ffe.zip
make sure query attributes on custom fields works as it used to
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5807 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rwxr-xr-xactiverecord/test/base_test.rb23
2 files changed, 29 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f5e6fb57e3..26010d8643 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1978,7 +1978,13 @@ module ActiveRecord #:nodoc:
false
else
column = self.class.columns_hash[attr_name]
- if column.number?
+ if column.nil?
+ if value !~ /[^0-9]/
+ !value.to_i.zero?
+ else
+ !value.blank?
+ end
+ elsif column.number?
!value.zero?
else
!value.blank?
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 3335ab6019..d6b912eb6a 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -299,7 +299,28 @@ class BasicsTest < Test::Unit::TestCase
assert_equal true, Topic.new(:approved => value).approved?
end
end
-
+
+ def test_query_attribute_with_custom_fields
+ object = Company.find_by_sql(<<-SQL).first
+ SELECT c1.*, c2.ruby_type as string_value, c2.rating as int_value
+ FROM companies c1, companies c2
+ WHERE c1.firm_id = c2.id
+ AND c1.id = 2
+ SQL
+
+ assert_equal "Firm", object.string_value
+ assert object.string_value?
+
+ object.string_value = " "
+ assert !object.string_value?
+
+ assert_equal "1", object.int_value
+ assert object.int_value?
+
+ object.int_value = "0"
+ assert !object.int_value?
+ end
+
def test_reader_generation
Topic.find(:first).title
Firm.find(:first).name