diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:20:02 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:20:02 +0000 |
commit | 0b92d38c0083c2077d0533014678ed017026fac1 (patch) | |
tree | 5127ff1b6bf11f9954932dbcec3c2b3bba6835ca /activerecord/test | |
parent | 07c494ae24b897bfa1d46f741b9ac14d3b480bc2 (diff) | |
download | rails-0b92d38c0083c2077d0533014678ed017026fac1.tar.gz rails-0b92d38c0083c2077d0533014678ed017026fac1.tar.bz2 rails-0b92d38c0083c2077d0533014678ed017026fac1.zip |
Added :offset and :limit to the kinds of options that Base.constrain can use (closes #2466) [duane.johnson@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2748 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index ed81645c5e..acfd327556 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1039,6 +1039,30 @@ class BasicsTest < Test::Unit::TestCase assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo bar} baz') } end + def test_constrain_conditions + developers = Developer.constrain(:conditions => 'salary > 90000') do + Developer.find(:all, :conditions => 'id < 5') + end + david = Developer.find(1) + assert !developers.include?(david) # David's salary is less than 90,000 + assert_equal 3, developers.size + end + + def test_constrain_limit_offset + developers = Developer.constrain(:limit => 3, :offset => 2) do + Developer.find(:all, :order => 'id') + end + david = Developer.find(1) + jamis = Developer.find(1) + assert !developers.include?(david) # David has id 1 + assert !developers.include?(jamis) # Jamis has id 2 + assert_equal 3, developers.size + + # Now test without constraints to make sure we get the whole thing + developers = Developer.find(:all, :order => 'id') + assert_equal 10, developers.size + end + # FIXME: this test ought to run, but it needs to run sandboxed so that it # doesn't b0rk the current test environment by undefing everything. # |