diff options
author | Jan De Poorter <jan@defv.be> | 2008-09-22 18:14:42 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-09-22 18:22:30 +0100 |
commit | 050e58441bf7e60d167f6708072f8fa7aee2ce76 (patch) | |
tree | ab71b73bc91801cc2daa22ba92fb2da5ea1eec99 /activerecord/test/cases/associations/has_many_associations_test.rb | |
parent | 46939a9b5a0098fddeac99a8a4331f66bdd0710e (diff) | |
download | rails-050e58441bf7e60d167f6708072f8fa7aee2ce76.tar.gz rails-050e58441bf7e60d167f6708072f8fa7aee2ce76.tar.bz2 rails-050e58441bf7e60d167f6708072f8fa7aee2ce76.zip |
Association#first and last should not load the association if not needed. [#1091 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ba750b266c..9d550916d7 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1009,6 +1009,19 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert firm.clients.loaded? end + def test_calling_first_or_last_on_existing_record_with_create_should_not_load_association + firm = companies(:first_firm) + firm.clients.create(:name => 'Foo') + assert !firm.clients.loaded? + + assert_queries 2 do + firm.clients.first + firm.clients.last + end + + assert !firm.clients.loaded? + end + def test_calling_first_or_last_on_new_record_should_not_run_queries firm = Firm.new |