Permalink
Browse files

Merge pull request #31006 from rails/kamipo/ordinal_methods_should_re…

…spect_loaded_records

Ordinal methods should respect loaded records
  • Loading branch information...
eileencodes committed Nov 25, 2017
2 parents d575f7f + cd4cbfc commit 0f79ab91150b4cdb6c018530978a3395962c7a02
Showing with 17 additions and 0 deletions.
  1. +1 −0 activerecord/lib/active_record/relation.rb
  2. +16 −0 activerecord/test/cases/finder_test.rb
@@ -544,6 +544,7 @@ def exec_queries(&block)
end
@records.each(&:readonly!) if readonly_value
@offsets = {} unless @offsets.empty?
@loaded = true
@records
@@ -676,6 +676,22 @@ def test_take_and_first_and_last_with_integer_should_return_an_array
assert_kind_of Array, Topic.last(5)
end
def test_first_should_respect_loaded_records
authors = Author.order(:name)
assert_equal authors(:bob), authors.first
aaron = authors.create!(name: "Aaron")
authors.load
assert_no_queries do
assert_equal aaron, authors.first
assert_equal authors(:bob), authors.second
assert_not_equal authors.first, authors.second
end
end
def test_unexisting_record_exception_handling
assert_raise(ActiveRecord::RecordNotFound) {
Topic.find(1).parent

0 comments on commit 0f79ab9

Please sign in to comment.