提交 0bfabaa0 编写于 作者: J Jamis Buck

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
上级 a8d72150
......@@ -1978,7 +1978,13 @@ def query_attribute(attr_name)
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?
......
......@@ -299,7 +299,28 @@ def test_query_attribute_boolean
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册