1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

Raise MissingAttributeError on query methods
This commit is contained in:
Carlos Antonio da Silva 2012-09-08 14:51:53 -07:00
commit 5d264f229c
3 changed files with 8 additions and 1 deletions

View file

@ -1,5 +1,11 @@
## 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.

View file

@ -8,7 +8,7 @@ module ActiveRecord
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

View file

@ -276,6 +276,7 @@ class FinderTest < ActiveRecord::TestCase
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")