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:
commit
5d264f229c
3 changed files with 8 additions and 1 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue