提交 5d264f22 编写于 作者: C Carlos Antonio da Silva

Merge pull request #7548 from ernie/missing-attributes-query-fix

Raise MissingAttributeError on query methods
## Rails 4.0.0 (unreleased) ##
* Attribute predicate methods, such as `article.title?`, will now raise
`ActiveModel::MissingAttributeError` if the attribute being queried for
truthiness was not read from the database, instead of just returning false.
*Ernie Miller*
* `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
schema.rb file will be generated using this new syntax from now on.
......
......@@ -8,7 +8,7 @@ module Query
end
def query_attribute(attr_name)
value = read_attribute(attr_name)
value = read_attribute(attr_name) { |n| missing_attribute(n, caller) }
case value
when true then true
......
......@@ -276,6 +276,7 @@ def test_unexisting_record_exception_handling
def test_find_only_some_columns
topic = Topic.all.merge!(:select => "author_name").find(1)
assert_raise(ActiveModel::MissingAttributeError) {topic.title}
assert_raise(ActiveModel::MissingAttributeError) {topic.title?}
assert_nil topic.read_attribute("title")
assert_equal "David", topic.author_name
assert !topic.attribute_present?("title")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册