• J
    Ensure AR #second, #third, etc. finders work through associations · 03855e79
    Jason Meller 提交于
    This commit fixes two regressions introduced in cafe31a0 where
    newly created finder methods #second, #third, #forth, and #fifth
    caused a NoMethodError error on reload associations and where we
    were pulling the wrong element out of cached associations.
    
    Examples:
    
      some_book.authors.reload.second
    
      # Before
      # => NoMethodError: undefined method 'first' for nil:NilClass
    
      # After
      # => #<Author id: 2, name: "Sally Second", ...>
    
      some_book.first.authors.first
      some_book.first.authors.second
    
      # Before
      # => #<Author id: 1, name: "Freddy First", ...>
      # => #<Author id: 1, name: "Freddy First", ...>
    
      # After
      # => #<Author id: 1, name: "Freddy First", ...>
      # => #<Author id: 2, name: "Sally Second", ...>
    
    Fixes #13783.
    03855e79
finder_test.rb 34.7 KB