Ensure first! and friends work on loaded associations

Fixes #18237
This commit is contained in:
Sean Griffin 2014-12-29 11:55:50 -07:00
parent 2223f49157
commit fb14aa0c1b
3 changed files with 12 additions and 0 deletions

@ -1,3 +1,9 @@
* Ensure `first!` and friends work on loaded associations.
Fixes #18237.
*Sean Griffin*
* `eager_load` preserves readonly flag for associations.
Closes #15853.

@ -29,6 +29,7 @@ module Associations
# instantiation of the actual post records.
class CollectionProxy < Relation
delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
delegate :find_nth, to: :scope
def initialize(klass, association) #:nodoc:
@association = association

@ -264,6 +264,11 @@ def test_scoped_allows_conditions
end
end
test "first! works on loaded associations" do
david = authors(:david)
assert_equal david.posts.first, david.posts.reload.first!
end
def test_reset_unloads_target
david = authors(:david)
david.posts.reload