diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2017-11-25 10:00:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-25 10:00:38 -0500 |
commit | 0f79ab91150b4cdb6c018530978a3395962c7a02 (patch) | |
tree | 98c2a025e680e31910e3e1f377401742399e31d2 /activerecord | |
parent | d575f7f2e737739302a0e8210d01c10f5d4e2c35 (diff) | |
parent | cd4cbfccea281b670e527401b0e8572746e39a5d (diff) | |
download | rails-0f79ab91150b4cdb6c018530978a3395962c7a02.tar.gz rails-0f79ab91150b4cdb6c018530978a3395962c7a02.tar.bz2 rails-0f79ab91150b4cdb6c018530978a3395962c7a02.zip |
Merge pull request #31006 from rails/kamipo/ordinal_methods_should_respect_loaded_records
Ordinal methods should respect loaded records
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 081ef5771f..d3b8091665 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -544,6 +544,7 @@ module ActiveRecord end @records.each(&:readonly!) if readonly_value + @offsets = {} unless @offsets.empty? @loaded = true @records diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 1268949ba9..b5c9bdf3a7 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -676,6 +676,22 @@ class FinderTest < ActiveRecord::TestCase 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 |