diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 15:07:00 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 15:07:00 +0530 |
commit | 3c5a7dcaf55f427f3a48e206feb06410d011ca4f (patch) | |
tree | 1eed5483a1c1d2ad6e7a6d83408cf509c4e7b8c1 /activerecord/test/cases | |
parent | 9d3d60c64a9ce69b9932f5c543112199e576c2ad (diff) | |
download | rails-3c5a7dcaf55f427f3a48e206feb06410d011ca4f.tar.gz rails-3c5a7dcaf55f427f3a48e206feb06410d011ca4f.tar.bz2 rails-3c5a7dcaf55f427f3a48e206feb06410d011ca4f.zip |
Cache the loaded relations
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index d0a28c58e0..475090fbd8 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -24,6 +24,37 @@ class RelationTest < ActiveRecord::TestCase assert_no_queries { assert_equal 4, topics.size } end + def test_loaded_all + topics = Topic.scoped + + assert_queries(1) do + 2.times { assert_equal 4, topics.all.size } + end + + assert topics.loaded? + end + + def test_scoped_first + topics = Topic.scoped + + assert_queries(1) do + 2.times { assert_equal "The First Topic", topics.first.title } + end + + assert ! topics.loaded? + end + + def test_loaded_first + topics = Topic.scoped + + assert_queries(1) do + topics.all # force load + 2.times { assert_equal "The First Topic", topics.first.title } + end + + assert topics.loaded? + end + def test_finding_with_conditions assert_equal ["David"], Author.where(:name => 'David').map(&:name) assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name) @@ -141,7 +172,7 @@ class RelationTest < ActiveRecord::TestCase end end - def test_default_scope_with_conditions_string + def test_default_scope_with_conditions_string assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.scoped.to_a.map(&:id).sort assert_equal nil, DeveloperCalledDavid.create!.name end |