diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2010-05-09 12:24:25 +0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-09 13:14:47 +0300 |
commit | 231d7676f72947bae765b9bd885b134aaf949921 (patch) | |
tree | 1943fb3a2ed3818334d1cb2b6863a89b87b4db00 /activerecord/test | |
parent | 06eaf27fffbd4e24c038ea40ee8d118b5b4f04df (diff) | |
download | rails-231d7676f72947bae765b9bd885b134aaf949921.tar.gz rails-231d7676f72947bae765b9bd885b134aaf949921.tar.bz2 rails-231d7676f72947bae765b9bd885b134aaf949921.zip |
corrected AR find_each and find_in_batches to raise when the user uses select but does not specify the primary key
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 83deabb5b7..dcc49e12ca 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -17,6 +17,20 @@ class EachTest < ActiveRecord::TestCase end end + def test_each_should_raise_if_select_is_set_without_id + assert_raise(RuntimeError) do + Post.find_each(:select => :title, :batch_size => 1) { |post| post } + end + end + + def test_each_should_execute_if_id_is_in_select + assert_queries(4) do + Post.find_each(:select => "id, title, type", :batch_size => 2) do |post| + assert_kind_of Post, post + end + end + end + def test_each_should_raise_if_the_order_is_set assert_raise(RuntimeError) do Post.find_each(:order => "title") { |post| post } |