diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2011-04-05 21:22:38 +1000 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2011-04-05 21:22:38 +1000 |
commit | 92e6255b58ce445d23580b669dac67d80e64d411 (patch) | |
tree | de3a01091787b30f1bafd462eedcb6210342493a /activerecord/test/cases/relations_test.rb | |
parent | 357578256fb55e32ae87c6fbf22a1c19f59ce264 (diff) | |
parent | ac07da8fc72b7a57fd4a60c0dcb5b777d85f9eb7 (diff) | |
download | rails-92e6255b58ce445d23580b669dac67d80e64d411.tar.gz rails-92e6255b58ce445d23580b669dac67d80e64d411.tar.bz2 rails-92e6255b58ce445d23580b669dac67d80e64d411.zip |
Merge branch 'master' of github.com:lifo/docrails
* 'master' of github.com:lifo/docrails: (57 commits)
Made the defaults section a little more readable and more to the point, giving a overview of the possibilities.
Added information about default values
added .'s to headings in the initialization textile page
s/ERb/ERB/g (part II)
s/ERb/ERB/g
Bump up erubis to 2.7.0
Implicit actions named not_implemented can be rendered
Gem::Specification#has_rdoc= is deprecated since rubygems 1.7.0
default_executable is deprecated since rubygems 1.7.0
Trivial fix to HTTP Digest auth MD5 example
Moved Turn activation/dependency to railties
fix typo
Direct logging of Active Record to STDOUT so it's shown inline with the results in the console [DHH]
Add using Turn with natural language test case names if the library is available (which it will be in Rails 3.1) [DHH]
require turn only for minitest
Use Turn to format all Rails tests and enable the natural language case names
Improve docs.
pass respond_with options to controller render when using a template for api navigation
only try to display an api template in responders if the request is a get or there are no errors
when using respond_with with an invalid resource and custom options, the default response status and error messages should be returned
...
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 4c5c871251..fc9df8c7a3 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -151,6 +151,12 @@ class RelationTest < ActiveRecord::TestCase assert_equal topics(:fourth).title, topics.first.title end + def test_finding_with_reorder + topics = Topic.order('author_name').order('title').reorder('id').all + topics_titles = topics.map{ |t| t.title } + assert_equal ['The First Topic', 'The Second Topic of the day', 'The Third Topic of the day', 'The Fourth Topic of the day'], topics_titles + end + def test_finding_with_order_and_take entrants = Entrant.order("id ASC").limit(2).to_a @@ -666,6 +672,34 @@ class RelationTest < ActiveRecord::TestCase assert_no_queries { assert_equal 9, best_posts.size } end + def test_size_with_limit + posts = Post.limit(10) + + assert_queries(1) { assert_equal 10, posts.size } + assert ! posts.loaded? + + best_posts = posts.where(:comments_count => 0) + best_posts.to_a # force load + assert_no_queries { assert_equal 9, best_posts.size } + end + + def test_size_with_zero_limit + posts = Post.limit(0) + + assert_no_queries { assert_equal 0, posts.size } + assert ! posts.loaded? + + posts.to_a # force load + assert_no_queries { assert_equal 0, posts.size } + end + + def test_empty_with_zero_limit + posts = Post.limit(0) + + assert_no_queries { assert_equal true, posts.empty? } + assert ! posts.loaded? + end + def test_count_complex_chained_relations posts = Post.select('comments_count').where('id is not null').group("author_id").where("comments_count > 0") |